Exemplo n.º 1
0
def create_exportable_temp_file_object(fileobj):
    try:
        cache_dir = os.path.join(quodlibet.get_cache_dir(), "tempcovers")
        mkdir(cache_dir, 0o700)
        fn = NamedTemporaryFile(dir=cache_dir)
        fn.write(fileobj.read())
        fn.flush()
        fn.seek(0, 0)
    except EnvironmentError:
        return
    else:
        return fn
Exemplo n.º 2
0
def get_thumbnail_folder():
    """Returns a path to the thumbnail folder.

    The returned path might not exist.
    """

    if os.name == "nt":
        thumb_folder = os.path.join(quodlibet.get_cache_dir(), "thumbnails")
    else:
        cache_folder = os.path.join(xdg_get_cache_home(), "thumbnails")
        thumb_folder = os.path.expanduser('~/.thumbnails')
        if os.path.exists(cache_folder) or not os.path.exists(thumb_folder):
            thumb_folder = cache_folder

    return thumb_folder
Exemplo n.º 3
0
 def test_dirs(self):
     self.assertTrue(isinstance(quodlibet.get_base_dir(), fsnative))
     self.assertTrue(isinstance(quodlibet.get_image_dir(), fsnative))
     self.assertTrue(isinstance(quodlibet.get_user_dir(), fsnative))
     self.assertTrue(isinstance(quodlibet.get_cache_dir(), fsnative))
Exemplo n.º 4
0
    def fetch_cover(self):
        """
        Method to ask source fetch the cover from its source into location at
        `self.cover_path`.

        If this method succeeds in putting the image from its source into
        `self.cover_path`, `fetch-success` signal shall be emitted and
        `fetch-failure` otherwise.

        Return value of this function doesn't have any meaning whatsoever.
        """
        self.fail('This source is incapable of fetching covers')

    def fail(self, message):
        """
        Shorthand method for emitting `fetch-failure` signals.

        Most common use pattern would be:
            return self.fail("Failure message")
        """
        self.emit('fetch-failure', message)


cover_dir = path.join(get_cache_dir(), 'covers')

try:
    makedirs(cover_dir)
except OSError:
    pass
Exemplo n.º 5
0
    def PluginPreferences(self, *args):
        vb = Gtk.VBox()

        row = 0
        grid = Gtk.Grid(column_spacing=12, row_spacing=6)

        def label_title(text):
            l = Gtk.Label(label=text, xalign=1, yalign=0, wrap=True,
                          justify=Gtk.Justification.RIGHT, selectable=True)
            l.get_style_context().add_class(Gtk.STYLE_CLASS_DIM_LABEL)
            return l

        def label_value(text):
            return Gtk.Label(label=text, wrap=True, xalign=0, yalign=0,
                             width_chars=25, selectable=True)

        def label_path(path):
            l = Gtk.Label(label="<a href='%s'>%s</a>" % (
                            fsn2uri(path), escape(fsn2text(unexpand(path)))),
                          use_markup=True,
                          ellipsize=Pango.EllipsizeMode.MIDDLE,
                          xalign=0,
                          selectable=True)

            l.connect("activate-link", show_uri)
            return l

        grid.insert_row(row)
        l = label_title(_("Supported Formats"))
        format_names = sorted([t.format for t in formats.types])
        v = label_value(", ".join(format_names))
        grid.attach(l, 0, row, 1, 1)
        grid.attach(v, 1, row, 1, 1)
        row += 1

        grid.insert_row(row)
        l = label_title(_("Configuration Directory"))
        v = label_path(get_user_dir())
        grid.attach(l, 0, row, 1, 1)
        grid.attach(v, 1, row, 1, 1)
        row += 1

        grid.insert_row(row)
        l = label_title(_("Cache Directory"))
        v = label_path(get_cache_dir())
        grid.attach(l, 0, row, 1, 1)
        grid.attach(v, 1, row, 1, 1)
        row += 1

        grid.insert_row(row)
        l = label_title(_("Audio Backend"))
        v = label_value("%s\n%s" % (app.player.name, app.player.version_info))
        grid.attach(l, 0, row, 1, 1)
        grid.attach(v, 1, row, 1, 1)
        row += 1

        grid.insert_row(row)
        l = label_title("Python")
        v = label_value(platform.python_version())
        grid.attach(l, 0, row, 1, 1)
        grid.attach(v, 1, row, 1, 1)
        row += 1

        grid.insert_row(row)
        l = label_title("Mutagen")
        v = label_value(fver(mutagen.version))
        grid.attach(l, 0, row, 1, 1)
        grid.attach(v, 1, row, 1, 1)
        row += 1

        grid.insert_row(row)
        l = label_title("Gtk+")
        v = label_value("%s (%s, %s)" % (
            fver(gtk_version), get_backend_name(), get_font_backend_name()))
        grid.attach(l, 0, row, 1, 1)
        grid.attach(v, 1, row, 1, 1)
        row += 1

        grid.insert_row(row)
        l = label_title("PyGObject")
        v = label_value(fver(pygobject_version))
        grid.attach(l, 0, row, 1, 1)
        grid.attach(v, 1, row, 1, 1)
        row += 1

        vb.pack_start(grid, True, True, 0)
        vb.show_all()

        return vb
Exemplo n.º 6
0
    def fetch_cover(self):
        """
        Method to ask source fetch the cover from its source into location at
        `self.cover_path`.

        If this method succeeds in putting the image from its source into
        `self.cover_path`, `fetch-success` signal shall be emitted and
        `fetch-failure` otherwise.

        Return value of this function doesn't have any meaning whatsoever.
        """
        self.fail('This source is incapable of fetching covers')

    def fail(self, message):
        """
        Shorthand method for emitting `fetch-failure` signals.

        Most common use pattern would be:
            return self.fail("Failure message")
        """
        self.emit('fetch-failure', message)


cover_dir = path.join(get_cache_dir(), 'covers')

try:
    makedirs(cover_dir)
except OSError:
    pass
Exemplo n.º 7
0
USER_DATA_KEYS = " ".join(MIGRATE | {PLAYLISTS_KEY})

# Could be made configurable in the future, but these likely suffice
# "tag1 tag2" will result in only tag1 and tag2 being exported
# * means all tags (so tags like 'title' and internal (user data) "tags" like ~#added)
# * tag1 tag2 means all except tag1 and tag2
EXPORT_OPTIONS = [(_("Export User Data"), USER_DATA_KEYS),
                  (_("Export Tags"), f"* {USER_DATA_KEYS} {FILE_STEM_KEY}"),
                  (_("Export Tags and User Data"), f"* {FILE_STEM_KEY}"),
                  (_("Export File Stems and User Data"), f"{USER_DATA_KEYS} "
                   f"{FILE_STEM_KEY}"),
                  (_("Export File Stems and Tags"), f"* {USER_DATA_KEYS}"),
                  (_("Export File Stems, Tags and User Data"), "*")]

EXPORT_DIR_PATH = Path(quodlibet.get_cache_dir(), 'tags_and_track_user_data')
os.makedirs(EXPORT_DIR_PATH, exist_ok=True)

EXPORT_EXTENSION = 'json'
TAGS_AND_USERDATA_INDEX_FILE_PATH = EXPORT_DIR_PATH / f'index.{EXPORT_EXTENSION}'


def move_export_to_used(export_path: Path):
    used_path = EXPORT_DIR_PATH / 'used'
    used_path.mkdir(exist_ok=True)

    export_path.rename(used_path / export_path.name)


class AlbumId(NamedTuple):
    id_value: str
Exemplo n.º 8
0
    def PluginPreferences(self, *args):
        vb = Gtk.VBox()

        row = 0
        grid = Gtk.Grid(column_spacing=12, row_spacing=6)

        def label_title(text):
            l = Gtk.Label(label=text, xalign=1, yalign=0, wrap=True,
                          justify=Gtk.Justification.RIGHT, selectable=True)
            l.get_style_context().add_class(Gtk.STYLE_CLASS_DIM_LABEL)
            return l

        def label_value(text):
            return Gtk.Label(label=text, wrap=True, xalign=0, yalign=0,
                             width_chars=25, selectable=True)

        def label_path(path):
            l = Gtk.Label(label="<a href='%s'>%s</a>" % (
                            fsn2uri(path), escape(fsn2text(unexpand(path)))),
                          use_markup=True,
                          ellipsize=Pango.EllipsizeMode.MIDDLE,
                          xalign=0,
                          selectable=True)

            l.connect("activate-link", show_uri)
            return l

        grid.insert_row(row)
        l = label_title(_("Supported Formats"))
        format_names = sorted([t.format for t in formats.types])
        v = label_value(", ".join(format_names))
        grid.attach(l, 0, row, 1, 1)
        grid.attach(v, 1, row, 1, 1)
        row += 1

        grid.insert_row(row)
        l = label_title(_("Configuration Directory"))
        v = label_path(get_user_dir())
        grid.attach(l, 0, row, 1, 1)
        grid.attach(v, 1, row, 1, 1)
        row += 1

        grid.insert_row(row)
        l = label_title(_("Cache Directory"))
        v = label_path(get_cache_dir())
        grid.attach(l, 0, row, 1, 1)
        grid.attach(v, 1, row, 1, 1)
        row += 1

        grid.insert_row(row)
        l = label_title(_("Audio Backend"))
        v = label_value("%s\n%s" % (app.player.name, app.player.version_info))
        grid.attach(l, 0, row, 1, 1)
        grid.attach(v, 1, row, 1, 1)
        row += 1

        grid.insert_row(row)
        l = label_title("Python")
        v = label_value(platform.python_version())
        grid.attach(l, 0, row, 1, 1)
        grid.attach(v, 1, row, 1, 1)
        row += 1

        grid.insert_row(row)
        l = label_title("Mutagen")
        v = label_value(fver(mutagen.version))
        grid.attach(l, 0, row, 1, 1)
        grid.attach(v, 1, row, 1, 1)
        row += 1

        grid.insert_row(row)
        l = label_title("Gtk+")
        v = label_value("%s (%s)" % (fver(gtk_version), get_backend_name()))
        grid.attach(l, 0, row, 1, 1)
        grid.attach(v, 1, row, 1, 1)
        row += 1

        grid.insert_row(row)
        l = label_title("PyGObject")
        v = label_value(fver(pygobject_version))
        grid.attach(l, 0, row, 1, 1)
        grid.attach(v, 1, row, 1, 1)
        row += 1

        vb.pack_start(grid, True, True, 0)
        vb.show_all()

        return vb