def complete_move(self, value, current_position): urwid.disconnect_signal( self, self.move_prompt, signals.PROMPT_DONE, self.complete_move) urwid.disconnect_signal( self, self.move_prompt, signals.UPDATE_INDEX, self.view.move_update_index) self.update_focus('body') try: new_index = int(value) logger.debug('Moving playlist track from {} to {}'.format( current_position, new_index)) mpd = mstat.initialize_mpd(self.conf) mpd.move(current_position, new_index) self.view.focus_position = new_index except (TypeError, ValueError): logger.error('Invalid move index: {}'.format(value)) self.view.update() self.update()
def run(self): mpd = mstat.initialize_mpd(self.conf) while not self.quit_event.is_set(): logger.debug('MPD: idle') changes = mpd.idle() logger.debug('Mpd changes: {}'.format(changes)) for change in changes: self.consume_event(change)
def __init__(self, model, conf, loop): super(PlaylistController, self).__init__(model, conf, loop) self._conf = conf # Connections self._mpd = mstat.initialize_mpd(conf) # Initialize self.update_model()
def __init__(self, model, conf, loop): super(LibraryController, self).__init__(model, conf, loop) self._default_orderers = [analytics.BaseOrder()] # Connections self._mpd = mstat.initialize_mpd(conf) self._anl = analytics.Analytics(conf) self._orderers = None self.orderers = self._default_orderers.copy()
def status_text(self): mpd = mstat.initialize_mpd(self.conf) status = mpd.status() text = '' songid = status.get('songid') if songid: track = mpd.playlistid(songid) if track: params = self.status_params(status, track[0]) text = self.status_format.format(**params) return 'Playlist | ' + text return 'Playlist'
def order_albums(self, orderers=None): mpd = mstat.initialize_mpd(self.conf) if orderers is None: orderers = [BaseOrder()] ordered = {} with session_scope(self.conf, commit=False) as session: for album_orderer in orderers: ordered = album_orderer.order(ordered, session, mpd) # Order by score, then by artist name, then by album name sorted_order = sorted(ordered.items(), reverse=True, key=lambda item: (item[1], item[0])) return [Suggestion(album, order) for album, order in sorted_order]
def __init__(self, args, conf): self._conf = conf self._mpd = mstat.initialize_mpd(conf) self.quit_event = threading.Event() self.loop = asyncio.get_event_loop() self.top = MainView(conf, self.loop) self.urwid_loop = self.main_loop() self.bindings = self.setup_bindings() self.commands = self.setup_commands() self.update_footer_text('suggestive') self.continuously_update_playlist_status() if not args.no_update and (args.update or conf.general.update_on_startup): self.start_mpd_update()
def order_albums(self, orderers=None): mpd = mstat.initialize_mpd(self.conf) if orderers is None: orderers = [BaseOrder()] ordered = {} with session_scope(self.conf, commit=False) as session: for album_orderer in orderers: ordered = album_orderer.order(ordered, session, mpd) # Order by score, then by artist name, then by album name sorted_order = sorted( ordered.items(), reverse=True, key=lambda item: (item[1], item[0])) return [Suggestion(album, order) for album, order in sorted_order]
def insert_new_song_played(self): mpd = mstat.initialize_mpd(self.conf) status = mpd.status() songid = status.get('songid') if songid != self.current_song_id: try: info = mpd.playlistid(songid)[0] db_track = mstat.database_track_from_mpd( self.conf, info) play_model = PlayModel(db_track) self.model.plays.insert(0, play_model) self.model.update() logger.debug('Plays: {}'.format(self.model.plays)) self.current_song_id = songid except (MpdCommandError, IndexError): pass
def pause(self): mpd = mstat.initialize_mpd(self.conf) mpd.pause()
def track_changed(self): mpd = mstat.initialize_mpd(self.conf) return self.current_track != self.now_playing_index(mpd)