def songrequest(channel, user, op, youtubelink): print("\nAttempting to play: {}\nRequested by: {}\n".format( youtubelink, user)) config = configuration.readconfig() if user in config['irc']['moderating']['banlist']: print( 'Request denied, user {} is banned from songrequests'.format(user)) return match_You = matchYou(youtubelink) if not match_You: print( "Warning: Did not recognize the link. Will now attempt to search for the song." ) youtubelink = 'gvsearch1:' + ' '.join(youtubelink) else: youtubelink = 'https://www.youtube.com/watch?v=' + match_You.group(1) songrequestdelay = config['irc']['songrequest']['delay'] maxsongduration = config['youtube']['maxsongduration'] if not user in op: if user in sruser: srdelta = datetime.now() - sruser[user] if srdelta.total_seconds() < songrequestdelay: print("Request denied. User {} is adding songs too quickly". format(user)) return youtube_info = youtube.get_youtube_info(youtubelink) title = youtube_info['title'] if title: safeprint("Video title: {}".format(title)) category = youtube_info["categories"][0] if not config['youtube']['category_whitelist'][0].lower() == 'all': if not category in config['youtube']['category_whitelist']: safeprint( "Request denied. Video titled: {}'s category is not whitelisted" .format(title)) return duration = youtube_info['duration'] if duration > maxsongduration: safeprint( "Request denied. Video titled: {} is too long. Seconds: {}".format( title, duration)) return if youtubelink in songs: safeprint("Request by {} denied. Song {} has already been added once.". format(user, title)) return play_song(youtube_info, user, channel)
def unban(user, op, nick): config = readconfig() banlist = config['irc']['moderating']['banlist'] if nick in banlist: if user in op: banlist.remove(nick) writeconfig(config) print('user {} has unbanned: {}\n'.format(user, nick))
def ban(user, op, nick): config = readconfig() banlist = config['irc']['moderating']['banlist'] if nick in banlist: return if user in op: banlist.append(nick) writeconfig(config) print('user {} has banned: {}\n'.format(user, nick))
def play_song(youtube_info, user, channel): if not youtube_info: return youtubelink = "https://www.youtube.com/watch?v=" + youtube_info['id'] title = youtube_info['title'] glink = youtube_info['url'] if youtubelink in songs: print("Song " + youtubelink + " has already been requested once.") return if not glink.startswith("https://"): print( "Unknown error occured during converting stream. Update youtube-dl or contact nejtilsvampe." ) return sendmsg(channel, title + ", Requested by: " + user) config = configuration.readconfig() vlc_options = config['vlc']['vlc_options'] vlc_path = config['vlc']['vlc_path'] subprocess.Popen([vlc_path] + vlc_options + [glink, ":meta-title={}".format(title)]) songs[youtubelink] = { 'id': len(songs) + 1, 'link': youtubelink, 'title': title, 'uri': glink, 'duration': youtube_info['duration'], 'category': youtube_info["categories"][0], 'user': user } sruser[user] = datetime.now() if config['playlist']['autoresume'] != True: return #Auto Resume Check: web_pw = config['vlc']['web_intf']['password'] web_host = config['vlc']['web_intf']['host'] if not web_pw: return state = playlist.check_going(playlist.getPlayerInfo(web_host, web_pw)) if state: return time.sleep(0.5) playlist.auto_resume(glink, web_host, web_pw, title)
def command_handling(data, user, op, config): channel = data.pop(0) command = data.pop(0)[1:] command.lower() arguments = data web_pw = config['vlc']['web_intf']['password'] web_host = config['vlc']['web_intf']['host'] #Non admin commands: if command == '!chatters': sendmsg( '#nejtilsvampe', "There are {} users on {}".format(chatters('#bitey'), '#bitey')) return elif command == '!skip': config = readconfig() skip_handling(user, config) return elif command == '!currentsong': playlist_ = getPlayList(web_host, web_pw) current_song(playlist_) return elif command == '!nextsong': playlist_ = getPlayList(web_host, web_pw) nextsong(playlist_) return elif command in config['irc']['songrequest']['cmd']: if not arguments: return songrequest(channel, user, op, config['vlc']['vlc_path'], arguments) return #Admin commands: elif command == '#sr.ban': addbanlist(user, op, arguments[0]) return elif command == '#sr.unban': removebanlist(user, op, arguments[0]) return elif command == '#skip': extra_priv = config['irc']['moderating']['extra_op_privileges'] playlist_ = getPlayList(web_host, web_pw) skip_song_op(user, op, web_host, web_pw, playlist_, extra_priv) return elif command == '#skipcondition': Edit_skip_conditions(user, op, arguments) return
def Edit_skip_conditions(user, op, arg): config = readconfig() print("{} attempted to edit skip conditions".format(user)) if user in config['irc']['moderating']['banlist']: print("{} appears to be banned".format(user)) return if not user in op: print("{} does not have op".format(user)) return config['playlist']['skip']['skip_conditions'] = ' '.join(arg) writeconfig(config) print("{} has edited skip conditions to: {}".format(user, ' '.join(arg)))
def nextsong(playlist): config = readconfig() next_song = next_song_info(playlist) if not next_song: return if not next_song['name'].startswith("https://"): for chan in config['irc']['channels']: sendmsg(chan, "Next song is: {}".format(next_song['name'])) return from packets.songrequest import songs if not songs: return for song in songs: if songs[song]['uri'] == next_song['uri']: for chan in config['irc']['channels']: sendmsg(chan, "Next song is: {}".format(songs[song]['title'])) return
def privatelist(channel, random): config = configuration.readconfig() vlc = dict(config['vlc']['web_intf']) while True: try: playerInfo = playlist.getPlayerInfo( vlc['host'], vlc['password'] ) if playlist.check_going(playerInfo) == True: continue youtube_info = youtube.add_private(random) songrequest.play_song(youtube_info, channel, channel) playlist.auto_resume('', vlc['host'], vlc['password'], 'random song...' ) except Exception: logging.exception('Got exception on privatelist')
def songrequest(channel, user, op, vlc_path, youtubelink): print("\nAttempting to play: {}\nRequested by: {}\n".format( youtubelink, user)) config = configuration.readconfig() if user in config['irc']['moderating']['banlist']: print( 'Request denied, user {} is banned from songrequests'.format(user)) return match_You = matchYou(youtubelink) if not match_You: print( "Warning: Did not recognize the link. Will now attempt to search for the song." ) youtubelink = 'gvsearch1:' + ' '.join(youtubelink) else: youtubelink = 'https://www.youtube.com/watch?v=' + match_You.group(1) songrequestdelay = config['irc']['songrequest']['delay'] maxsongduration = config['youtube']['maxsongduration'] if not user in op: if user in sruser: srdelta = datetime.now() - sruser[user] if srdelta.total_seconds() < songrequestdelay: print("Request denied. User {} is adding songs too quickly". format(user)) return youtube_info = youtube.get_youtube_info(youtubelink) if not youtube_info: return youtubelink = "https://www.youtube.com/watch?v=" + youtube_info['id'] title = youtube_info['title'] if title: safeprint("Video title: {}".format(title)) category = youtube_info["categories"][0] if not config['youtube']['category_whitelist'][0].lower() == 'all': if not category in config['youtube']['category_whitelist']: safeprint( "Request denied. Video titled: {} is not classified as Music". format(title)) return duration = youtube_info['duration'] if duration > maxsongduration: safeprint( "Request denied. Video titled: {} is too long. Seconds: {}".format( title, duration)) return if youtubelink in songs: safeprint("Request by {} denied. Song {} has already been added once.". format(user, title)) return glink = youtube_info['url'] if not glink.startswith("https://"): print( "Unknown error occured during converting stream. Update youtube-dl or contact nejtilsvampe." ) return sendmsg(channel, title + ", Requested by: " + user) vlc_options = config['vlc']['vlc_options'] subprocess.Popen([vlc_path] + vlc_options + [glink, ":meta-title={}".format(title)]) songs[youtubelink] = { 'id': len(songs) + 1, 'link': youtubelink, 'title': title, 'uri': glink, 'duration': duration, 'category': category, 'user': user } sruser[user] = datetime.now() if config['playlist']['autoresume'] != True: return #Auto Resume Check: web_pw = config['vlc']['web_intf']['password'] web_host = config['vlc']['web_intf']['host'] if not web_pw: return state = playlist.getPlayerInfo(web_host, web_pw) if not 'state' in state: return if state['state'] != 'stopped': return time.sleep(0.05) playlist.auto_resume(glink, web_host, web_pw, title)