def _execute_info(self): if self.status['state'] in ['play', 'pause']: cmds = [ (_("Title"), 'title'), (_("Artist"), 'artist'), (_("Album"), 'album'), (_("Date"), 'date'), (_("Track"), 'track'), (_("Genre"), 'genre'), (_("File"), 'file'), ] for pretty, key in cmds: value = str(self.songinfo.get(key)) if key == 'track': value = value.zfill(2) # XXX this could fail, if not all characters are supported by # os.stdout.encoding print("%s: %s" % (pretty, value)) at, _length = [int(c) for c in self.status['time'].split(':')] at_time = misc.convert_time(at) try: time = misc.convert_time(self.songinfo.time) 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): song_count = int(stats['songs']) song_text = ngettext('{count} song.', '{count} songs.', song_count).format(count=song_count) album_count = int(stats['albums']) album_text = ngettext('{count} album.', '{count} albums.', album_count).format(count=album_count) artist_count = int(stats['artists']) artist_text = ngettext('{count} artist.', '{count} artists.', artist_count).format(count=artist_count) try: db_playtime = float(stats['db_playtime']) hours = int(misc.convert_time(db_playtime).split(':')[-3]) except: hours = 0 if hours >= 24: days = round(hours / 24, 1) time_text = ngettext('{count} day of bliss.', '{count} days of bliss.', days).format(count=days) else: time_text = ngettext('{count} hour of bliss.', '{count} hours of bliss.', hours).format(count=hours) parts = (song_text, album_text, artist_text, time_text) live_parts = [part for part in parts if part is not None] return '\n'.join(live_parts)
def _update_album(self, songinfo): if 'album' not in songinfo: self.album_text.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: x.track) playtime = 0 tracklist = [] for t in tracks: playtime += t.time tracklist.append("%s. %s" % ( str(t.track).zfill(2), t.get('title', os.path.basename(t.file)))) album = songinfo.album year = songinfo.date 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.album_text.get_buffer().set_text(albuminfo)
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.album_text.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: x.track) playtime = 0 tracklist = [] for t in tracks: playtime += t.time tracklist.append("%s. %s" % (str(t.track).zfill(2), t.get('title', os.path.basename(t.file)))) album = songinfo.album year = songinfo.date 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.album_text.get_buffer().set_text(albuminfo)
def test_convert_time(self): self.assertEqual(misc.convert_time(60 * 4 + 4), "04:04") self.assertEqual(misc.convert_time(3600 * 3 + 60 * 2), "03:02:00")
def test_convert_time(self): self.assertEqual(misc.convert_time(60*4+4), "04:04") self.assertEqual(misc.convert_time(3600*3+60*2), "03:02:00")
def format(self, item, wintitle, songpos): time = FormatCode.format(self, item, wintitle, songpos) if time.isdigit(): time = misc.convert_time(int(time)) return time