def _execute_info(self): if self.status['state'] in ['play', 'pause']: cmds = [(_('Title'), ('title',)), (_('Artist'), ('artist',)), (_('Album'), ('album',)), (_('Date'), ('date',)), (_('Track'), ('track', '0', False, 2)), (_('Genre'), ('genre',)), (_('File'), ('file',)), ] for pretty, cmd in cmds: mpdh.conout('%s: %s' % (pretty, mpdh.get(self.songinfo, *cmd))) at, _length = [int(c) for c in self.status['time'].split(':')] at_time = misc.convert_time(at) try: time = misc.convert_time(mpdh.get(self.songinfo, 'time', '', True)) aprint(3, '%s: %s/%s' % (_('Time'), at_time, time)) except: aprint(3, '%s: %s' % (_('Time'), at_time)) aprint(3, '%s: %s' % (_('Bitrate'), self.status.get('bitrate', ''))) else: aprint(3, _('MPD stopped'))
def format(self, item, wintitle, songpos): if not wintitle: return "%E" elapsed_time = songpos.split(':')[0] if songpos else self.default if elapsed_time.isdigit(): elapsed_time = misc.convert_time(int(elapsed_time)) return elapsed_time
def _update_album(self, songinfo): if 'album' not in songinfo: self.albumText.set_text(_('Album name not set.')) return artist, tracks = self.album_return_artist_and_tracks() albuminfo = _('Album info not found.') if tracks: tracks.sort(key=lambda x: mpdh.get(x, 'track', 0, True)) playtime = 0 tracklist = [] for t in tracks: playtime += mpdh.get(t, 'time', 0, True) tracklist.append( '%s. %s' % (mpdh.get(t, 'track', '0', False, 2), mpdh.get(t, 'title', os.path.basename(t['file'])))) album = mpdh.get(songinfo, 'album') year = mpdh.get(songinfo, 'date', None) playtime = misc.convert_time(playtime) albuminfo = '\n'.join(i for i in (album, artist, year, playtime) if i) albuminfo += '\n\n' albuminfo += '\n'.join(t for t in tracklist) self.albumText.set_text(albuminfo)
def _update_album(self, songinfo): if 'album' not in songinfo: self.albumText.get_buffer().set_text(_("Album name not set.")) return artist, tracks = self.album_return_artist_and_tracks() albuminfo = _("Album info not found.") if tracks: tracks.sort(key=lambda x: mpdh.get(x, 'track', 0, True)) playtime = 0 tracklist = [] for t in tracks: playtime += mpdh.get(t, 'time', 0, True) tracklist.append("%s. %s" % (mpdh.get(t, 'track', '0', False, 2), mpdh.get(t, 'title', os.path.basename( t['file'])))) album = mpdh.get(songinfo, 'album') year = mpdh.get(songinfo, 'date', None) playtime = misc.convert_time(playtime) albuminfo = "\n".join(i for i in (album, artist, year, playtime) if i) albuminfo += "\n\n" albuminfo += "\n".join(t for t in tracklist) self.albumText.get_buffer().set_text(albuminfo)
def statstext(self, stats): # XXX translate expressions, not words statslabel = '%s %s\n.' % (stats['songs'], gettext.ngettext('song', 'songs', int(stats['songs']))) statslabel += '%s %s\n.' % (stats['albums'], gettext.ngettext('album', 'albums', int(stats['albums']))) statslabel += '%s %s\n.' % (stats['artists'], gettext.ngettext('artist', 'artists', int(stats['artists']))) try: db_playtime = float(stats['db_playtime']) hours_of_playtime = misc.convert_time(db_playtime).split(':')[-3] except: hours_of_playtime = '0' if int(hours_of_playtime) >= 24: days_of_playtime = str(int(hours_of_playtime) / 24) statslabel += '%s %s.' % (days_of_playtime, gettext.ngettext('day of bliss', 'days of bliss', int(days_of_playtime))) else: statslabel += '%s %s.' % (hours_of_playtime, gettext.ngettext('hour of bliss', 'hours of bliss', int(hours_of_playtime))) return statslabel
def _execute_info(self): if self.status["state"] in ["play", "pause"]: cmds = [ (_("Title"), ("title",)), (_("Artist"), ("artist",)), (_("Album"), ("album",)), (_("Date"), ("date",)), (_("Track"), ("track", "0", False, 2)), (_("Genre"), ("genre",)), (_("File"), ("file",)), ] for pretty, cmd in cmds: mpdh.conout("%s: %s" % (pretty, mpdh.get(self.songinfo, *cmd))) at, _length = [int(c) for c in self.status["time"].split(":")] at_time = misc.convert_time(at) try: time = misc.convert_time(mpdh.get(self.songinfo, "time", "", True)) print "%s: %s/%s" % (_("Time"), at_time, time) except: print "%s: %s" % (_("Time"), at_time) print "%s: %s" % (_("Bitrate"), self.status.get("bitrate", "")) else: print _("MPD stopped")
def _execute_info(self): if self.status['state'] in ['play', 'pause']: cmds = [ (_("Title"), ('title', )), (_("Artist"), ('artist', )), (_("Album"), ('album', )), (_("Date"), ('date', )), (_("Track"), ('track', '0', False, 2)), (_("Genre"), ('genre', )), (_("File"), ('file', )), ] for pretty, cmd in cmds: mpdh.conout("%s: %s" % (pretty, mpdh.get(self.songinfo, *cmd))) at, _length = [int(c) for c in self.status['time'].split(':')] at_time = misc.convert_time(at) try: time = misc.convert_time( mpdh.get(self.songinfo, 'time', '', True)) print "%s: %s/%s" % (_("Time"), at_time, time) except: print "%s: %s" % (_("Time"), at_time) print "%s: %s" % (_("Bitrate"), self.status.get('bitrate', '')) else: print _("MPD stopped")
def _execute_info(self): if self.status['state'] in ['play', 'pause']: cmds = [(_("Title"), ('title',)), (_("Artist"), ('artist',)), (_("Album"), ('album',)), (_("Date"), ('date',)), (_("Track"), ('track', '0', False, 2)), (_("Genre"), ('genre',)), (_("File"), ('file',)), ] for pretty, cmd in cmds: mpdh.conout("%s: %s" % (pretty, mpdh.get(self.songinfo, *cmd))) at, _length = [int(c) for c in self.status['time'].split(':')] at_time = misc.convert_time(at) try: time = misc.convert_time(mpdh.get(self.songinfo, 'time', '', True)) print "%s: %s/%s" % (_("Time"), at_time, time) except: print "%s: %s" % (_("Time"), at_time) print "%s: %s" % (_("Bitrate"), self.status.get('bitrate', '')) else: print _("MPD stopped")
def statstext(self, stats): # XXX translate expressions, not words statslabel = stats['songs'] + ' ' + gettext.ngettext('song', 'songs', int(stats['songs'])) + '.\n' statslabel = statslabel + stats['albums'] + ' ' + gettext.ngettext('album', 'albums', int(stats['albums'])) + '.\n' statslabel = statslabel + stats['artists'] + ' ' + gettext.ngettext('artist', 'artists', int(stats['artists'])) + '.\n' try: hours_of_playtime = misc.convert_time(float(stats['db_playtime'])).split(':')[-3] except: hours_of_playtime = '0' if int(hours_of_playtime) >= 24: days_of_playtime = str(int(hours_of_playtime)/24) statslabel = statslabel + days_of_playtime + ' ' + gettext.ngettext('day of bliss', 'days of bliss', int(days_of_playtime)) + '.' else: statslabel = statslabel + hours_of_playtime + ' ' + gettext.ngettext('hour of bliss', 'hours of bliss', int(hours_of_playtime)) + '.' return statslabel
def execute_cmd(self, cmd): self.status = mpdh.status(self.client) if not self.status: print _("Unable to connect to MPD.\nPlease check your Sonata preferences or MPD_HOST/MPD_PORT environment variables.") sys.exit(1) self.songinfo = mpdh.currsong(self.client) if cmd == "play": mpdh.call(self.client, 'play') elif cmd == "pause": mpdh.call(self.client, 'pause', 1) elif cmd == "stop": mpdh.call(self.client, 'stop') elif cmd == "next": mpdh.call(self.client, 'next') elif cmd == "prev": mpdh.call(self.client, 'previous') elif cmd == "random": if self.status['random'] == '0': mpdh.call(self.client, 'random', 1) else: mpdh.call(self.client, 'random', 0) elif cmd == "repeat": if self.status['repeat'] == '0': mpdh.call(self.client, 'repeat', 1) else: mpdh.call(self.client, 'repeat', 0) elif cmd == "pp": if self.status['state'] in ['play']: mpdh.call(self.client, 'pause', 1) elif self.status['state'] in ['pause', 'stop']: mpdh.call(self.client, 'play') elif cmd == "info": if self.status['state'] in ['play', 'pause']: mpdh.conout (_("Title") + ": " + mpdh.get(self.songinfo, 'title')) mpdh.conout (_("Artist") + ": " + mpdh.get(self.songinfo, 'artist')) mpdh.conout (_("Album") + ": " + mpdh.get(self.songinfo, 'album')) mpdh.conout (_("Date") + ": " + mpdh.get(self.songinfo, 'date')) mpdh.conout (_("Track") + ": " + mpdh.getnum(self.songinfo, 'track', '0', False, 2)) mpdh.conout (_("Genre") + ": " + mpdh.get(self.songinfo, 'genre')) mpdh.conout (_("File") + ": " + os.path.basename(mpdh.get(self.songinfo, 'file'))) at, _length = [int(c) for c in self.status['time'].split(':')] at_time = misc.convert_time(at) try: time = misc.convert_time(int(mpdh.get(self.songinfo, 'time'))) print _("Time") + ": " + at_time + " / " + time except: print _("Time") + ": " + at_time print _("Bitrate") + ": " + self.status.get('bitrate', '') else: print _("MPD stopped") elif cmd == "status": try: if self.status['state'] == 'play': print _("State") + ": " + _("Playing") elif self.status['state'] == 'pause': print _("State") + ": " + _("Paused") elif self.status['state'] == 'stop': print _("State") + ": " + _("Stopped") if self.status['repeat'] == '0': print _("Repeat") + ": " + _("Off") else: print _("Repeat") + ": " + _("On") if self.status['random'] == '0': print _("Random") + ": " + _("Off") else: print _("Random") + ": " + _("On") print _("Volume") + ": " + self.status['volume'] + "/100" print _('Crossfade') + ": " + self.status['xfade'] + ' ' + gettext.ngettext('second', 'seconds', int(self.status['xfade'])) except: pass
def format(self, item, wintitle, songpos): time = FormatCode.format(self, item, wintitle, songpos) if time.isdigit(): time = misc.convert_time(int(time)) return time
def info_update(self, playing_or_paused, newbitrate, songinfo, update_all, blank_window=False, skip_lyrics=False): # update_all = True means that every tag should update. This is # only the case on song and status changes. Otherwise we only # want to update the minimum number of widgets so the user can # do things like select label text. if playing_or_paused: bitratelabel = self.info_labels[self.info_type[_("Bitrate")]] titlelabel = self.info_labels[self.info_type[_("Title")]] artistlabel = self.info_labels[self.info_type[_("Artist")]] albumlabel = self.info_labels[self.info_type[_("Album")]] datelabel = self.info_labels[self.info_type[_("Date")]] genrelabel = self.info_labels[self.info_type[_("Genre")]] tracklabel = self.info_labels[self.info_type[_("Track")]] filelabel = self.info_labels[self.info_type[_("File")]] if not self.last_info_bitrate or self.last_info_bitrate != newbitrate: bitratelabel.set_text(newbitrate) self.last_info_bitrate = newbitrate if update_all: # Use artist/album Wikipedia links? artist_use_link = False if 'artist' in songinfo: artist_use_link = True album_use_link = False if 'album' in songinfo: album_use_link = True titlelabel.set_text(mpdh.get(songinfo, 'title')) if artist_use_link: artistlabel.set_markup(misc.link_markup(misc.escape_html(mpdh.get(songinfo, 'artist')), False, False, self.linkcolor)) else: artistlabel.set_text(mpdh.get(songinfo, 'artist')) if album_use_link: albumlabel.set_markup(misc.link_markup(misc.escape_html(mpdh.get(songinfo, 'album')), False, False, self.linkcolor)) else: albumlabel.set_text(mpdh.get(songinfo, 'album')) datelabel.set_text(mpdh.get(songinfo, 'date')) genrelabel.set_text(mpdh.get(songinfo, 'genre')) if 'track' in songinfo: tracklabel.set_text(mpdh.getnum(songinfo, 'track', '0', False, 0)) else: tracklabel.set_text("") path = misc.file_from_utf8(self.config.musicdir[self.config.profile_num] + os.path.dirname(mpdh.get(songinfo, 'file'))) if os.path.exists(path): filelabel.set_text(self.config.musicdir[self.config.profile_num] + mpdh.get(songinfo, 'file')) self.info_editlabel.set_markup(misc.link_markup(_("edit tags"), True, True, self.linkcolor)) else: filelabel.set_text(mpdh.get(songinfo, 'file')) self.info_editlabel.set_text("") if 'album' in songinfo: # Update album info: artist, tracks = self.album_return_artist_and_tracks() trackinfo = "" album = mpdh.get(songinfo, 'album') year = mpdh.get(songinfo, 'date', None) if album is not None: albuminfo = album + "\n" playtime = 0 if len(tracks) > 0: for track in tracks: playtime += int(mpdh.get(track, 'time', 0)) if 'title' in track: trackinfo = trackinfo + mpdh.getnum(track, 'track', '0', False, 2) + '. ' + mpdh.get(track, 'title') + '\n' else: trackinfo = trackinfo + mpdh.getnum(track, 'track', '0', False, 2) + '. ' + mpdh.get(track, 'file').split('/')[-1] + '\n' if artist is not None: albuminfo += artist + "\n" if year is not None: albuminfo += year + "\n" albuminfo += misc.convert_time(playtime) + "\n" albuminfo += "\n" + trackinfo else: albuminfo = _("Album info not found.") self.albumText.set_markup(misc.escape_html(albuminfo)) else: self.albumText.set_text(_("Album name not set.")) # Update lyrics: if self.config.show_lyrics and not skip_lyrics: global ServiceProxy if ServiceProxy is None: try: from ZSI import ServiceProxy # Make sure we have the right version.. _test = ServiceProxy.ServiceProxy except: ServiceProxy = None if ServiceProxy is None: self.info_searchlabel.set_text("") self.info_show_lyrics(_("ZSI not found, fetching lyrics support disabled."), "", "", True) elif 'artist' in songinfo and 'title' in songinfo: self.get_lyrics_start(mpdh.get(songinfo, 'artist'), mpdh.get(songinfo, 'title'), mpdh.get(songinfo, 'artist'), mpdh.get(songinfo, 'title'), os.path.dirname(mpdh.get(songinfo, 'file'))) else: self.info_searchlabel.set_text("") self.info_show_lyrics(_("Artist or song title not set."), "", "", True) else: blank_window = True if blank_window: for label in self.info_labels: label.set_text("") self.info_editlabel.set_text("") if self.config.show_lyrics: self.info_searchlabel.set_text("") self.info_editlyricslabel.set_text("") self.info_show_lyrics("", "", "", True) self.albumText.set_text("") self.last_info_bitrate = ""
def info_update(self, playing_or_paused, newbitrate, songinfo, update_all, blank_window=False, skip_lyrics=False): # update_all = True means that every tag should update. This is # only the case on song and status changes. Otherwise we only # want to update the minimum number of widgets so the user can # do things like select label text. if playing_or_paused: bitratelabel = self.info_labels[self.info_type[_("Bitrate")]] titlelabel = self.info_labels[self.info_type[_("Title")]] artistlabel = self.info_labels[self.info_type[_("Artist")]] albumlabel = self.info_labels[self.info_type[_("Album")]] datelabel = self.info_labels[self.info_type[_("Date")]] genrelabel = self.info_labels[self.info_type[_("Genre")]] tracklabel = self.info_labels[self.info_type[_("Track")]] filelabel = self.info_labels[self.info_type[_("File")]] if not self.last_info_bitrate or self.last_info_bitrate != newbitrate: bitratelabel.set_text(newbitrate) self.last_info_bitrate = newbitrate if update_all: # Use artist/album Wikipedia links? artist_use_link = False if 'artist' in songinfo: artist_use_link = True album_use_link = False if 'album' in songinfo: album_use_link = True titlelabel.set_text(mpdh.get(songinfo, 'title')) if artist_use_link: artistlabel.set_markup( misc.link_markup( misc.escape_html(mpdh.get(songinfo, 'artist')), False, False, self.linkcolor)) else: artistlabel.set_text(mpdh.get(songinfo, 'artist')) if album_use_link: albumlabel.set_markup( misc.link_markup( misc.escape_html(mpdh.get(songinfo, 'album')), False, False, self.linkcolor)) else: albumlabel.set_text(mpdh.get(songinfo, 'album')) datelabel.set_text(mpdh.get(songinfo, 'date')) genrelabel.set_text(mpdh.get(songinfo, 'genre')) if 'track' in songinfo: tracklabel.set_text( mpdh.getnum(songinfo, 'track', '0', False, 0)) else: tracklabel.set_text("") path = misc.file_from_utf8( self.config.musicdir[self.config.profile_num] + os.path.dirname(mpdh.get(songinfo, 'file'))) if os.path.exists(path): filelabel.set_text( self.config.musicdir[self.config.profile_num] + mpdh.get(songinfo, 'file')) self.info_editlabel.set_markup( misc.link_markup(_("edit tags"), True, True, self.linkcolor)) else: filelabel.set_text(mpdh.get(songinfo, 'file')) self.info_editlabel.set_text("") if 'album' in songinfo: # Update album info: artist, tracks = self.album_return_artist_and_tracks() trackinfo = "" album = mpdh.get(songinfo, 'album') year = mpdh.get(songinfo, 'date', None) if album is not None: albuminfo = album + "\n" playtime = 0 if len(tracks) > 0: for track in tracks: playtime += int(mpdh.get(track, 'time', 0)) if 'title' in track: trackinfo = trackinfo + mpdh.getnum( track, 'track', '0', False, 2) + '. ' + mpdh.get(track, 'title') + '\n' else: trackinfo = trackinfo + mpdh.getnum( track, 'track', '0', False, 2) + '. ' + mpdh.get( track, 'file').split('/')[-1] + '\n' if artist is not None: albuminfo += artist + "\n" if year is not None: albuminfo += year + "\n" albuminfo += misc.convert_time(playtime) + "\n" albuminfo += "\n" + trackinfo else: albuminfo = _("Album info not found.") self.albumText.set_markup(misc.escape_html(albuminfo)) else: self.albumText.set_text(_("Album name not set.")) # Update lyrics: if self.config.show_lyrics and not skip_lyrics: global ServiceProxy if ServiceProxy is None: try: from ZSI import ServiceProxy # Make sure we have the right version.. _test = ServiceProxy.ServiceProxy except: ServiceProxy = None if ServiceProxy is None: self.info_searchlabel.set_text("") self.info_show_lyrics( _("ZSI not found, fetching lyrics support disabled." ), "", "", True) elif 'artist' in songinfo and 'title' in songinfo: self.get_lyrics_start( mpdh.get(songinfo, 'artist'), mpdh.get(songinfo, 'title'), mpdh.get(songinfo, 'artist'), mpdh.get(songinfo, 'title'), os.path.dirname(mpdh.get(songinfo, 'file'))) else: self.info_searchlabel.set_text("") self.info_show_lyrics( _("Artist or song title not set."), "", "", True) else: blank_window = True if blank_window: for label in self.info_labels: label.set_text("") self.info_editlabel.set_text("") if self.config.show_lyrics: self.info_searchlabel.set_text("") self.info_editlyricslabel.set_text("") self.info_show_lyrics("", "", "", True) self.albumText.set_text("") self.last_info_bitrate = ""
def execute_cmd(self, cmd): self.status = mpdh.status(self.client) if not self.status: print _( "Unable to connect to MPD.\nPlease check your Sonata preferences or MPD_HOST/MPD_PORT environment variables." ) sys.exit(1) self.songinfo = mpdh.currsong(self.client) if cmd == "play": mpdh.call(self.client, 'play') elif cmd == "pause": mpdh.call(self.client, 'pause', 1) elif cmd == "stop": mpdh.call(self.client, 'stop') elif cmd == "next": mpdh.call(self.client, 'next') elif cmd == "prev": mpdh.call(self.client, 'previous') elif cmd == "random": if self.status['random'] == '0': mpdh.call(self.client, 'random', 1) else: mpdh.call(self.client, 'random', 0) elif cmd == "repeat": if self.status['repeat'] == '0': mpdh.call(self.client, 'repeat', 1) else: mpdh.call(self.client, 'repeat', 0) elif cmd == "pp": if self.status['state'] in ['play']: mpdh.call(self.client, 'pause', 1) elif self.status['state'] in ['pause', 'stop']: mpdh.call(self.client, 'play') elif cmd == "info": if self.status['state'] in ['play', 'pause']: mpdh.conout( _("Title") + ": " + mpdh.get(self.songinfo, 'title')) mpdh.conout( _("Artist") + ": " + mpdh.get(self.songinfo, 'artist')) mpdh.conout( _("Album") + ": " + mpdh.get(self.songinfo, 'album')) mpdh.conout(_("Date") + ": " + mpdh.get(self.songinfo, 'date')) mpdh.conout( _("Track") + ": " + mpdh.getnum(self.songinfo, 'track', '0', False, 2)) mpdh.conout( _("Genre") + ": " + mpdh.get(self.songinfo, 'genre')) mpdh.conout( _("File") + ": " + os.path.basename(mpdh.get(self.songinfo, 'file'))) at, _length = [int(c) for c in self.status['time'].split(':')] at_time = misc.convert_time(at) try: time = misc.convert_time( int(mpdh.get(self.songinfo, 'time'))) print _("Time") + ": " + at_time + " / " + time except: print _("Time") + ": " + at_time print _("Bitrate") + ": " + self.status.get('bitrate', '') else: print _("MPD stopped") elif cmd == "status": try: if self.status['state'] == 'play': print _("State") + ": " + _("Playing") elif self.status['state'] == 'pause': print _("State") + ": " + _("Paused") elif self.status['state'] == 'stop': print _("State") + ": " + _("Stopped") if self.status['repeat'] == '0': print _("Repeat") + ": " + _("Off") else: print _("Repeat") + ": " + _("On") if self.status['random'] == '0': print _("Random") + ": " + _("Off") else: print _("Random") + ": " + _("On") print _("Volume") + ": " + self.status['volume'] + "/100" print _('Crossfade') + ": " + self.status[ 'xfade'] + ' ' + gettext.ngettext( 'second', 'seconds', int(self.status['xfade'])) except: pass