def inc_current_song(self): while True: if not self.enabled: break if self.current_song_id: if not self.paused: try: with DBManager.create_session_scope() as db_session: current_song = SongrequestQueue._from_id( db_session, self.current_song_id) next_song = SongrequestQueue._get_next_song( db_session) if not current_song or ( current_song.skip_after and current_song.skip_after < current_song.current_song_time + 10): self.load_song() else: if (not current_song.requested_by ) and next_song and next_song.requested_by: self.load_song() current_song.current_song_time += 1 except Exception as e: log.error(e) elif self.module_opened: self.load_song() time.sleep(1)
def get_next_song(self, bot, source, message, **rest): with DBManager.create_session_scope() as db_session: next_song = SongrequestQueue._get_next_song(db_session) if next_song: m, s = divmod(next_song.playing_in(db_session), 60) m = int(m) s = int(s) playing_in = f"{m:02d}:{s:02d}" if next_song.requestor: bot.say( self.settings["message_in_chat_when_next_song"].format( title=next_song.song_info.title, requestor=next_song.requestor.username_raw, playing_in=playing_in, )) return True bot.say(self.settings["message_in_chat_when_next_song"].format( title=next_song.song_info.title, requestor="Backup Playlist", playing_in=playing_in)) return True bot.say(self.settings["message_in_chat_when_next_song_none"]) return True
def load_song(self, skipped_by_id=None): if not self.enabled: return False if self.current_song_id: with DBManager.create_session_scope() as db_session: current_song = SongrequestQueue._from_id( db_session, self.current_song_id) if current_song: if current_song.current_song_time > 5: self.previous_queue = 0 histroy = current_song._to_histroy( db_session, skipped_by_id) if not histroy: log.info( "History not added because stream is offline!") else: current_song._remove(db_session) self._stop_video() self._hide() db_session.commit() self._playlist_history() SongrequestQueue._update_queue() self.current_song_id = None if not self.module_opened: return False with DBManager.create_session_scope() as db_session: current_song = SongrequestQueue._get_current_song(db_session) if not current_song: current_song = SongrequestQueue._get_next_song(db_session) if current_song: current_song.playing = True current_song.queue = 0 current_song.current_song_time = 0 self.current_song_id = current_song.id song_info = current_song.song_info self._play( current_song.video_id, song_info.title, current_song.requested_by.username_raw if current_song.requested_by else "Backup list", ) if self.settings["use_spotify"]: is_playing, song_name, artistsArr = self.bot.spotify_api.state( self.bot.spotify_token_manager) if is_playing: self.bot.spotify_api.pause( self.bot.spotify_token_manager) self.previously_playing_spotify = True if not current_song.requested_by_id: SongrequestQueue._create( db_session, current_song.video_id, current_song.skip_after, None, SongrequestQueue._get_next_queue(db_session), ) db_session.commit() self._playlist() SongrequestQueue._update_queue() return True if self.settings["use_spotify"]: if self.previously_playing_spotify: self.bot.spotify_api.play(self.bot.spotify_token_manager) self.previously_playing_spotify = False if self.isVideoShowing: self._hide() return False