patch
This commit is contained in:
parent
e3cfd9087e
commit
8b54fa9c7b
1 changed files with 16 additions and 13 deletions
29
sweebot.py
29
sweebot.py
|
@ -51,10 +51,13 @@ 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"]
|
||||||
# The regular /watch path, which stores the ID in the query.
|
try:
|
||||||
if query.path == '/watch': return parse_qs(query.query)['v'][0]
|
# The regular /watch path, which stores the ID in the query.
|
||||||
# Alternatively, it will get the ID in the path if the path was in the list above.
|
if query.path == '/watch': return parse_qs(query.query)['v'][0]
|
||||||
elif query.path.split('/')[1] in integrated_in_url: return query.path.split('/')[2]
|
# 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:
|
class config:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.conn = sqlite3.connect(environ["SBconfig"])
|
self.conn = sqlite3.connect(environ["SBconfig"])
|
||||||
|
@ -664,20 +667,20 @@ while True:
|
||||||
parse = urlparse(i)
|
parse = urlparse(i)
|
||||||
if parse.scheme in ["http", "https"]:
|
if parse.scheme in ["http", "https"]:
|
||||||
try:
|
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:
|
||||||
if parse.hostname in ["youtube.com", "youtu.be", "www.youtube.com", "m.youtube.com", "youtube-nocookie.com"]:
|
try:
|
||||||
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']
|
||||||
views = details['items'][0]['statistics']['viewCount']
|
channel = details['items'][0]['statistics']['']
|
||||||
multiline("(" + nick + ") [▶️ YouTube] {title} | Author: {channel} | {views} views", channel)
|
multiline("(" + nick + ") [▶️ YouTube] {title} | Author: {channel}", channel)
|
||||||
else:
|
except Exception as ex:
|
||||||
raise Exception("No special URL, go ahead and parse the normal title...")
|
multiline("(" + nick + ") [YouTube Error, is it a valid YouTube URL?]", channel)
|
||||||
except:
|
print(traceback.format_exc())
|
||||||
print(traceback.formal_exc())
|
else:
|
||||||
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]
|
||||||
|
@ -694,7 +697,7 @@ while True:
|
||||||
except rex.SSLError as ex:
|
except rex.SSLError as ex:
|
||||||
multiline("(" + nick + ") [SSL Error: " + str(ex.message) + "]", channel)
|
multiline("(" + nick + ") [SSL Error: " + str(ex.message) + "]", channel)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
multiline("(" + nick + ") [Request error: " + str(ex) + "]", channel)
|
multiline("(" + nick + ") [Request error: " + str(ex.message) + "]", channel)
|
||||||
except:
|
except:
|
||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
elif "JOIN" in text and "#nixsanctuary" in text:
|
elif "JOIN" in text and "#nixsanctuary" in text:
|
||||||
|
|
Loading…
Reference in a new issue