示例#1
0
文件: musabot.py 项目: Lartza/musabot
 def cmd_mp3(self, text, parameter):
     if parameter is not None:
         url, urlhash = utils.parse_parameter(parameter)
         if urlhash in self.processing:
             self.send_msg(text.actor, 'Already processing this video!')
             return
         self.processing.append(urlhash)
         try:
             db.connect()
             video_entry = Video.get_by_id(urlhash)
             video = {
                 'id': video_entry.id,
                 'url': video_entry.url,
                 'title': video_entry.title
             }
             db.close()
         except Video.DoesNotExist:
             db.close()
             if urlhash in config.as_list('blacklist'):
                 self.send_msg(text.actor, 'Video blacklisted')
                 self.processing.remove(urlhash)
                 return
             video = self.download_mp3(text, url, urlhash)
             if video is None:
                 return
         self.processing.remove(video['id'])
         self.play_or_queue(video)
     else:
         self.send_msg(text.actor, 'No video given')
示例#2
0
文件: musabot.py 项目: Lartza/musabot
 def cmd_delete(self, text, parameter):
     if is_admin(self.mumble.users[text.actor]) > 0:
         video = None
         resume = False
         if parameter is not None:
             urlhash = utils.parse_parameter(parameter)[1]
             if urlhash is None:
                 return
             db.connect()
             video = Video.get_by_id(urlhash)
         else:
             if self.playing:
                 resume = True
                 db.connect()
                 logging.debug("Database connection opened")
                 logging.debug(
                     "Selecting currently playing track for deletion")
                 video = Video.get_by_id(self.current_track['id'])
                 self.stop()
             else:
                 self.send_msg(text.actor, 'No video defined')
         if video is not None:
             os.remove(os.path.join(filedir, video.id))
             logging.debug("Removed video file %s", video.id)
             video.delete_instance()
             logging.debug("Removed database entry for video")
             db.close()
             logging.debug("Database connection closed")
             self.send_msg(text.actor, 'Deleted succesfully')
         else:
             db.close()
             self.send_msg(text.actor, 'Failed to delete')
         if resume:
             logging.debug("Resuming playback")
             self.playnext()
示例#3
0
文件: musabot.py 项目: Lartza/musabot
 def cmd_unblacklist(self, text, parameter):
     if is_admin(self.mumble.users[text.actor]) > 0 and parameter:
         urlhash = utils.parse_parameter(parameter)[1]
         blacklist = config.as_list('blacklist')
         if urlhash in blacklist:
             blacklist.remove(urlhash)
             config['blacklist'] = blacklist
             config.write()
             self.send_msg(text.actor, "Blacklist removal successful")
示例#4
0
文件: musabot.py 项目: Lartza/musabot
 def cmd_youtube(self, text, parameter):
     if config['youtube_apikey'] is not None:
         if parameter is not None:
             url, urlhash = utils.parse_parameter(parameter)
             if urlhash in self.processing:
                 self.send_msg(text.actor, 'Already processing this video!')
                 return
             self.processing.append(urlhash)
             try:
                 db.connect()
                 video_entry = Video.get_by_id(urlhash)
                 video = {
                     'id': video_entry.id,
                     'url': video_entry.url,
                     'title': video_entry.title
                 }
                 db.close()
             except Video.DoesNotExist:
                 db.close()
                 if urlhash in config.as_list('blacklist'):
                     self.send_msg(text.actor, 'Video blacklisted')
                     self.processing.remove(urlhash)
                     return
                 try:
                     videoid = utils.get_yt_video_id(url)
                 except ValueError:
                     self.send_msg(text.actor, 'Invalid YouTube link')
                     self.processing.remove(urlhash)
                     return
                 video = self.download_youtube(text, url, urlhash, videoid)
                 if video is None:
                     return
             try:
                 timecode = parse_qs(urlparse(video['url']).query)['t'][0]
                 video['starttime'] = 0
                 if 'h' in timecode:
                     hours, timecode = timecode.split('h', 1)
                     video['starttime'] += int(hours) * 3600
                 if 'm' in timecode:
                     minutes, timecode = timecode.split('m', 1)
                     video['starttime'] += int(minutes) * 60
                 if 's' in timecode:
                     seconds, timecode = timecode.split('s', 1)
                     video['starttime'] += int(seconds)
                 if timecode:
                     video['starttime'] = int(timecode)
             except KeyError:
                 pass
             self.processing.remove(video['id'])
             self.play_or_queue(video)
         else:
             self.send_msg(text.actor, 'No video given')
     else:
         self.send_msg(text.actor, 'YouTube API Key not set')
示例#5
0
文件: musabot.py 项目: Lartza/musabot
 def cmd_blacklist(self, text, parameter):
     if is_admin(self.mumble.users[text.actor]) > 0:
         video = None
         if parameter is not None:
             urlhash = utils.parse_parameter(parameter)[1]
             if urlhash is None:
                 return
             db.connect()
             video = Video.get_by_id(urlhash)
         else:
             if self.playing:
                 video = Video.get_by_id(self.current_track['id'])
                 self.playnext()
         if video is not None:
             os.remove(os.path.join(filedir, video.id))
             video.delete_instance()
             db.close()
             blacklist = config.as_list('blacklist')
             blacklist.append(video.id)
             config['blacklist'] = blacklist
             config.write()
             self.send_msg(text.actor, 'Blacklisted succesfully')
         else:
             self.send_msg(text.actor, 'Failed to blacklist')