Example #1
0
 def task(self, musicbrainzrelease_id):
     release = models.MusicbrainzRelease.objects.get(pk=musicbrainzrelease_id)
     try:
         caa.get_image_list(release.mbid)
         has_coverart = True
     except musicbrainzngs.ResponseError:
         has_coverart = False
     ret = {}
     return (has_coverart, ret)
 def test_list_baduuid(self):
     exc = compat.HTTPError("", 400, "", "", _common.StringIO.StringIO(""))
     self.opener = _common.FakeOpener(exception=musicbrainzngs.ResponseError(cause=exc))
     musicbrainzngs.compat.build_opener = lambda *args: self.opener
     try:
         res = caa.get_image_list("8ec178f4-a8e8-4f22-bcba-19644XXXXXX")
         self.assertTrue(False, "Expected an exception")
     except musicbrainzngs.ResponseError as e:
         self.assertEqual(e.cause.code, 400)
 def test_get_list(self):
     # check the url and response for a listing
     resp = b'{"images":[]}'
     self.opener = _common.FakeOpener(resp)
     musicbrainzngs.compat.build_opener = lambda *args: self.opener
     res = caa.get_image_list("8ec178f4-a8e8-4f22-bcba-1964466ef214")
     self.assertEqual("http://coverartarchive.org/release/8ec178f4-a8e8-4f22-bcba-1964466ef214", self.opener.myurl)
     self.assertEqual(1, len(res))
     self.assertTrue("images" in res)
 def test_list_baduuid(self):
     exc = compat.HTTPError("", 400, "", "", _common.StringIO.StringIO(""))
     self.opener = _common.FakeOpener(
         exception=musicbrainzngs.ResponseError(cause=exc))
     musicbrainzngs.compat.build_opener = lambda *args: self.opener
     try:
         res = caa.get_image_list("8ec178f4-a8e8-4f22-bcba-19644XXXXXX")
         self.assertTrue(False, "Expected an exception")
     except musicbrainzngs.ResponseError as e:
         self.assertEqual(e.cause.code, 400)
 def test_get_list(self):
     # check the url and response for a listing
     resp = '{"images":[]}'
     self.opener = _common.FakeOpener(resp)
     musicbrainzngs.compat.build_opener = lambda *args: self.opener
     res = caa.get_image_list("8ec178f4-a8e8-4f22-bcba-1964466ef214")
     self.assertEqual(
         "http://coverartarchive.org/release/8ec178f4-a8e8-4f22-bcba-1964466ef214",
         self.opener.myurl)
     self.assertEqual(1, len(res))
     self.assertTrue("images" in res)
    def test_set_useragent(self):
        """ When a useragent is set it is sent with the request """
        musicbrainzngs.set_useragent("caa-test", "0.1")

        resp = b'{"images":[]}'
        self.opener = _common.FakeOpener(resp)
        musicbrainzngs.compat.build_opener = lambda *args: self.opener
        res = caa.get_image_list("8ec178f4-a8e8-4f22-bcba-1964466ef214")

        headers = dict(self.opener.headers)
        self.assertTrue("User-agent" in headers)
        self.assertEqual("caa-test/0.1 python-musicbrainzngs/%s" % _version, headers["User-agent"])
    def test_set_useragent(self):
        """ When a useragent is set it is sent with the request """
        musicbrainzngs.set_useragent("caa-test", "0.1")

        resp = '{"images":[]}'
        self.opener = _common.FakeOpener(resp)
        musicbrainzngs.compat.build_opener = lambda *args: self.opener
        res = caa.get_image_list("8ec178f4-a8e8-4f22-bcba-1964466ef214")

        headers = dict(self.opener.headers)
        self.assertTrue("User-agent" in headers)
        self.assertEqual("caa-test/0.1 python-musicbrainzngs/%s" % _version,
                         headers["User-agent"])
Example #8
0
        tags = []
        print 'R:', rec['recording']
        if 'tag-list' in rec['recording']:
            for t in rec['recording']['tag-list']:
                atag = t['name']
                try:
                    c.execute("INSERT INTO genre (name) VALUES (?)", (atag, ))
                except:
                    pass

                tags += [atag]
            mbtags = ",".join(tags)  # This is possibly where nosql may help...
            print mbtags
        coverart = None
        try:
            coverart = caa.get_image_list(webid)
        except:
            pass
        break  # just the first

    print 'update'

    c.execute("select xid, artist, name from hits where xid = ?", (xid, ))
    result = c.fetchone()
    if result is not None:
        # we have this already
        # in proper version, double check name mismatches, etc.
        print "Dupe hit ignored"
        pass
    else:
        c.execute(