예제 #1
0
 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)
예제 #2
0
    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)
예제 #3
0
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()
예제 #4
0
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
예제 #5
0
    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)
예제 #6
0
    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)
예제 #7
0
    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)
예제 #8
0
 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)
예제 #9
0
파일: ipod.py 프로젝트: urielz/quodlibet
 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')
예제 #10
0
 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')
예제 #11
0
    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)
예제 #12
0
    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)
예제 #13
0
 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)
예제 #14
0
 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)
예제 #15
0
    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
예제 #16
0
    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)
예제 #17
0
    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)
예제 #18
0
    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')
예제 #19
0
    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')
예제 #20
0
    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')
예제 #21
0
    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')
예제 #22
0
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
예제 #23
0
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
예제 #24
0
 def test_main(self):
     assert isinstance(util.get_locale_encoding(), str)
예제 #25
0
                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:
예제 #26
0
 def test_main(self):
     assert isinstance(util.get_locale_encoding(), str)