Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import hexchat
- from apiclient.discovery import build
- from apiclient.errors import HttpError
- # Galaxy's YouTube Display Script
- # v1.0 - First version
- # v1.1 - Title/nDuration -> Title [Duration]
- # - YouTube link can be anywhere in message [rather than just beginning and end]
- # - Consolidated to one function
- # - Added mobile YouTube link support
- # - Replaces unrecognized characters with '?' [for xChat]
- # v1.2 - now prevents recursion if youtube link is in youtube title [thanks Tyranisaur]
- # - only works for #gtsplus
- # - now displays duration is a fully readable fashion!
- #
- # Upcoming changes
- # imgur support
- __module_name__ = "youtubeTitleDisplay"
- __module_version__ = "1.2"
- __module_description__ = "Displays title & duration of YouTube video linked in chat"
- youtube = build("youtube", "v3", developerKey="AIzaSyBdObvQPz5ayaL2-RVv_jcSclOCCwJ3Mxw")
- def youtube_cb(word, word_eol, userdata):
- if hexchat.get_info('channel') == '#gtsplus':
- if "https://www.youtube.com/watch?v=" in word[1]:
- start = word[1].find('watch?v=')
- vid_id = word[1][start+8:start+19]
- vid = youtube.videos().list(id=vid_id, part='snippet, contentDetails').execute()
- vid_data = [' ',' ']
- vid_dur = 'hour:minute:second'
- for vid_res in vid.get("items", []):
- vid_data[0] = ("Title: %s" % (vid_res['snippet']['title']))
- vid_data[1] = ("%s" % (vid_res['contentDetails']['duration'])[2:])
- hours=minutes=seconds=True
- if "H" not in vid_data[1]:
- vid_dur = vid_dur.replace('hour:','')
- hours = False
- if "M" not in vid_data[1]:
- vid_dur = vid_dur.replace('minute','00')
- minutes = False
- if "S" not in vid_data[1]:
- vid_dur = vid_dur.replace('second','00')
- seconds = False
- if hours:
- vid_dur = vid_dur.replace('hour',vid_data[1][0])
- vid_data[1] = vid_data[1][2:]
- if minutes:
- start = vid_data[1].find('M')
- if (start - 1):
- vid_dur = vid_dur.replace('minute',vid_data[1][:2])
- vid_data[1] = vid_data[1][3:]
- else:
- vid_dur = vid_dur.replace('minute',vid_data[1][0])
- vid_data[1] = vid_data[1][2:]
- if seconds:
- if len(vid_data[1]) == 3:
- vid_dur = vid_dur.replace('second',vid_data[1][0:2])
- else:
- vid_dur = vid_dur.replace('second',('0' + vid_data[1][0]))
- if vid_data[0] not in word[1]:
- hexchat.command("bs say #gtsplus %s [%s]" % (vid_data[0], vid_dur))
- if "://youtu.be/" in word[1]:
- start = word[1].find('.be/')
- vid_id = word[1][start+4:start+15]
- vid = youtube.videos().list(id=vid_id, part='snippet, contentDetails').execute()
- vid_data = [' ',' ']
- vid_dur = 'hour:minute:second'
- for vid_res in vid.get("items", []):
- vid_data[0] = ("Title: %s" % (vid_res['snippet']['title']))
- vid_data[1] = ("%s" % (vid_res['contentDetails']['duration'])[2:])
- hours=minutes=seconds=True
- if "H" not in vid_data[1]:
- vid_dur = vid_dur.replace('hour:','')
- hours = False
- if "M" not in vid_data[1]:
- vid_dur = vid_dur.replace('minute','00')
- minutes = False
- if "S" not in vid_data[1]:
- vid_dur = vid_dur.replace('second','00')
- seconds = False
- if hours:
- vid_dur = vid_dur.replace('hour',vid_data[1][0])
- vid_data[1] = vid_data[1][2:]
- if minutes:
- start = vid_data[1].find('M')
- if (start - 1):
- vid_dur = vid_dur.replace('minute',vid_data[1][:2])
- vid_data[1] = vid_data[1][3:]
- else:
- vid_dur = vid_dur.replace('minute',vid_data[1][0])
- vid_data[1] = vid_data[1][2:]
- if seconds:
- if len(vid_data[1]) == 3:
- vid_dur = vid_dur.replace('second',vid_data[1][0:2])
- else:
- vid_dur = vid_dur.replace('second',('0' + vid_data[1][0]))
- if vid_data[0] not in word[1]:
- hexchat.command("bs say #gtsplus %s [%s]" % (vid_data[0], vid_dur))
- return hexchat.EAT_NONE
- EVENTS = [("Channel Message"),("Your Message"),("Your Action"),("Channel Action")]
- for event in EVENTS:
- #if hexchat.get_info('channel') == '#gtsplus':
- hexchat.hook_print(event, youtube_cb)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement