This commit is contained in:
Nova Cat 2024-12-17 16:34:07 -08:00
parent e3cfd9087e
commit 8b54fa9c7b

View file

@ -51,10 +51,13 @@ def get_yt_id(url):
if query.hostname in {'www.youtube.com', 'youtube.com', 'music.youtube.com'}:
# URLs that have the ID in the path instead of the query.
integrated_in_url = ["watch", "embed", "v", "shorts"]
# The regular /watch path, which stores the ID in the query.
if query.path == '/watch': return parse_qs(query.query)['v'][0]
# Alternatively, it will get the ID in the path if the path was in the list above.
elif query.path.split('/')[1] in integrated_in_url: return query.path.split('/')[2]
try:
# The regular /watch path, which stores the ID in the query.
if query.path == '/watch': return parse_qs(query.query)['v'][0]
# Alternatively, it will get the ID in the path if the path was in the list above.
elif query.path.split('/')[1] in integrated_in_url: return query.path.split('/')[2]
except:
return None
class config:
def __init__(self):
self.conn = sqlite3.connect(environ["SBconfig"])
@ -664,20 +667,20 @@ while True:
parse = urlparse(i)
if parse.scheme in ["http", "https"]:
try:
try:
if parse.hostname in ["youtube.com", "youtu.be", "www.youtube.com", "m.youtube.com", "youtube-nocookie.com"]:
if parse.hostname in ["youtube.com", "youtu.be", "www.youtube.com", "m.youtube.com", "youtube-nocookie.com"] and get_yt_id(i) != None:
try:
video_id = get_yt_id(i)
youtube = build('youtube', 'v3', developerKey=DEVELOPER_KEY)
request = youtube.videos().list(part='snippet,statistics', id=video_id)
details = request.execute()
title = details['items'][0]['snippet']['title']
channel = details['items'][0]['snippet']['channelTitle']
views = details['items'][0]['statistics']['viewCount']
multiline("(" + nick + ") [▶️ YouTube] {title} | Author: {channel} | {views} views", channel)
else:
raise Exception("No special URL, go ahead and parse the normal title...")
except:
print(traceback.formal_exc())
channel = details['items'][0]['statistics']['']
multiline("(" + nick + ") [▶️ YouTube] {title} | Author: {channel}", channel)
except Exception as ex:
multiline("(" + nick + ") [YouTube Error, is it a valid YouTube URL?]", channel)
print(traceback.format_exc())
else:
e = get(i, headers=headers, timeout=10)
header = e.headers
content_type = header.get('content-type').split(";")[0]
@ -694,7 +697,7 @@ while True:
except rex.SSLError as ex:
multiline("(" + nick + ") [SSL Error: " + str(ex.message) + "]", channel)
except Exception as ex:
multiline("(" + nick + ") [Request error: " + str(ex) + "]", channel)
multiline("(" + nick + ") [Request error: " + str(ex.message) + "]", channel)
except:
print(traceback.format_exc())
elif "JOIN" in text and "#nixsanctuary" in text: