def ftime(t): if t == 0: return _("Unknown") else: timestr = time.strftime("%c", time.localtime(t)) encoding = util.get_locale_encoding() return timestr.decode(encoding)
def __save(self, save, song, buffer, delete): start, end = buffer.get_bounds() text = buffer.get_text(start, end, True) # First, write back to the tags. song["lyrics"] = text.decode("utf-8") try: song.write() except AudioFileError: util.print_exc() # Then, write to file. # TODO: write to file only if could not write to tags, otherwise delete # the file. lyricname = song.lyric_filename try: os.makedirs(os.path.dirname(lyricname)) except EnvironmentError as err: pass try: with open(lyricname, "w") as f: f.write(text) except EnvironmentError as err: encoding = util.get_locale_encoding() print_w(err.strerror.decode(encoding, "replace")) delete.set_sensitive(True) save.set_sensitive(False)
def add_station(uri): """Fetches the URI content and extracts IRFiles""" irfs = [] if isinstance(uri, unicode): uri = uri.encode('utf-8') if uri.lower().endswith(".pls") or uri.lower().endswith(".m3u"): try: sock = urllib.urlopen(uri) except EnvironmentError as e: encoding = util.get_locale_encoding() try: err = e.strerror.decode(encoding, 'replace') except (TypeError, AttributeError): err = e.strerror[1].decode(encoding, 'replace') qltk.ErrorMessage(None, _("Unable to add station"), err).run() return [] if uri.lower().endswith(".pls"): irfs = ParsePLS(sock) elif uri.lower().endswith(".m3u"): irfs = ParseM3U(sock) sock.close() else: try: irfs = [IRFile(uri)] except ValueError, err: qltk.ErrorMessage(None, _("Unable to add station"), err).run()
def add_station(uri): """Fetches the URI content and extracts IRFiles""" irfs = [] if isinstance(uri, unicode): uri = uri.encode("utf-8") if uri.lower().endswith(".pls") or uri.lower().endswith(".m3u"): try: sock = urllib.urlopen(uri) except EnvironmentError as e: encoding = util.get_locale_encoding() try: err = e.strerror.decode(encoding, "replace") except (TypeError, AttributeError): err = e.strerror[1].decode(encoding, "replace") qltk.ErrorMessage(None, _("Unable to add station"), err).run() return [] if uri.lower().endswith(".pls"): irfs = ParsePLS(sock) elif uri.lower().endswith(".m3u"): irfs = ParseM3U(sock) sock.close() else: try: irfs = [IRFile(uri)] except ValueError as err: qltk.ErrorMessage(None, _("Unable to add station"), err).run() return irfs
def __search(self, song, buffer, refresh, add): artist = song.comma("artist") title = song.comma("title") try: sock = urllib.urlopen( "http://lyricwiki.org/api.php?" "client=QuodLibet&func=getSong&artist=%s&song=%s&fmt=text" % (urllib.quote(artist.encode('utf-8')), urllib.quote(title.encode('utf-8')))) text = sock.read() except Exception as err: encoding = util.get_locale_encoding() try: err = err.strerror.decode(encoding, 'replace') except: err = _("Unable to download lyrics.") GLib.idle_add(buffer.set_text, err) return sock.close() if text == 'Not found': GLib.idle_add(buffer.set_text, _("No lyrics found for this song.")) return else: GLib.idle_add(buffer.set_text, text) GLib.idle_add(refresh.set_sensitive, True)
def __search(self, song, buffer, refresh, add): artist = song.comma("artist") title = song.comma("title") try: sock = urlopen( "http://lyricwiki.org/api.php?" "client=QuodLibet&func=getSong&artist=%s&song=%s&fmt=text" % ( quote(artist.encode('utf-8')), quote(title.encode('utf-8')))) text = sock.read() except Exception as err: encoding = util.get_locale_encoding() try: err = err.strerror.decode(encoding, 'replace') except: err = _("Unable to download lyrics.") GLib.idle_add(buffer.set_text, err) return sock.close() if text == 'Not found': GLib.idle_add( buffer.set_text, _("No lyrics found for this song.")) return else: GLib.idle_add(buffer.set_text, text) GLib.idle_add(refresh.set_sensitive, True)
def delete(self, parent_widget, song): if self.__load_db() is None: return False try: for track in gpod.sw_get_tracks(self.__itdb): if gpod.itdb_filename_on_ipod(track) == song['~filename']: os.remove(song['~filename']) self.__remove_track(track) return True else: return False except IOError as exc: encoding = util.get_locale_encoding() return str(exc).decode(encoding, 'replace')
def __save(self, save, lyricname, buffer, delete): try: os.makedirs(os.path.dirname(lyricname)) except EnvironmentError as err: pass start, end = buffer.get_bounds() try: with open(lyricname, "w") as f: f.write(buffer.get_text(start, end, True)) except EnvironmentError as err: encoding = util.get_locale_encoding() print_w(err.strerror.decode(encoding, "replace")) delete.set_sensitive(True) save.set_sensitive(False)
def _apply_value(self, model, iter_, cell, stamp): if not stamp: cell.set_property('text', _("Never")) else: date = datetime.datetime.fromtimestamp(stamp).date() today = datetime.datetime.now().date() days = (today - date).days if days == 0: format_ = "%X" elif days < 7: format_ = "%A" else: format_ = "%x" stamp = time.localtime(stamp) encoding = util.get_locale_encoding() text = time.strftime(format_, stamp).decode(encoding) cell.set_property('text', text)
def __search(self, song, buffer, refresh, add): artist = song.comma("artist") title = song.comma("title") try: sock = urllib.urlopen( "http://lyricwiki.org/api.php?" "client=QuodLibet&func=getSong&artist=%s&song=%s&fmt=text" % ( urllib.quote(artist.encode('utf-8')), urllib.quote(title.encode('utf-8')))) text = sock.read() except Exception, err: encoding = util.get_locale_encoding() try: err = err.strerror.decode(encoding, 'replace') except: err = _("Unable to download lyrics.") GLib.idle_add(buffer.set_text, err) return
def _cdf(self, column, cell, model, iter_, user_data): stamp = model.get_value(iter_)(self.header_name) if not self._needs_update(stamp): return if not stamp: cell.set_property('text', _("Never")) else: date = datetime.datetime.fromtimestamp(stamp).date() today = datetime.datetime.now().date() days = (today - date).days if days == 0: format_ = "%X" elif days < 7: format_ = "%A" else: format_ = "%x" stamp = time.localtime(stamp) encoding = util.get_locale_encoding() text = time.strftime(format_, stamp).decode(encoding) cell.set_property('text', text)
def delete(self, parent_widget, song): try: path = song['~filename'] dir = os.path.dirname(path) os.unlink(path) self.__library.remove([song]) if self['unclutter']: files = glob(dir + '/*') if len(files) == 1 and os.path.isfile(files[0]) and \ os.path.basename(files[0]) == 'folder.jpg': os.unlink(files[0]) try: os.removedirs(os.path.dirname(path)) except OSError: pass return True except (OSError, IOError) as exc: encoding = util.get_locale_encoding() return str(exc).decode(encoding, 'replace')
def copy(self, parent_widget, song): if not self.__pattern: self.__set_pattern() target = strip_win32_incompat_from_path(self.__pattern.format(song)) dirname = os.path.dirname(target) if os.path.exists(target): dialog = ConfirmFileReplace(parent_widget, target) resp = dialog.run() if resp == ConfirmFileReplace.RESPONSE_REPLACE: try: # Remove the current song self.__library.remove([self.__library[target]]) except KeyError: pass else: return False try: if not os.path.isdir(dirname): os.makedirs(dirname) shutil.copyfile(song['~filename'], target) if self['covers']: coverfile = os.path.join(dirname, 'folder.jpg') cover = app.cover_manager.get_cover(song) if cover and mtime(cover.name) > mtime(coverfile): image = GdkPixbuf.Pixbuf.new_from_file_at_size( cover.name, 200, 200) image.savev(coverfile, "jpeg", [], []) song = copy.deepcopy(song) song.sanitize(target) self.__library.add([song]) return song except (OSError, IOError, GLib.GError) as exc: encoding = util.get_locale_encoding() return str(exc).decode(encoding, 'replace')
def add_station(uri): """Fetches the URI content and extracts IRFiles Returns None in error, else a possibly filled list of stations""" irfs = [] if isinstance(uri, unicode): uri = uri.encode('utf-8') if uri.lower().endswith(".pls") or uri.lower().endswith(".m3u"): try: sock = urlopen(uri) except EnvironmentError as e: print_d("Got %s from %s" % (uri, e)) encoding = util.get_locale_encoding() try: err = e.strerror.decode(encoding, 'replace') except TypeError: err = e.strerror[1].decode(encoding, 'replace') except AttributeError: # Give up and display the exception - may be useful HTTP info err = str(e) ErrorMessage(None, _("Unable to add station"), escape(err)).run() return None if uri.lower().endswith(".pls"): irfs = ParsePLS(sock) elif uri.lower().endswith(".m3u"): irfs = ParseM3U(sock) sock.close() else: try: irfs = [IRFile(uri)] except ValueError as err: ErrorMessage(None, _("Unable to add station"), err).run() return irfs
def test_main(self): assert isinstance(util.get_locale_encoding(), str)
buffer.set_text, _("No lyrics found for this song.")) return else: GLib.idle_add(buffer.set_text, text) GLib.idle_add(refresh.set_sensitive, True) def __save(self, save, lyricname, buffer, delete): try: os.makedirs(os.path.dirname(lyricname)) except EnvironmentError, err: pass try: f = file(lyricname, "w") except EnvironmentError as err: encoding = util.get_locale_encoding() print_w(err.strerror.decode(encoding, "replace")) else: start, end = buffer.get_bounds() f.write(buffer.get_text(start, end, True)) f.close() delete.set_sensitive(True) save.set_sensitive(False) def __delete(self, delete, lyricname, save): try: os.unlink(lyricname) except EnvironmentError: pass lyricname = os.path.dirname(lyricname) try: