Exemplo n.º 1
0
 def setUp(self):
     fd, self.filename = mkstemp()
     os.close(fd)
     config.init()
     self.wrap = SongWrapper(
         AudioFile({
             "title": "woo",
             "~filename": self.filename
         }))
    def _update_album(self, songs):
        song_wrappers = []

        req_play_counts_above_zero = CONFIG.ensure_play_counts_above_zero
        for song in songs:
            if req_play_counts_above_zero and not song.get("~#playcount", 0):
                song['~#playcount'] = 1

            wrapper = SongWrapper(song)
            wrapper._needs_write = True
            song_wrappers.append(wrapper)

        self._write_tags_to_files(song_wrappers)
Exemplo n.º 3
0
 def test_cmp(self):
     songs = [
         SongWrapper(AudioFile({"tracknumber": str(i)})) for i in range(10)
     ]
     songs.reverse()
     songs.sort()
     self.failUnlessEqual([s("~#track") for s in songs], range(10))
Exemplo n.º 4
0
    def enabled(self):
        self.scrolled_window = Gtk.ScrolledWindow()
        self.scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC,
                                        Gtk.PolicyType.AUTOMATIC)
        self.adjustment = self.scrolled_window.get_vadjustment()

        self.textview = Gtk.TextView()
        self.textbuffer = self.textview.get_buffer()
        self._italics = self.textbuffer.create_tag("italic",
                                                   style="italic",
                                                   foreground="grey")
        self.textview.set_editable(False)
        self.textview.set_cursor_visible(False)
        self.textview.set_wrap_mode(Gtk.WrapMode.WORD)
        self.textview.set_justification(Gtk.Justification.CENTER)
        self.textview.connect('key-press-event', self.key_press_event_cb)
        add_css(self.textview, "* { padding: 6px; }")
        vbox = Gtk.VBox()
        vbox.pack_start(self.textview, True, True, 0)
        self._edit_button = Button("Edit Lyrics", Icons.EDIT)
        hbox = Gtk.HBox()
        hbox.pack_end(self._edit_button, False, False, 3)
        vbox.pack_start(hbox, False, False, 3)
        self.scrolled_window.add(vbox)
        self.textview.show()

        self.scrolled_window.show()
        self._sig = None
        cur = app.player.info
        if cur is not None:
            cur = SongWrapper(cur)
        self.plugin_on_song_started(cur)
Exemplo n.º 5
0
    def __invoke(self, librarian, event, *args):
        args = list(args)
        if args and args[0]:
            if isinstance(args[0], dict):
                args[0] = SongWrapper(args[0])
            elif isinstance(args[0], (set, list)):
                args[0] = ListWrapper(args[0])
        for plugin in itervalues(self.__plugins):
            method_name = 'plugin_on_' + event.replace('-', '_')
            handler = getattr(plugin, method_name, None)

            def overridden(obj, name):
                return name in type(obj).__dict__

            if overridden(plugin, method_name):
                try:
                    handler(*args)
                except Exception:
                    print_e("Error during %s on %s" %
                            (method_name, type(plugin)))
                    util.print_exc()

        if event not in ["removed", "changed"] and args:
            from quodlibet import app
            songs = args[0]
            if not isinstance(songs, (set, list)):
                songs = [songs]
            songs = filter(None, songs)
            check_wrapper_changed(librarian, app.window, songs)
Exemplo n.º 6
0
 def plugin_on_changed(self, songs):
     cur = app.player.info
     if cur:
         fn = cur("~filename")
         for s in songs:
             if s("~filename") == fn:
                 print_d("Active song changed, reloading lyrics")
                 self.plugin_on_song_started(SongWrapper(cur))
     else:
         self._set_italicised(_("No active song"))
Exemplo n.º 7
0
    def run(self, songs, playlist_name=None):
        """
        Runs this command on `songs`,
        splitting into multiple calls if necessary.
        `playlist_name` if populated contains the Playlist's name.
        """
        args = []
        template_vars = {}
        if self.parameter:
            value = GetStringDialog(None, _("Input value"),
                                    _("Value for %s?") % self.parameter).run()
            template_vars[self.parameter] = value
        if playlist_name:
            print_d("Playlist command for %s" % playlist_name)
            template_vars["PLAYLIST"] = playlist_name

        actual_command = self.command.format(**template_vars)
        print_d("Actual command=%s" % actual_command)
        for i, song in enumerate(songs):
            wrapped = SongWrapper(song)
            if playlist_name:
                wrapped["~playlistname"] = playlist_name
                wrapped["~playlistindex"] = str(i + 1)
                wrapped["~#playlistindex"] = i + 1
            arg = str(self.__pat.format(wrapped))
            if not arg:
                print_w("Couldn't build shell command using \"%s\"."
                        "Check your pattern?" % self.pattern)
                break
            if not self.unique:
                args.append(arg)
            elif arg not in args:
                args.append(arg)
        max = int((self.max_args or 10000))
        com_words = actual_command.split(" ")

        if self.reverse:
            args.reverse()

        while args:
            print_d(
                "Running %s with %d substituted arg(s) (of %d%s total)..." %
                (actual_command, min(max, len(args)), len(args),
                 " unique" if self.unique else ""))
            util.spawn(com_words + args[:max])
            args = args[max:]
Exemplo n.º 8
0
    def __invoke(self, librarian, event, *args):
        args = list(args)
        if args and args[0]:
            if isinstance(args[0], dict):
                args[0] = SongWrapper(args[0])
            elif isinstance(args[0], (set, list)):
                args[0] = ListWrapper(args[0])
        for plugin in self.__plugins.itervalues():
            method_name = 'plugin_on_' + event.replace('-', '_')
            handler = getattr(plugin, method_name, None)
            if handler is not None:
                try:
                    handler(*args)
                except Exception:
                    util.print_exc()

        if event not in ["removed", "changed"] and args:
            from quodlibet import app
            songs = args[0]
            if not isinstance(songs, (set, list)):
                songs = [songs]
            songs = filter(None, songs)
            check_wrapper_changed(librarian, app.window, songs)
Exemplo n.º 9
0
# -*- coding: utf-8 -*-
# Copyright 2017 Nick Boultbee
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

from quodlibet import app
from quodlibet.formats import AudioFile
from quodlibet.util.songwrapper import SongWrapper
from tests import init_fake_app, destroy_fake_app
from tests.plugin import PluginTestCase

AUDIO_FILE = SongWrapper(AudioFile({'~filename': "/tmp/foobar",
                                    'lyrics': 'Never gonna give you up'}))


class TViewlyrics(PluginTestCase):

    def setUp(self):
        self.mod = self.modules['View Lyrics']
        init_fake_app()
        self.plugin = self.mod.ViewLyrics()
        self.plugin.enabled()

    def tearDown(self):
        destroy_fake_app()
        del self.mod

    def test_no_song_started(self):
Exemplo n.º 10
0
 def test_on_changed(self):
     app.player.info = AUDIO_FILE
     self.plugin.plugin_on_changed([SongWrapper(AUDIO_FILE)])
     tb = self.plugin.textbuffer
     actual = tb.get_text(tb.get_start_iter(), tb.get_end_iter(), True)
     self.failUnlessEqual(actual, AUDIO_FILE("lyrics"))
Exemplo n.º 11
0
 def test_song_started(self):
     self.plugin.plugin_on_song_started(SongWrapper(AUDIO_FILE))
Exemplo n.º 12
0
class TSongWrapper(TestCase):

    psong = AudioFile({
        "~filename": "does not/exist",
        "title": "more songs",
        "discnumber": "2/2", "tracknumber": "1",
        "artist": "Foo\nI have two artists", "album": "Bar",
        "~bookmark": "2:10 A bookmark"})
    pwrap = SongWrapper(psong)

    def setUp(self):
        fd, self.filename = mkstemp()
        os.close(fd)
        config.init()
        self.wrap = SongWrapper(AudioFile(
            {"title": "woo", "~filename": self.filename}))

    def tearDown(self):
        os.unlink(self.filename)
        config.quit()

    def test_slots(self):
        def breakme():
            self.wrap.woo = 1
        self.failUnlessRaises(AttributeError, breakme)

    def test_cmp(self):
        songs = [SongWrapper(AudioFile({"tracknumber": str(i)}))
                 for i in range(10)]
        songs.reverse()
        songs.sort()
        self.failUnlessEqual([s("~#track") for s in songs], list(range(10)))

    def test_needs_write_yes(self):
        self.failIf(self.wrap._needs_write)
        self.wrap["woo"] = "bar"
        self.failUnless(self.wrap._needs_write)

    def test_needs_write_no(self):
        self.failIf(self.wrap._needs_write)
        self.wrap["~woo"] = "bar"
        self.failIf(self.wrap._needs_write)

    def test_pop(self):
        self.failIf(self.wrap._needs_write)
        self.wrap.pop("artist", None)
        self.failUnless(self.wrap._needs_write)

    def test_getitem(self):
        self.failUnlessEqual(self.wrap["title"], "woo")

    def test_get(self):
        self.failUnlessEqual(self.wrap.get("title"), "woo")
        self.failUnlessEqual(self.wrap.get("dne"), None)
        self.failUnlessEqual(self.wrap.get("dne", "huh"), "huh")

    def test_delitem(self):
        self.failUnless("title" in self.wrap)
        del(self.wrap["title"])
        self.failIf("title" in self.wrap)
        self.failUnless(self.wrap._needs_write)

    def test_realkeys(self):
        self.failUnlessEqual(self.pwrap.realkeys(), self.psong.realkeys())

    def test_can_change(self):
        for key in ["~foo", "title", "whee", "a test", "foo=bar", ""]:
            self.failUnlessEqual(
                self.pwrap.can_change(key), self.psong.can_change(key))

    def test_comma(self):
        for key in ["title", "artist", "album", "notexist", "~length"]:
            self.failUnlessEqual(self.pwrap.comma(key), self.psong.comma(key))

    def test_list(self):
        for key in ["title", "artist", "album", "notexist", "~length"]:
            self.failUnlessEqual(self.pwrap.list(key), self.psong.list(key))

    def test_dicty(self):
        self.failUnlessEqual(self.pwrap.keys(), self.psong.keys())
        self.failUnlessEqual(
            list(self.pwrap.values()), list(self.psong.values()))
        self.failUnlessEqual(self.pwrap.items(), self.psong.items())

    def test_mtime(self):
        self.wrap._song.sanitize()
        self.failUnless(self.wrap.valid())
        self.wrap["~#mtime"] = os.path.getmtime(self.filename) - 2
        self.wrap._updated = False
        self.failIf(self.wrap.valid())

    def test_setitem(self):
        self.failIf(self.wrap._was_updated())
        self.wrap["title"] = "bar"
        self.failUnless(self.wrap._was_updated())
        self.failUnlessEqual(self.wrap["title"], "bar")

    def test_not_really_updated(self):
        self.failIf(self.wrap._was_updated())
        self.wrap["title"] = "woo"
        self.failIf(self.wrap._was_updated())
        self.wrap["title"] = "quux"
        self.failUnless(self.wrap._was_updated())

    def test_new_tag(self):
        self.failIf(self.wrap._was_updated())
        self.wrap["version"] = "bar"
        self.failUnless(self.wrap._was_updated())

    def test_bookmark(self):
        self.failUnlessEqual(self.psong.bookmarks, self.pwrap.bookmarks)
        self.pwrap.bookmarks = [(43, "another mark")]
        self.failUnlessEqual(self.psong["~bookmark"], "0:43 another mark")
        self.failUnlessEqual(self.psong.bookmarks, self.pwrap.bookmarks)
Exemplo n.º 13
0
 def setUp(self):
     fd, self.filename = mkstemp()
     os.close(fd)
     config.init()
     self.wrap = SongWrapper(AudioFile(
         {"title": "woo", "~filename": self.filename}))
Exemplo n.º 14
0
def wrap_songs(songs):
    return [SongWrapper(s) for s in songs]
Exemplo n.º 15
0
 def test_starts_up(self):
     sws = [SongWrapper(s) for s in app.library.songs]
     self.plugin.plugin_songs(sws).destroy()
Exemplo n.º 16
0
 def setUp(self):
     config.init()
     self.wrap = SongWrapper(AudioFile(
         {"title": "woo", "~filename": "/dev/null"}))
Exemplo n.º 17
0
class TSongWrapper(TestCase):

    psong = AudioFile({
        "~filename": "does not/exist",
        "title": "more songs",
        "discnumber": "2/2",
        "tracknumber": "1",
        "artist": "Foo\nI have two artists",
        "album": "Bar",
        "~bookmark": "2:10 A bookmark"
    })
    pwrap = SongWrapper(psong)

    def setUp(self):
        fd, self.filename = mkstemp()
        os.close(fd)
        config.init()
        self.wrap = SongWrapper(
            AudioFile({
                "title": "woo",
                "~filename": self.filename
            }))

    def tearDown(self):
        os.unlink(self.filename)
        config.quit()

    def test_slots(self):
        def breakme():
            self.wrap.woo = 1

        self.failUnlessRaises(AttributeError, breakme)

    def test_cmp(self):
        songs = [
            SongWrapper(AudioFile({"tracknumber": str(i)})) for i in range(10)
        ]
        songs.reverse()
        songs.sort()
        self.failUnlessEqual([s("~#track") for s in songs], range(10))

    def test_needs_write_yes(self):
        self.failIf(self.wrap._needs_write)
        self.wrap["woo"] = "bar"
        self.failUnless(self.wrap._needs_write)

    def test_needs_write_no(self):
        self.failIf(self.wrap._needs_write)
        self.wrap["~woo"] = "bar"
        self.failIf(self.wrap._needs_write)

    def test_pop(self):
        self.failIf(self.wrap._needs_write)
        self.wrap.pop("artist", None)
        self.failUnless(self.wrap._needs_write)

    def test_getitem(self):
        self.failUnlessEqual(self.wrap["title"], "woo")

    def test_get(self):
        self.failUnlessEqual(self.wrap.get("title"), "woo")
        self.failUnlessEqual(self.wrap.get("dne"), None)
        self.failUnlessEqual(self.wrap.get("dne", "huh"), "huh")

    def test_delitem(self):
        self.failUnless("title" in self.wrap)
        del (self.wrap["title"])
        self.failIf("title" in self.wrap)
        self.failUnless(self.wrap._needs_write)

    def test_realkeys(self):
        self.failUnlessEqual(self.pwrap.realkeys(), self.psong.realkeys())

    def test_website(self):
        self.failUnlessEqual(self.pwrap.website(), self.psong.website())

    def test_can_change(self):
        for key in ["~foo", "title", "whee", "a test", "foo=bar", ""]:
            self.failUnlessEqual(self.pwrap.can_change(key),
                                 self.psong.can_change(key))

    def test_comma(self):
        for key in ["title", "artist", "album", "notexist", "~length"]:
            self.failUnlessEqual(self.pwrap.comma(key), self.psong.comma(key))

    def test_list(self):
        for key in ["title", "artist", "album", "notexist", "~length"]:
            self.failUnlessEqual(self.pwrap.list(key), self.psong.list(key))

    def test_dicty(self):
        self.failUnlessEqual(self.pwrap.keys(), self.psong.keys())
        self.failUnlessEqual(self.pwrap.values(), self.psong.values())
        self.failUnlessEqual(self.pwrap.items(), self.psong.items())

    def test_mtime(self):
        self.wrap._song.sanitize()
        self.failUnless(self.wrap.valid())
        self.wrap["~#mtime"] = os.path.getmtime(self.filename) - 2
        self.wrap._updated = False
        self.failIf(self.wrap.valid())

    def test_setitem(self):
        self.failIf(self.wrap._was_updated())
        self.wrap["title"] = "bar"
        self.failUnless(self.wrap._was_updated())
        self.failUnlessEqual(self.wrap["title"], "bar")

    def test_not_really_updated(self):
        self.failIf(self.wrap._was_updated())
        self.wrap["title"] = "woo"
        self.failIf(self.wrap._was_updated())
        self.wrap["title"] = "quux"
        self.failUnless(self.wrap._was_updated())

    def test_new_tag(self):
        self.failIf(self.wrap._was_updated())
        self.wrap["version"] = "bar"
        self.failUnless(self.wrap._was_updated())

    def test_bookmark(self):
        self.failUnlessEqual(self.psong.bookmarks, self.pwrap.bookmarks)
        self.pwrap.bookmarks = [(43, "another mark")]
        self.failUnlessEqual(self.psong["~bookmark"], "0:43 another mark")
        self.failUnlessEqual(self.psong.bookmarks, self.pwrap.bookmarks)
Exemplo n.º 18
0
# Copyright 2017 Christoph Reiter
#           2021 halfbrained@github
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

from gi.repository import Gtk

from quodlibet.formats import AudioFile
from quodlibet.util.songwrapper import SongWrapper
from tests.plugin import PluginTestCase

AUDIO_FILE = SongWrapper(AudioFile({'~filename': "/tmp/foobar"}))


class Dummy:
    dummy_val = "str!"

    def dummy_meth(self, arg, varg=101):
        pass


DUMMY_COMPLETIONS = [
    ('dummy_meth', ' (arg, varg=101)'),
    ('dummy_val', ''),
]
NAMESPACE_COMPLETIONS = ('dummy', '')