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 skip_song_op(user, op, host, password, playlist, extra_priv): if not extra_priv: return if user in op: current_song = current_song_info(playlist) title = current_song['name'] for chan in config['irc']['channels']: sendmsg(chan, "{} skipped song: {}.".format(user, title)) skip_song(host, password, playlist) return
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 current_song(playlist): current_song = current_song_info(playlist) if not current_song: return if not current_song['name']: return title = current_song['name'] from packets.configuration import config if not title.startswith('https://'): for chan in config['irc']['channels']: sendmsg(chan, "Current song is: {}".format(title))
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 skip_handling(user, config): host = config['vlc']['web_intf']['host'] password = config['vlc']['web_intf']['password'] playlist = getPlayList(host, password) if not playlist: return if user in config['irc']['moderating']['banlist']: return current_song = current_song_info(playlist) id_ = current_song['id'] title = current_song['name'] if not current_song: return if not id_ in skip_votes: skip_votes[id_] = dict() skip_votes[id_]['requirement'] = skip_Requirement(config) skip_votes[id_]['voters'] = [] for chan in config['irc']['channels']: sendmsg( chan, "{} requests to skip song: {}. Need {} more votes".format( user, title, skip_votes[id_]['requirement'] - 1)) if user in skip_votes[id_]['voters']: return skip_requirement = skip_votes[id_]['requirement'] skip_votes[id_]['voters'].append(user) skippers = len(skip_votes[id_]['voters']) if skip_requirement > skippers: if (skip_requirement - skippers) % 3 == 0: for chan in config['irc']['channels']: sendmsg( chan, "{} requested to skip song: {}. {} more required to skip.". format(skippers, title, skip_requirement - skippers)) safeprint( "{} requested to skip song: {}. {} more required to skip.". format(user, title, skip_requirement - skippers)) return msg = '{} users requested to skip song. Now attempting to skip...'.format( skippers) print(msg) for chan in config['irc']['channels']: sendmsg(chan, msg) skip_song(host, password, playlist)
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)