def _update_song(self, songinfo): artistlabel = self.info_labels['artist'] tracklabel = self.info_labels['track'] albumlabel = self.info_labels['album'] filelabel = self.info_labels['file'] for name in ['title', 'date', 'genre']: label = self.info_labels[name] label.set_text(mpdh.get(songinfo, name)) tracklabel.set_text(mpdh.get(songinfo, 'track', '', False)) artistlabel.set_markup(misc.link_markup(misc.escape_html( mpdh.get(songinfo, 'artist')), False, False, self.linkcolor)) albumlabel.set_markup(misc.link_markup(misc.escape_html( mpdh.get(songinfo, 'album')), False, False, self.linkcolor)) path = misc.file_from_utf8(os.path.join( self.config.musicdir[self.config.profile_num], mpdh.get(songinfo, 'file'))) if os.path.exists(path): filelabel.set_text(os.path.join( self.config.musicdir[self.config.profile_num], mpdh.get(songinfo, 'file'))) self._editlabel.set_markup(misc.link_markup(_("edit tags"), True, True, self.linkcolor)) else: filelabel.set_text(mpdh.get(songinfo, 'file')) self._editlabel.set_text("")
def _show_lyrics(self, artist_then, title_then, lyrics=None, error=None): # For error messages where there is no appropriate info: if not artist_then or not title_then: self._searchlabel.set_markup("") self._editlyricslabel.set_markup("") if error: self.lyricsText.get_buffer().set_text(error) elif lyrics: self.lyricsText.get_buffer().set_text(lyrics) else: self.lyricsText.get_buffer().set_text("") return # Verify that we are displaying the correct lyrics: songinfo = self.get_playing_song() if not songinfo: return artist_now = misc.strip_all_slashes(mpdh.get(songinfo, 'artist', None)) title_now = misc.strip_all_slashes(mpdh.get(songinfo, 'title', None)) if artist_now == artist_then and title_now == title_then: self._searchlabel.set_markup(misc.link_markup( _("search"), True, True, self.linkcolor)) self._editlyricslabel.set_markup(misc.link_markup( _("edit"), True, True, self.linkcolor)) if error: self.lyricsText.get_buffer().set_text(error) elif lyrics: self._set_lyrics(lyrics) else: self.lyricsText.get_buffer().set_text("")
def _show_lyrics(self, artist_then, title_then, lyrics=None, error=None): # For error messages where there is no appropriate info: if not artist_then or not title_then: self._searchlabel.set_markup('') self._editlyricslabel.set_markup('') if error: self.lyricsText.set_markup(error) elif lyrics: self.lyricsText.set_markup(lyrics) else: self.lyricsText.set_markup('') return # Verify that we are displaying the correct lyrics: songinfo = self.get_playing_song() if not songinfo: return artist_now = misc.strip_all_slashes(mpdh.get(songinfo, 'artist', None)) title_now = misc.strip_all_slashes(mpdh.get(songinfo, 'title', None)) if artist_now == artist_then and title_now == title_then: self._searchlabel.set_markup( misc.link_markup(_('search'), True, True, self.linkcolor)) self._editlyricslabel.set_markup( misc.link_markup(_('edit'), True, True, self.linkcolor)) if error: self.lyricsText.set_markup(error) elif lyrics: try: self.lyricsText.set_markup(misc.escape_html(lyrics)) except: # XXX why would this happen? self.lyricsText.set_text(lyrics) else: self.lyricsText.set_markup('')
def _show_lyrics(self, artist_then, title_then, lyrics=None, error=None): # For error messages where there is no appropriate info: if not artist_then or not title_then: self._searchlabel.set_markup('') self._editlyricslabel.set_markup('') if error: self.lyricsText.set_markup(error) elif lyrics: self.lyricsText.set_markup(lyrics) else: self.lyricsText.set_markup('') return # Verify that we are displaying the correct lyrics: songinfo = self.get_playing_song() if not songinfo: return artist_now = misc.strip_all_slashes(mpdh.get(songinfo, 'artist', None)) title_now = misc.strip_all_slashes(mpdh.get(songinfo, 'title', None)) if artist_now == artist_then and title_now == title_then: self._searchlabel.set_markup(misc.link_markup( _('search'), True, True, self.linkcolor)) self._editlyricslabel.set_markup(misc.link_markup( _('edit'), True, True, self.linkcolor)) if error: self.lyricsText.set_markup(error) elif lyrics: try: self.lyricsText.set_markup(misc.escape_html(lyrics)) except: # XXX why would this happen? self.lyricsText.set_text(lyrics) else: self.lyricsText.set_markup('')
def _update_song(self, songinfo): artistlabel = self.info_labels['artist'] tracklabel = self.info_labels['track'] albumlabel = self.info_labels['album'] filelabel = self.info_labels['file'] for name in ['title', 'date', 'genre']: label = self.info_labels[name] label.set_text(mpdh.get(songinfo, name)) tracklabel.set_text(mpdh.get(songinfo, 'track', '', False)) artistlabel.set_markup( misc.link_markup(misc.escape_html(mpdh.get(songinfo, 'artist')), False, False, self.linkcolor)) albumlabel.set_markup( misc.link_markup(misc.escape_html(mpdh.get(songinfo, 'album')), False, False, self.linkcolor)) path = misc.file_from_utf8( os.path.join(self.config.musicdir[self.config.profile_num], mpdh.get(songinfo, 'file'))) if os.path.exists(path): filelabel.set_text( os.path.join(self.config.musicdir[self.config.profile_num], mpdh.get(songinfo, 'file'))) self._editlabel.set_markup( misc.link_markup(_('edit tags'), True, True, self.linkcolor)) else: filelabel.set_text(mpdh.get(songinfo, 'file')) self._editlabel.set_text('')
def toggle_more(self): text = _("hide") if self.config.info_song_more else _("more") func = "show" if self.config.info_song_more else "hide" func = getattr(ui, func) self._morelabel.set_markup(misc.link_markup(text, True, True, self.linkcolor)) for hbox in self.info_boxes_in_more: func(hbox)
def on_link_click(self, _widget, _event, linktype): if linktype == 'more': previous_is_more = (self.info_morelabel.get_text() == "(" + _("more") + ")") if previous_is_more: self.info_morelabel.set_markup(misc.link_markup(_("hide"), True, True, self.linkcolor)) self.config.info_song_more = True else: self.info_morelabel.set_markup(misc.link_markup(_("more"), True, True, self.linkcolor)) self.config.info_song_more = False if self.config.info_song_more: for hbox in self.info_boxes_in_more: ui.show(hbox) else: for hbox in self.info_boxes_in_more: ui.hide(hbox) else: self.on_link_click_cb(linktype)
def toggle_more(self): text = _('hide') if self.config.info_song_more else _('more') func = 'show' if self.config.info_song_more else 'hide' func = getattr(ui, func) self._morelabel.set_markup(misc.link_markup(text, True, True, self.linkcolor)) for hbox in self.info_boxes_in_more: func(hbox)
def toggle_more(self): text = _('hide') if self.config.info_song_more else _('more') func = 'show' if self.config.info_song_more else 'hide' func = getattr(ui, func) self._morelabel.set_markup( misc.link_markup(text, True, True, self.linkcolor)) for hbox in self.info_boxes_in_more: func(hbox)
def get_lyrics_thread(self, search_artist, search_title, filename_artist, filename_title, song_dir): filename_artist = misc.strip_all_slashes(filename_artist) filename_title = misc.strip_all_slashes(filename_title) filename = self.info_check_for_local_lyrics(filename_artist, filename_title, song_dir) search_str = misc.link_markup(_("search"), True, True, self.linkcolor) edit_str = misc.link_markup(_("edit"), True, True, self.linkcolor) if filename: # If the lyrics only contain "not found", delete the file and try to # fetch new lyrics. If there is a bug in Sonata/SZI/LyricWiki that # prevents lyrics from being found, storing the "not found" will # prevent a future release from correctly fetching the lyrics. f = open(filename, 'r') lyrics = f.read() f.close() if lyrics == _("Lyrics not found"): misc.remove_file(filename) filename = self.info_check_for_local_lyrics(filename_artist, filename_title, song_dir) if filename: # Re-use lyrics from file: f = open(filename, 'r') lyrics = f.read() f.close() # Strip artist - title line from file if it exists, since we # now have that information visible elsewhere. header = filename_artist + " - " + filename_title + "\n\n" if lyrics[:len(header)] == header: lyrics = lyrics[len(header):] gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) gobject.idle_add(self.info_searchlabel.set_markup, search_str) gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str) else: # Use default filename: filename = self.target_lyrics_filename(filename_artist, filename_title, song_dir) # Fetch lyrics from lyricwiki.org gobject.idle_add(self.info_show_lyrics, _("Fetching lyrics..."), filename_artist, filename_title) if self.lyricServer is None: wsdlFile = "http://lyricwiki.org/server.php?wsdl" try: self.lyricServer = True timeout = socketgettimeout() socketsettimeout(consts.LYRIC_TIMEOUT) self.lyricServer = ServiceProxy.ServiceProxy(wsdlFile, cachedir=os.path.expanduser("~/.service_proxy_dir")) except: socketsettimeout(timeout) lyrics = _("Couldn't connect to LyricWiki") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) self.lyricServer = None gobject.idle_add(self.info_searchlabel.set_markup, search_str) gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str) return try: timeout = socketgettimeout() socketsettimeout(consts.LYRIC_TIMEOUT) lyrics = self.lyricServer.getSong(artist=self.lyricwiki_format(search_artist), song=self.lyricwiki_format(search_title))['return']["lyrics"] if lyrics.lower() != "not found": lyrics = misc.unescape_html(lyrics) lyrics = misc.wiki_to_html(lyrics) lyrics = lyrics.encode("ISO-8859-1") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) # Save lyrics to file: misc.create_dir('~/.lyrics/') f = open(filename, 'w') lyrics = misc.unescape_html(lyrics) try: f.write(lyrics.decode(self.enc).encode('utf8')) except: f.write(lyrics) f.close() else: lyrics = _("Lyrics not found") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) except: lyrics = _("Fetching lyrics failed") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) gobject.idle_add(self.info_searchlabel.set_markup, search_str) gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str) socketsettimeout(timeout)
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 get_lyrics_thread(self, search_artist, search_title, filename_artist, filename_title, song_dir): filename_artist = misc.strip_all_slashes(filename_artist) filename_title = misc.strip_all_slashes(filename_title) filename = self.info_check_for_local_lyrics(filename_artist, filename_title, song_dir) search_str = misc.link_markup(_("search"), True, True, self.linkcolor) edit_str = misc.link_markup(_("edit"), True, True, self.linkcolor) if filename: # If the lyrics only contain "not found", delete the file and try to # fetch new lyrics. If there is a bug in Sonata/SZI/LyricWiki that # prevents lyrics from being found, storing the "not found" will # prevent a future release from correctly fetching the lyrics. f = open(filename, 'r') lyrics = f.read() f.close() if lyrics == _("Lyrics not found"): misc.remove_file(filename) filename = self.info_check_for_local_lyrics( filename_artist, filename_title, song_dir) if filename: # Re-use lyrics from file: f = open(filename, 'r') lyrics = f.read() f.close() # Strip artist - title line from file if it exists, since we # now have that information visible elsewhere. header = filename_artist + " - " + filename_title + "\n\n" if lyrics[:len(header)] == header: lyrics = lyrics[len(header):] gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) gobject.idle_add(self.info_searchlabel.set_markup, search_str) gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str) else: # Use default filename: filename = self.target_lyrics_filename(filename_artist, filename_title, song_dir) # Fetch lyrics from lyricwiki.org gobject.idle_add(self.info_show_lyrics, _("Fetching lyrics..."), filename_artist, filename_title) if self.lyricServer is None: wsdlFile = "http://lyricwiki.org/server.php?wsdl" try: self.lyricServer = True timeout = socketgettimeout() socketsettimeout(consts.LYRIC_TIMEOUT) self.lyricServer = ServiceProxy.ServiceProxy( wsdlFile, cachedir=os.path.expanduser("~/.service_proxy_dir")) except: socketsettimeout(timeout) lyrics = _("Couldn't connect to LyricWiki") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) self.lyricServer = None gobject.idle_add(self.info_searchlabel.set_markup, search_str) gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str) return try: timeout = socketgettimeout() socketsettimeout(consts.LYRIC_TIMEOUT) lyrics = self.lyricServer.getSong( artist=self.lyricwiki_format(search_artist), song=self.lyricwiki_format( search_title))['return']["lyrics"] if lyrics.lower() != "not found": lyrics = misc.unescape_html(lyrics) lyrics = misc.wiki_to_html(lyrics) lyrics = lyrics.encode("ISO-8859-1") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) # Save lyrics to file: misc.create_dir('~/.lyrics/') f = open(filename, 'w') lyrics = misc.unescape_html(lyrics) try: f.write(lyrics.decode(self.enc).encode('utf8')) except: f.write(lyrics) f.close() else: lyrics = _("Lyrics not found") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) except: lyrics = _("Fetching lyrics failed") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) gobject.idle_add(self.info_searchlabel.set_markup, search_str) gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str) socketsettimeout(timeout)
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 = ""