コード例 #1
0
def show_collection(collection_id):
    """Show the list of releases in a given collection.
    """
    result = musicbrainzngs.get_releases_in_collection(collection_id, limit=25)
    collection = result["collection"]
    release_list = collection["release-list"]
    # release count is only available starting with musicbrainzngs 0.5
    if "release-count" in collection:
        release_count = collection["release-count"]
        print("{} releases in {}:".format(release_count, collection["name"]))
    else:
        print("Releases in {}:".format(collection["name"]))
    releases_fetched = 0
    while len(release_list) > 0:
        print("")
        releases_fetched += len(release_list)
        for release in release_list:
            print("{title} ({mbid})".format(title=release["title"], mbid=release["id"]))
        if user_input("Would you like to display more releases? [y/N] ") != "y":
            break

        # fetch next batch of releases
        result = musicbrainzngs.get_releases_in_collection(collection_id, limit=25, offset=releases_fetched)
        collection = result["collection"]
        release_list = collection["release-list"]

    print("")
    print("Number of fetched releases: %d" % releases_fetched)
コード例 #2
0
    def test_other_collection(self):
        """ If you ask for someone else's collection, you don't
        need to be authenticated."""

        old_mb_request = musicbrainzngs.musicbrainz._mb_request

        params = {}

        def local_mb_request(path,
                             method='GET',
                             auth_required=musicbrainzngs.musicbrainz.AUTH_NO,
                             client_required=False,
                             args=None,
                             data=None,
                             body=None):
            params["auth_required"] = auth_required

        musicbrainzngs.musicbrainz._mb_request = local_mb_request
        musicbrainzngs.get_releases_in_collection(
            "17905fdb-102d-40f0-91d3-eabcabc64fd3")
        # If _get_auth_type() returns AUTH_IFSET, then _mb_request()
        # should send the user credentials if they are set by auth()
        # i.e., We use whether auth() has been executed to determine if
        # the requested collection belongs to the user or not.
        self.assertEqual(musicbrainzngs.musicbrainz.AUTH_IFSET,
                         params["auth_required"])

        musicbrainzngs.musicbrainz._mb_request = old_mb_request
コード例 #3
0
def show_collection(collection_id):
    """Show the list of releases in a given collection.
    """
    result = musicbrainzngs.get_releases_in_collection(collection_id, limit=25)
    collection = result['collection']
    release_list = collection['release-list']
    # release count is only available starting with musicbrainzngs 0.5
    if "release-count" in collection:
        release_count = collection['release-count']
        print('{} releases in {}:'.format(release_count, collection['name']))
    else:
        print('Releases in {}:'.format(collection['name']))
    releases_fetched = 0
    while len(release_list) > 0:
        print("")
        releases_fetched += len(release_list)
        for release in release_list:
            print('{title} ({mbid})'.format(title=release['title'],
                                            mbid=release['id']))
        if user_input(
                "Would you like to display more releases? [y/N] ") != "y":
            break

        # fetch next batch of releases
        result = musicbrainzngs.get_releases_in_collection(
            collection_id, limit=25, offset=releases_fetched)
        collection = result['collection']
        release_list = collection['release-list']

    print("")
    print("Number of fetched releases: %d" % releases_fetched)
コード例 #4
0
    def test_other_collection(self):
        """ If you ask for someone else's collection, you don't
        need to be authenticated."""

        old_mb_request = musicbrainzngs.musicbrainz._mb_request

        params = {}
        def local_mb_request(path, method='GET', auth_required=False,
                client_required=False, args=None, data=None, body=None):
            params["auth_required"] = auth_required

        musicbrainzngs.musicbrainz._mb_request = local_mb_request
        musicbrainzngs.get_releases_in_collection("17905fdb-102d-40f0-91d3-eabcabc64fd3")
        self.assertEqual(False, params["auth_required"])

        musicbrainzngs.musicbrainz._mb_request = old_mb_request
コード例 #5
0
def show_collection(collection_id):
    """Show the list of releases in a given collection.
    """
    result = musicbrainzngs.get_releases_in_collection(collection_id)
    collection = result['collection']
    print('Releases in {}:'.format(collection['name']))
    for release in collection['release-list']:
        print('{title} ({mbid})'.format(title=release['title'],
                                        mbid=release['id']))
コード例 #6
0
    def testGetCollection(self):
        musicbrainzngs.get_releases_in_collection("0b15c97c-8eb8-4b4f-81c3-0eb24266a2ac")
        self.assertEqual("http://musicbrainz.org/ws/2/collection/0b15c97c-8eb8-4b4f-81c3-0eb24266a2ac/releases", self.opener.get_url())

        musicbrainzngs.get_works_in_collection("898676a6-bc79-4fe2-98ae-79c5940fe1a2")
        self.assertEqual("http://musicbrainz.org/ws/2/collection/898676a6-bc79-4fe2-98ae-79c5940fe1a2/works", self.opener.get_url())

        musicbrainzngs.get_events_in_collection("65cb5dda-44aa-44a8-9c0d-4f99a14ab944")
        self.assertEqual("http://musicbrainz.org/ws/2/collection/65cb5dda-44aa-44a8-9c0d-4f99a14ab944/events", self.opener.get_url())

        musicbrainzngs.get_places_in_collection("9dde4c3c-520a-4bfd-9aae-446c3a04ce0c")
        self.assertEqual("http://musicbrainz.org/ws/2/collection/9dde4c3c-520a-4bfd-9aae-446c3a04ce0c/places", self.opener.get_url())

        musicbrainzngs.get_recordings_in_collection("42bc6dd9-8deb-4bd7-83eb-5dacdb218b38")
        self.assertEqual("http://musicbrainz.org/ws/2/collection/42bc6dd9-8deb-4bd7-83eb-5dacdb218b38/recordings", self.opener.get_url())

        musicbrainzngs.get_artists_in_collection("7e582256-b3ce-421f-82ba-451b0ab080eb")
        self.assertEqual("http://musicbrainz.org/ws/2/collection/7e582256-b3ce-421f-82ba-451b0ab080eb/artists", self.opener.get_url())
コード例 #7
0
def show_collection(collection_id):
    """Show the list of releases in a given collection.
    """
    result = musicbrainzngs.get_releases_in_collection(collection_id)
    collection = result['collection']
    print('Releases in {}:'.format(collection['name']))
    for release in collection['release-list']:
        print('{title} ({mbid})'.format(
            title=release['title'], mbid=release['id']
        ))
コード例 #8
0
def show_releases(collection):
    result = musicbrainzngs.get_releases_in_collection(collection_id, limit=25)
    release_list = result["collection"]["release-list"]
    print("Releases:")
    releases_fetched = 0
    while len(release_list) > 0:
        print("")
        releases_fetched += len(release_list)
        for release in release_list:
            print("{title} ({mbid})".format(title=release["title"], mbid=release["id"]))
        if user_input("Would you like to display more releases? [y/N] ") != "y":
            break

        # fetch next batch of releases
        result = musicbrainzngs.get_releases_in_collection(collection_id, limit=25, offset=releases_fetched)
        collection = result["collection"]
        release_list = collection["release-list"]

    print("")
    print("Number of fetched releases: %d" % releases_fetched)
コード例 #9
0
def show_collection(collection_id, ctype):
    """Show a given collection.
    """
    if ctype == "release":
        result = musicbrainzngs.get_releases_in_collection(collection_id,
                                                           limit=0)
    elif ctype == "artist":
        result = musicbrainzngs.get_artists_in_collection(collection_id,
                                                          limit=0)
    elif ctype == "event":
        result = musicbrainzngs.get_events_in_collection(collection_id,
                                                         limit=0)
    elif ctype == "place":
        result = musicbrainzngs.get_places_in_collection(collection_id,
                                                         limit=0)
    elif ctype == "recording":
        result = musicbrainzngs.get_recordings_in_collection(collection_id,
                                                             limit=0)
    elif ctype == "work":
        result = musicbrainzngs.get_works_in_collection(collection_id, limit=0)
    collection = result['collection']
    # entity-type only available starting with musicbrainzngs 0.6
    if "entity-type" in collection:
        print('{mbid}\n"{name}" by {editor} ({cat}, {entity})'.format(
            name=collection['name'],
            editor=collection['editor'],
            cat=collection['type'],
            entity=collection['entity-type'],
            mbid=collection['id']))
    else:
        print('{mbid}\n"{name}" by {editor}'.format(
            name=collection['name'],
            editor=collection['editor'],
            mbid=collection['id']))
    print('')
    # release count is only available starting with musicbrainzngs 0.5
    if "release-count" in collection:
        print('{} releases'.format(collection['release-count']))
    if "artist-count" in collection:
        print('{} artists'.format(collection['artist-count']))
    if "event-count" in collection:
        print('{} events'.format(collection['release-count']))
    if "place-count" in collection:
        print('{} places'.format(collection['place-count']))
    if "recording-count" in collection:
        print('{} recordings'.format(collection['recording-count']))
    if "work-count" in collection:
        print('{} works'.format(collection['work-count']))
    print('')

    if "release-list" in collection:
        show_releases(collection)
    else:
        pass  # TODO
コード例 #10
0
    def test_no_collection(self):
        """ If a collection doesn't exist, you get a 404 """

        exc = compat.HTTPError("", 404, "", "", _common.StringIO.StringIO(""))
        self.opener = _common.FakeOpener(exception=musicbrainzngs.ResponseError(cause=exc))
        musicbrainzngs.compat.build_opener = lambda *args: self.opener
        try:
            res = musicbrainzngs.get_releases_in_collection("17905fdb-102d-40f0-91d3-eabcabc64f44")
            self.assertTrue(False, "Expected an exception")
        except musicbrainzngs.ResponseError as e:
            self.assertEqual(e.cause.code, 404)
コード例 #11
0
ファイル: collection2playlist.py プロジェクト: mineo/mpdstuff
def get_releases_in_collection(collectionid):
    releaseids = []
    offset = 0
    found = True

    while found:
        res = m.get_releases_in_collection(collectionid, offset=offset)
        found = len(res["collection"]["release-list"]) > 0
        releaseids += parse_collection(res["collection"])
        offset += 25

    return releaseids
コード例 #12
0
    def test_private_collection(self):
        """ If you ask for a collection that is private, you should
        get a 401"""

        exc = compat.HTTPError("", 401, "", "", _common.StringIO.StringIO(""))
        self.opener = _common.FakeOpener(exception=musicbrainzngs.AuthenticationError(cause=exc))
        musicbrainzngs.compat.build_opener = lambda *args: self.opener
        try:
            res = musicbrainzngs.get_releases_in_collection("17905fdb-102d-40f0-91d3-eabcabc64fd3")
            self.assertTrue(False, "Expected an exception")
        except musicbrainzngs.AuthenticationError as e:
            self.assertEqual(e.cause.code, 401)
コード例 #13
0
def show_collection(collection_id, ctype):
    """Show a given collection.
    """
    if ctype == "release":
        result = musicbrainzngs.get_releases_in_collection(collection_id, limit=0)
    elif ctype == "artist":
        result = musicbrainzngs.get_artists_in_collection(collection_id, limit=0)
    elif ctype == "event":
        result = musicbrainzngs.get_events_in_collection(collection_id, limit=0)
    elif ctype == "place":
        result = musicbrainzngs.get_places_in_collection(collection_id, limit=0)
    elif ctype == "recording":
        result = musicbrainzngs.get_recordings_in_collection(collection_id, limit=0)
    elif ctype == "work":
        result = musicbrainzngs.get_works_in_collection(collection_id, limit=0)
    collection = result["collection"]
    # entity-type only available starting with musicbrainzngs 0.6
    if "entity-type" in collection:
        print(
            '{mbid}\n"{name}" by {editor} ({cat}, {entity})'.format(
                name=collection["name"],
                editor=collection["editor"],
                cat=collection["type"],
                entity=collection["entity-type"],
                mbid=collection["id"],
            )
        )
    else:
        print(
            '{mbid}\n"{name}" by {editor}'.format(
                name=collection["name"], editor=collection["editor"], mbid=collection["id"]
            )
        )
    print("")
    # release count is only available starting with musicbrainzngs 0.5
    if "release-count" in collection:
        print("{} releases".format(collection["release-count"]))
    if "artist-count" in collection:
        print("{} artists".format(collection["artist-count"]))
    if "event-count" in collection:
        print("{} events".format(collection["release-count"]))
    if "place-count" in collection:
        print("{} places".format(collection["place-count"]))
    if "recording-count" in collection:
        print("{} recordings".format(collection["recording-count"]))
    if "work-count" in collection:
        print("{} works".format(collection["work-count"]))
    print("")

    if "release-list" in collection:
        show_releases(collection)
    else:
        pass  # TODO
コード例 #14
0
def show_releases(collection):
    result = musicbrainzngs.get_releases_in_collection(collection_id, limit=25)
    release_list = result['collection']['release-list']
    print('Releases:')
    releases_fetched = 0
    while len(release_list) > 0:
        print("")
        releases_fetched += len(release_list)
        for release in release_list:
            print('{title} ({mbid})'.format(
                title=release['title'], mbid=release['id']
            ))
        if user_input("Would you like to display more releases? [y/N] ") != "y":
            break;

        # fetch next batch of releases
        result = musicbrainzngs.get_releases_in_collection(collection_id,
                            limit=25, offset=releases_fetched)
        collection = result['collection']
        release_list = collection['release-list']

    print("")
    print("Number of fetched releases: %d" % releases_fetched)
コード例 #15
0
    def test_other_collection(self):
        """ If you ask for someone else's collection, you don't
        need to be authenticated."""

        old_mb_request = musicbrainzngs.musicbrainz._mb_request

        params = {}
        def local_mb_request(path, method='GET',
                auth_required=musicbrainzngs.musicbrainz.AUTH_NO,
                client_required=False, args=None, data=None, body=None):
            params["auth_required"] = auth_required

        musicbrainzngs.musicbrainz._mb_request = local_mb_request
        musicbrainzngs.get_releases_in_collection(
                "17905fdb-102d-40f0-91d3-eabcabc64fd3")
        # If _get_auth_type() returns AUTH_IFSET, then _mb_request()
        # should send the user credentials if they are set by auth()
        # i.e., We use whether auth() has been executed to determine if
        # the requested collection belongs to the user or not.
        self.assertEqual(musicbrainzngs.musicbrainz.AUTH_IFSET,
                params["auth_required"])

        musicbrainzngs.musicbrainz._mb_request = old_mb_request
コード例 #16
0
def show_releases(collection):
    result = musicbrainzngs.get_releases_in_collection(collection_id, limit=25)
    release_list = result['collection']['release-list']
    print('Releases:')
    releases_fetched = 0
    while len(release_list) > 0:
        print("")
        releases_fetched += len(release_list)
        for release in release_list:
            print('{title} ({mbid})'.format(title=release['title'],
                                            mbid=release['id']))
        if user_input(
                "Would you like to display more releases? [y/N] ") != "y":
            break

        # fetch next batch of releases
        result = musicbrainzngs.get_releases_in_collection(
            collection_id, limit=25, offset=releases_fetched)
        collection = result['collection']
        release_list = collection['release-list']

    print("")
    print("Number of fetched releases: %d" % releases_fetched)
コード例 #17
0
    def test_other_collection(self):
        """ If you ask for someone else's collection, you don't
        need to be authenticated."""

        old_mb_request = musicbrainzngs.musicbrainz._mb_request

        params = {}

        def local_mb_request(path,
                             method='GET',
                             auth_required=False,
                             client_required=False,
                             args=None,
                             data=None,
                             body=None):
            params["auth_required"] = auth_required

        musicbrainzngs.musicbrainz._mb_request = local_mb_request
        musicbrainzngs.get_releases_in_collection(
            "17905fdb-102d-40f0-91d3-eabcabc64fd3")
        self.assertEqual(False, params["auth_required"])

        musicbrainzngs.musicbrainz._mb_request = old_mb_request
コード例 #18
0
    def testGetCollection(self):
        musicbrainzngs.get_releases_in_collection(
            "0b15c97c-8eb8-4b4f-81c3-0eb24266a2ac")
        self.assertEqual(
            "http://musicbrainz.org/ws/2/collection/0b15c97c-8eb8-4b4f-81c3-0eb24266a2ac/releases",
            self.opener.get_url())

        musicbrainzngs.get_works_in_collection(
            "898676a6-bc79-4fe2-98ae-79c5940fe1a2")
        self.assertEqual(
            "http://musicbrainz.org/ws/2/collection/898676a6-bc79-4fe2-98ae-79c5940fe1a2/works",
            self.opener.get_url())

        musicbrainzngs.get_events_in_collection(
            "65cb5dda-44aa-44a8-9c0d-4f99a14ab944")
        self.assertEqual(
            "http://musicbrainz.org/ws/2/collection/65cb5dda-44aa-44a8-9c0d-4f99a14ab944/events",
            self.opener.get_url())

        musicbrainzngs.get_places_in_collection(
            "9dde4c3c-520a-4bfd-9aae-446c3a04ce0c")
        self.assertEqual(
            "http://musicbrainz.org/ws/2/collection/9dde4c3c-520a-4bfd-9aae-446c3a04ce0c/places",
            self.opener.get_url())

        musicbrainzngs.get_recordings_in_collection(
            "42bc6dd9-8deb-4bd7-83eb-5dacdb218b38")
        self.assertEqual(
            "http://musicbrainz.org/ws/2/collection/42bc6dd9-8deb-4bd7-83eb-5dacdb218b38/recordings",
            self.opener.get_url())

        musicbrainzngs.get_artists_in_collection(
            "7e582256-b3ce-421f-82ba-451b0ab080eb")
        self.assertEqual(
            "http://musicbrainz.org/ws/2/collection/7e582256-b3ce-421f-82ba-451b0ab080eb/artists",
            self.opener.get_url())
コード例 #19
0
def show_collection(collection_id):
    """Show the list of releases in a given collection.
    """
    count = 0
    while True:
        result = musicbrainzngs.get_releases_in_collection(collection_id, limit=25, offset=count)
        collection = result['collection']
        release_list = collection['release-list']
        if len(release_list) == 0:
            break;
        if count == 0:
            print('Releases in {}:'.format(collection['name']))
        count += len(release_list)
        for release in release_list:
            print('{title} ({mbid})'.format(
                title=release['title'], mbid=release['id']
            ))
        if user_input("Would you like to display more releases? [y/N] ") != "y":
            break;
        print("")

    print("number of releases displayed: %d" % count)
コード例 #20
0
def show_collection(collection_id):
    """Show a given collection.
    """
    try:
        result = musicbrainzngs.get_releases_in_collection(
                                                collection_id, limit=0)
        collection = result['collection']
    except musicbrainzngs.ResponseError:
        # TODO
        #result = musicbrainzngs.get_events_in_collection(
        #        collection_id, limit=0)
        sys.exit("This is a collection of events which is not yet implemented")
    # entity-type only available starting with musicbrainzngs 0.6
    if "entity-type" in collection:
        print('{mbid}\n"{name}" by {editor} ({cat}, {entity})'.format(
            name=collection['name'], editor=collection['editor'],
            cat=collection['type'], entity=collection['entity-type'],
            mbid=collection['id']
        ))
    else:
        print('{mbid}\n"{name}" by {editor}'.format(
            name=collection['name'], editor=collection['editor'],
            mbid=collection['id']
        ))
    print('')
    # release count is only available starting with musicbrainzngs 0.5
    if "release-count" in collection:
        print('{} releases'.format(collection['release-count']))
    if "event-count" in collection:
        print('{} events'.format(collection['release-count']))
    print('')

    if "release-list" in collection:
        show_releases(collection)
    if "event-list" in collection:
        pass # TODO
コード例 #21
0
def get_mb_recording(collection_mbid, output_file):
    global symbtrmu2_url, count_matched_mu2, count_missing_mu2, count_missing_dunya
    # Get the collection from musicbrainz and extract the recordings
    print("Retrieving information from mb collection: %s" % collection_mbid)
    res = {"mu2": [], "mb": []}

    rec_list = []
    collection = mb.get_releases_in_collection(collection_mbid)
    for rel in collection["collection"]["release-list"]:
        rel_mb =  mb.get_release_by_id(rel['id'], includes=["recordings"])
        for i in rel_mb["release"]["medium-list"]:
            for track in i["track-list"]:
                rec = track['recording']['id']
                if rec not in rec_list:
                    rec_list.append(rec)

    # Get the recording from musicbrainz and extract makam, form and usul
    for rec_mbid in rec_list:
        work_rels = mb.get_recording_by_id(rec_mbid, includes=["tags", "work-rels"])
        rec_tags = []
        if "tag-list" in work_rels["recording"]:
            rec_tags = work_rels["recording"]["tag-list"]

        works = []
        if "work-relation-list" in work_rels["recording"]:
            works = work_rels["recording"]["work-relation-list"]
        for w in works:
            print("Extracting work information from MB: %s" %  w["work"]["id"])
            
            work_tags = []
            work = mb.get_work_by_id(w["work"]["id"], includes=["tags", "artist-rels"])
            if "tag-list" in work["work"]:
                work_tags = work["work"]["tag-list"] 
            
            mu2 = get_symbtrmu2(work["work"]["id"])
            title = work["work"]["title"].encode("utf-8")

            # get alias for each tag 
            try:
                rec_makam, rec_usul, rec_form = get_tags(rec_tags)
                work_makam, work_usul, work_form = get_tags(work_tags)
                mu2_makam = get_fuzzy("makam", mu2["makam"])
                mu2_form = get_fuzzy("form", mu2["form"])
                mu2_usul = get_fuzzy("usul", mu2["usul"])

                # compare results of 3 sources
                makam, usul, form = (None, None, None)
                if mu2_makam and mu2_usul and mu2_form:
                    #There is mu2 file with makam usul and form
                    count_matched_mu2 += 1

                    if mu2_makam == rec_makam and mu2_usul == rec_usul and mu2_form == rec_form:
                        if work_makam == rec_makam and work_usul == rec_usul and work_form == rec_form:
                            makam = work_makam
                            usul = work_usul
                            form = work_form
                        elif not work_makam and not work_usul and not work_form:
                            # If mb work has no tag we only consider information from mu2 and mb recording
                            makam = rec_makam
                            usul = rec_usul
                            form = rec_form
                    else:
                        print("There's a difference between mu2 file and mb recording information.")
                        print("Recording form: %s usul: %s makam: %s" % (rec_form, rec_usul, rec_makam))
                        print("Mu2 form: %s usul: %s makam: %s" % (mu2_form, mu2_usul, mu2_makam))

                    if makam and usul and form:
                        try:
                            new_link = update_mb_work(work["work"]["id"], title, makam, form, usul, symbtrmu2_url % work["work"]["id"])
                            if new_link:
                                res['mu2'].append(new_link)
                        except ElementNotFoundException as e:
                            print("Couldn't generate link because element not present in MB")

                elif (not work_makam and not work_usul and not work_form) or \
                        (work_makam == rec_makam and work_usul == rec_usul and work_form == rec_form):
                    # If theres no mu2 file we only consider mb information
                    count_missing_mu2 += 1
                    if rec_makam and rec_usul and rec_form:
                        try:
                            new_link = update_mb_work(work["work"]["id"], title, rec_makam, rec_form, rec_usul, None)
                            res['mb'].append(new_link)
                        except ElementNotFoundException as e:
                            print("Couldn't generate link because element not present in MB")

            except AliasNotFoundException as e:
                count_missing_dunya += 1
                print("Skipping work because alias not found on Dunya")

    with open(output_file, "a+") as append_file:
        append_file.write("<h1> List of links generated from MU2 files information </h1>")
        for i in res['mu2']:
            append_file.write(i)
        append_file.write("<h1> List of links generated from recording tags </h1>")
        for i in res['mb']:
            append_file.write(i)

    print("Completed with missing mu2 files: %d, matched mu2 files: %d, missing on dunya: %d" % \
            (count_missing_mu2, count_matched_mu2, count_missing_dunya))
コード例 #22
0
def get_mb_recording(collection_mbid, output_file):
    # Get the collection from musicbrainz and extract the recordings
    print "Retrieving information from mb collection: %s" % collection_mbid
    rec_list = []
    collection = mb.get_releases_in_collection(collection_mbid)
    for rel in collection["collection"]["release-list"]:
        rel_mb =  mb.get_release_by_id(rel['id'], includes=["recordings"])
        for i in rel_mb["release"]["medium-list"]:
            for track in i["track-list"]:
                rec = track['recording']['id']
                if rec not in rec_list:
                    rec_list.append(rec)

    # Get the recording from musicbrainz and extract makam, form and usul
    for rec_mbid in rec_list:
        work_rels = mb.get_recording_by_id(rec_mbid, includes=["tags", "work-rels"])
        rec_tags = []
        if "tag-list" in work_rels["recording"]:
            rec_tags = work_rels["recording"]["tag-list"]
        
        works = []
        if "work-relation-list" in work_rels["recording"]:
            works = work_rels["recording"]["work-relation-list"]
        for w in works:
            print "Extracting work information from MB: %s" %  w["work"]["id"]
            
            work_tags = []
            work = mb.get_work_by_id(w["work"]["id"], includes=["tags", "artist-rels"])
            if "tag-list" in work["work"]:
                work_tags = work["work"]["tag-list"] 
            
            mu2 = get_symbtrmu2(work["work"]["id"])

            # get alias for each tag 
            try:
                rec_makam, rec_usul, rec_form = get_tags(rec_tags)
                work_makam, work_usul, work_form = get_tags(work_tags)
                mu2_makam = get_fuzzy("makam", mu2["makam"])
                mu2_form = get_fuzzy("form", mu2["form"])
                mu2_usul = get_fuzzy("usul", mu2["usul"])
                
                # compare results of 3 sources
                makam, usul, form = (None, None, None)
                if mu2_makam and mu2_usul and mu2_form:
                    #There is mu2 file with makam usul and form

                    if mu2_makam == rec_makam and mu2_usul == rec_usul and mu2_form == rec_form:
                        if work_makam == rec_makam and work_usul == rec_usul and work_form == rec_form:
                            makam = work_makam
                            usul = work_usul
                            form = work_form
                        elif not work_makam and not work_usul and not work_form:
                            # If mb work has no tag we only consider information from mu2 and mb recording
                            makam = rec_makam
                            usul = rec_usul
                            form = rec_form
                    else:
                        print "There's a difference between mu2 file and mb recording information."
                        print "Recording form: %s usul: %s makam: %s" % (rec_form, rec_usul, rec_makam)
                        print "Mu2 form: %s usul: %s makam: %s" % (mu2_form, mu2_usul, mu2_makam)
                elif (not work_makam and not work_usul and not work_form) or \
                        (work_makam == rec_makam and work_usul == rec_usul and work_form == rec_form):
                    # If theres no mu2 file we only consider mb information
                    makam = rec_makam
                    usul = rec_usul
                    form = rec_form
                
                if makam and usul and form:
                    try:
                        update_mb_work(work["work"]["id"], makam, form, usul, output_file)
                    except ElementNotFoundException, e:
                        print "Couldn't generate link because element not present in MB"
            except AliasNotFoundException, e:
                 print "Skipping work because alias not found on Dunya"
コード例 #23
0
 def testGetCollection(self):
     musicbrainzngs.get_releases_in_collection("0b15c97c-8eb8-4b4f-81c3-0eb24266a2ac")
     self.assertEqual("http://musicbrainz.org/ws/2/collection/0b15c97c-8eb8-4b4f-81c3-0eb24266a2ac/releases", self.opener.get_url())