Ejemplo n.º 1
0
 def test_to_dump_unicode(self):
     b = AudioFile(bar_1_1)
     b[u"öäü"] = u"öäü"
     dump = b.to_dump()
     n = AudioFile()
     n.from_dump(dump)
     self.assertEqual(n[u"öäü"], u"öäü")
Ejemplo n.º 2
0
 def test(self):
     album = [
         AudioFile({"tracknumber": "7"}),
         AudioFile({"tracknumber": "garbage"}),
         AudioFile({"tracknumber": "10/42"}),
     ]
     self.assertEqual(brainz.get_trackcount([]), 0)
     self.assertEqual(brainz.get_trackcount(album), 42)
Ejemplo n.º 3
0
    def test_people_individuals(self):
        q = AudioFile({"artist": "A\nX", "albumartist": "Various Artists"})
        self.failUnlessEqual(q.list("~people:real"), ["A", "X"])

        lonely = AudioFile({"artist": "various artists", "title": "blah"})
        self.failUnlessEqual(lonely.list("~people:real"), ["various artists"])

        lots = AudioFile({"artist": "Various Artists", "albumartist": "V.A."})
        self.failUnlessEqual(lots.list("~people:real"), ["Various Artists"])
Ejemplo n.º 4
0
 def setUp(self):
     self.rg_data = {
         "replaygain_album_gain": "-1.00 dB",
         "replaygain_album_peak": "1.1",
         "replaygain_track_gain": "+1.0000001 dB",
         "replaygain_track_peak": "0.9"
     }
     self.song = AudioFile(self.rg_data)
     self.no_rg_song = AudioFile()
Ejemplo n.º 5
0
    def test_to_dump_long(self):
        b = AudioFile(bar_1_1)
        b["~#length"] = 200000000000L
        dump = b.to_dump()
        num = len(set(bar_1_1.keys()) | INTERN_NUM_DEFAULT)
        self.failUnlessEqual(dump.count("\n"), num + 2)

        n = AudioFile()
        n.from_dump(dump)
        self.failUnless(set(dump.split("\n")) == set(n.to_dump().split("\n")))
Ejemplo n.º 6
0
 def setUp(self):
     self.p = NullPlayer()
     self.w = SongLibrary()
     self.s1 = AudioFile(
         {"~#playcount": 0, "~#skipcount": 0, "~#lastplayed": 10,
          "~filename": "foo", "~#length": 1.5})
     self.s2 = AudioFile(
         {"~#playcount": 0, "~#skipcount": 0, "~#lastplayed": 10,
          "~filename": "foo", "~#length": 1.5})
     self.cm = SongTracker(self.w, self.p, self)
     self.current = None
Ejemplo n.º 7
0
    def test_uri(self):
        # On windows where we have unicode paths (windows encoding is utf-16)
        # we need to encode to utf-8 first, then escape.
        # On linux we take the byte stream and escape it.
        # see g_filename_to_uri

        if os.name == "nt":
            f = AudioFile({"~filename": u"/\xf6\xe4.mp3", "title": "win"})
            self.failUnlessEqual(f("~uri"), "file:///%C3%B6%C3%A4.mp3")
        else:
            f = AudioFile({"~filename": "/\x87\x12.mp3", "title": "linux"})
            self.failUnlessEqual(f("~uri"), "file:///%87%12.mp3")
Ejemplo n.º 8
0
    def test_set_songs_restore_select(self):
        song = AudioFile({"~filename": "/dev/null"})
        self.songlist.add_songs([song])
        sel = self.songlist.get_selection()
        sel.select_path(Gtk.TreePath.new_first())

        self.songlist.set_songs([song], scroll_select=True)
        self.assertEqual(self.songlist.get_selected_songs(), [song])

        song2 = AudioFile({"~filename": "/dev/null"})
        self.songlist.set_songs([song2], scroll_select=True)
        self.assertEqual(self.songlist.get_selected_songs(), [])
 def test_weighted(self):
     self.pl.order = ORDERS[2](self.pl)
     r0 = AudioFile({'~#rating': 0})
     r1 = AudioFile({'~#rating': 1})
     r2 = AudioFile({'~#rating': 2})
     r3 = AudioFile({'~#rating': 3})
     self.pl.set([r0, r1, r2, r3])
     Gtk.main_iteration_do(False)
     songs = [self.pl.current for i in range(1000)
              if self.pl.next() or True]
     self.assert_(songs.count(r1) > songs.count(r0))
     self.assert_(songs.count(r2) > songs.count(r1))
     self.assert_(songs.count(r3) > songs.count(r2))
Ejemplo n.º 10
0
 def test_sanitize(self):
     q = AudioFile(quux)
     b = AudioFile(bar_1_1)
     q.sanitize()
     b.pop('~filename')
     self.failUnlessRaises(ValueError, b.sanitize)
     n = AudioFile({
         "artist": u"foo\0bar",
         "title": u"baz\0",
         "~filename": fsnative(u"whatever")
     })
     n.sanitize()
     self.failUnlessEqual(n["artist"], "foo\nbar")
     self.failUnlessEqual(n["title"], "baz")
Ejemplo n.º 11
0
    def test_cover_path(self):
        song = AudioFile({"musicbrainz_albumid": u"foobar"})
        song2 = AudioFile()

        # missing Soup
        if "lastfm-cover" in self.plugins:
            cls = self.plugins["lastfm-cover"].cls
            self.assertTrue(is_fsnative(cls(song).cover_path))
            self.assertTrue(is_fsnative(cls(song2).cover_path))

        # missing Soup
        if "musicbrainz-cover" in self.plugins:
            cls = self.plugins["musicbrainz-cover"].cls
            self.assertTrue(is_fsnative(cls(song).cover_path))
            self.assertTrue(is_fsnative(cls(song2).cover_path))
Ejemplo n.º 12
0
    def test_dump_to_file(self):
        self.s["title"] = "artist - title"
        self.s.multisong = False
        dump = self.s.to_dump()
        new = AudioFile()
        new.from_dump(dump)
        self.assertEqual(new["title"], "title")
        self.assertEqual(new["artist"], "artist")

        del self.s["title"]
        dump = self.s.to_dump()
        new = AudioFile()
        new.from_dump(dump)
        self.assertTrue("title" not in new)
        self.assertTrue("artist" not in new)
Ejemplo n.º 13
0
    def test_embedded_special_cover_words(self):
        """Tests that words incidentally containing embedded "special" words
        album keywords (e.g. cover, disc, back) don't trigger
        See Issue 818"""

        song = AudioFile({
            "~filename": fsnative(u"tests/data/asong.ogg"),
            "album": "foobar",
            "title": "Ode to Baz",
            "artist": "Q-Man",
        })
        files = [self.full_path(f) for f in
                 ['back.jpg',
                  'discovery.jpg', "Pharell - frontin'.jpg",
                  'nickelback - Curb.jpg',
                  'foobar.jpg', 'folder.jpg',     # Though this is debatable
                  'Q-Man - foobar.jpg', 'Q-man - foobar (cover).jpg']]
        for f in files:
            file(f, "w").close()
            self.files.append(f)
            cover = self._find_cover(song)
            if cover:
                actual = os.path.abspath(cover.name)
                self.failUnlessEqual(
                    actual, f, "\"%s\" should trump \"%s\"" % (f, actual))
            else:
                self.failUnless(f, self.full_path('back.jpg'))
Ejemplo n.º 14
0
 def plugin_songs(self, songs):
     # Check this is a launch, not a configure
     if self.chosen_site:
         url_pat = self.get_url_pattern(self.chosen_site)
         pat = Pattern(url_pat)
         urls = set()
         for song in songs:
             # Generate a sanitised AudioFile; allow through most tags
             subs = AudioFile()
             for k in (USER_TAGS + MACHINE_TAGS):
                 vals = song.comma(k)
                 if vals:
                     try:
                         subs[k] = quote_plus(unicode(vals).encode('utf-8'))
                     # Dodgy unicode problems
                     except KeyError:
                         print_d("Problem with %s tag values: %r" %
                                 (k, vals))
             url = str(pat.format(subs))
             if not url:
                 print_w("Couldn't build URL using \"%s\"."
                         "Check your pattern?" % url_pat)
                 return
             # Grr, set.add() should return boolean...
             if url not in urls:
                 urls.add(url)
                 website(url)
Ejemplo n.º 15
0
    def test(self):
        lib = SongFileLibrary()

        with temp_filename() as song_fn:
            song = AudioFile({"~filename": song_fn})
            song.sanitize()
            lib.add([song])

            with temp_filename() as xml_fn:
                with open(xml_fn, "wb") as h:
                    x = get_example_xml(song("~filename"), 1, 1371802107)
                    h.write(x)

                handler = self.mod.RBDBContentHandler(lib)
                xml.sax.parse(xml_fn, handler)

                self.assertEqual(song("~#rating"), 0.2)
                self.assertEqual(song("~#lastplayed"), 1371802107)
                self.assertEqual(song("~#playcount"), 1)

                with open(xml_fn, "wb") as h:
                    x = get_example_xml(song("~filename"), 2, 1371802107 - 1)
                    h.write(x)

                handler = self.mod.RBDBContentHandler(lib)
                xml.sax.parse(xml_fn, handler)

                self.assertEqual(song("~#rating"), 0.4)
                self.assertEqual(song("~#lastplayed"), 1371802107)
Ejemplo n.º 16
0
 def test_album_key(self):
     album_key_tests = [
         ({}, ('', '', '')),
         ({
             'album': 'foo'
         }, (('foo', ), '', '')),
         ({
             'labelid': 'foo'
         }, ('', '', 'foo')),
         ({
             'musicbrainz_albumid': 'foo'
         }, ('', '', 'foo')),
         ({
             'album': 'foo',
             'labelid': 'bar'
         }, (('foo', ), '', 'bar')),
         ({
             'album': 'foo',
             'labelid': 'bar',
             'musicbrainz_albumid': 'quux'
         }, (('foo', ), '', 'bar')),
         ({
             'albumartist': 'a'
         }, ('', ('a', ), '')),
     ]
     for tags, expected in album_key_tests:
         afile = AudioFile(**tags)
         afile.sanitize(fsnative(u'/dir/fn'))
         self.failUnlessEqual(afile.album_key, expected)
Ejemplo n.º 17
0
 def test_add(self):
     song = AudioFile()
     self.failIf("foo" in song)
     song.add("foo", "bar")
     self.failUnlessEqual(song["foo"], "bar")
     song.add("foo", "another")
     self.failUnlessEqual(song.list("foo"), ["bar", "another"])
Ejemplo n.º 18
0
 def test_remove_all(self):
     song = AudioFile()
     song.add("foo", "bar")
     song.add("foo", "another")
     song.add("foo", "one more")
     song.remove("foo")
     self.assertFalse("foo" in song)
Ejemplo n.º 19
0
 def test_set_song(self):
     c = CoverImage()
     c.set_song(AudioFile({"~filename": "woo"}))
     event = Gdk.Event.new(Gdk.EventType.BUTTON_PRESS)
     event.type.button = 1
     c.emit("button-press-event", event)
     c.destroy()
Ejemplo n.º 20
0
 def test_people(self):
     q = AudioFile([("performer:vocals", "A"), ("performer:guitar", "B"),
                    ("performer", "C"), ("arranger", "A"),
                    ("albumartist", "B"), ("artist", "C")])
     self.failUnlessEqual(q.list("~people"), ["C", "B", "A"])
     self.failUnlessEqual(q.list("~people:roles"),
                          ["C", "B (Guitar)", "A (Arrangement, Vocals)"])
Ejemplo n.º 21
0
    def test_website(self):
        song = AudioFile()
        song["comment"] = "www.foo"
        song["contact"] = "*****@*****.**"
        self.failUnlessEqual(song.website(), "www.foo")
        song["contact"] = "https://www.foo.org"
        self.failUnlessEqual(song.website(), "https://www.foo.org")
        song["website"] = "foo\nhttps://another.com"
        self.failUnlessEqual(song.website(), "foo")

        song = AudioFile({"artist": "Artist", "album": "Album"})
        for value in song.values():
            self.failUnless(value in song.website())
        song["labelid"] = "QL-12345"
        self.failIf(song["artist"] in song.website())
        self.failUnless(song["labelid"] in song.website())
 def setUp(self):
     config.init()
     player = NullPlayer()
     song = AudioFile()
     song.bookmarks = [(10, "bla")]
     song.sanitize("/")
     player.song = song
     self.player = player
Ejemplo n.º 23
0
 def test_bookmark_invalid(self):
     af = AudioFile({
         "~bookmark": ("Not Valid\n1:40 Mark 2\n"
                       "-20 Not Valid 2\n1:20 Mark 1")
     })
     self.failUnlessEqual([(80, "Mark 1"),
                           (100, "Mark 2"), (-1, "Not Valid"),
                           (-1, "-20 Not Valid 2")], af.bookmarks)
Ejemplo n.º 24
0
 def test_msic(self):
     with realized(self.b):
         self.b.activate()
         self.b.statusbar(1000)
         self.b.statusbar(1)
         song = AudioFile({"~filename": fsnative(u"/fake")})
         song.sanitize()
         self.b.scroll(song)
Ejemplo n.º 25
0
 def test_lyric_filename(self):
     song = AudioFile()
     song["~filename"] = fsnative(u"filename")
     self.assertTrue(is_fsnative(song.lyric_filename))
     song["title"] = u"Title"
     song["artist"] = u"Artist"
     self.assertTrue(is_fsnative(song.lyric_filename))
     song["lyricist"] = u"Lyricist"
     self.assertTrue(is_fsnative(song.lyric_filename))
Ejemplo n.º 26
0
 def test_set_songs_no_restore_select(self):
     song = AudioFile({"~filename": "/dev/null"})
     self.songlist.add_songs([song])
     model = self.songlist.get_model()
     model.go_to(song)
     self.assertIs(model.current, song)
     # only restore if there was a selected one
     self.songlist.set_songs([song], scroll_select=True)
     self.assertEqual(self.songlist.get_selected_songs(), [])
Ejemplo n.º 27
0
 def test_menuitem(self):
     library = SongLibrary()
     library.librarian = SongLibrarian()
     a = AudioFile({"~filename": "/foo"})
     a.sanitize()
     x = RatingsMenuItem([a], library)
     x.set_rating(0, [a], library)
     x.destroy()
     library.destroy()
     library.librarian.destroy()
Ejemplo n.º 28
0
 def test_people_mix(self):
     q = AudioFile([
         ("performer:arrangement", "A"),
         ("arranger", "A"),
         ("performer", "A"),
         ("performer:foo", "A"),
     ])
     self.failUnlessEqual(q.list("~people"), ["A"])
     self.failUnlessEqual(q.list("~people:roles"),
                          ["A (Arrangement, Arrangement, Foo)"])
Ejemplo n.º 29
0
    def setUp(self):
        config.init()
        self.library = SongLibrary()
        backend = quodlibet.player.init("nullbe")
        self.device = backend.init(self.library)

        self.songs = [AudioFile({"title": x}) for x in
                      ["song1", "song2", "song3"]]
        for song in self.songs:
            song.sanitize(fsnative(unicode(song["title"])))
Ejemplo n.º 30
0
 def test_change(self):
     song = AudioFile()
     song.add("foo", "bar")
     song.add("foo", "another")
     song.change("foo", "bar", "one more")
     self.failUnlessEqual(song.list("foo"), ["one more", "another"])
     song.change("foo", "does not exist", "finally")
     self.failUnlessEqual(song["foo"], "finally")
     song.change("foo", "finally", "we're done")
     self.failUnlessEqual(song["foo"], "we're done")