Compare commits

..

No commits in common. "8b54fa9c7b896c0ed332502c2a0e40428abe4ec0" and "773fcd1b5e441050554b6d265417e951037141ed" have entirely different histories.

View file

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