-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a30abb2
commit 1fc14c1
Showing
11 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from helpers.youtubeFunctionalities.client import getClient | ||
from helpers.youtubeFunctionalities.stream import getStreamChatId | ||
from appUtils import log | ||
import os | ||
from dotenv import load_dotenv | ||
load_dotenv() | ||
|
||
streamId = os.environ.get("STREAM_ID", "") | ||
nextPageToken = "" | ||
|
||
youtube = getClient() | ||
|
||
chatId = getStreamChatId(youtube, streamId) | ||
if chatId != "": | ||
print(chatId) | ||
else: | ||
log.info("Received empty chat ID") |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from appUtils import log | ||
|
||
def getLiveChats(client, liveChatId: str, pageToken: str = "", part: str = "snippet"): | ||
# client.liveBroadcasts().list(part=part, ).execute() | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from helpers.youtubeFunctionalities.credentials import write as writeCred, read as readCred | ||
from appUtils import log | ||
import googleapiclient.discovery as discovery | ||
from googleapiclient.discovery import Resource | ||
|
||
API_SERVICE_NAME = 'youtube' | ||
API_VERSION = 'v3' | ||
|
||
def getClient() -> Resource: | ||
try: | ||
credentials = readCred() | ||
youtube = discovery.build(API_SERVICE_NAME, API_VERSION, credentials= credentials) | ||
writeCred(creds= credentials) # in case credentials were refreshed | ||
return youtube | ||
except Exception as e: | ||
log.error("Error in building client: {}".format(e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from appUtils import log, writeJson, readJson, configuration, json | ||
from google.oauth2.credentials import Credentials | ||
|
||
def write(creds: Credentials): | ||
try: | ||
writeJson(configuration["GCP"]["OAuthToken"], json.loads(creds.to_json())) | ||
except Exception as e: | ||
log.error("Error in writing credentials: {}".format(e)) | ||
|
||
def read() -> Credentials: | ||
try: | ||
tokenJson = readJson(configuration["GCP"]["OAuthToken"]) | ||
credentials = Credentials.from_authorized_user_info(tokenJson) | ||
return credentials | ||
except Exception as e: | ||
log.error("Error in reading credentials: {}".format(e)) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from appUtils import log | ||
from googleapiclient.discovery import Resource | ||
|
||
def getStreamChatId(client: Resource, streamId: str, part: str = "liveStreamingDetails"): | ||
response = "" | ||
try: | ||
ytResponse = client.videos().list( | ||
part=part, | ||
id= streamId | ||
).execute() | ||
items = ytResponse.get("items", []) | ||
if len(items) > 0: | ||
response = items[0].get("liveStreamingDetails", {}).get("activeLiveChatId", "") | ||
except Exception as e: | ||
log.error("Error in getting stream ID: {}".format(e)) | ||
return response |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
STREAM_ID="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters