示例#1
0
 def aliases_for_work(self, workid):
     w = mb.get_work_by_id(workid, includes=["aliases"])
     w = w["work"]
     ret = []
     for alias in w.get("alias-list", []):
         ret.append(alias["alias"])
     return list(set(ret))
示例#2
0
 def aliases_for_work(self, workid):
     w = mb.get_work_by_id(workid, includes=["aliases"])
     w = w["work"]
     ret = []
     for alias in w.get("alias-list", []):
         ret.append(alias["alias"])
     return list(set(ret))
示例#3
0
def main():
    m.set_useragent("application", "0.01", "http://example.com")
    print(m.get_artist_by_id("952a4205-023d-4235-897c-6fdb6f58dfaa", []))
    print(m.get_label_by_id("aab2e720-bdd2-4565-afc2-460743585f16"))
    print(m.get_release_by_id("e94757ff-2655-4690-b369-4012beba6114"))
    print(m.get_release_group_by_id("9377d65d-ffd5-35d6-b64d-43f86ef9188d"))
    print(m.get_recording_by_id("cb4d4d70-930c-4d1a-a157-776de18be66a"))
    print(m.get_work_by_id("7e48685c-72dd-3a8b-9274-4777efb2aa75"))

    print(m.get_releases_by_discid("BG.iuI50.qn1DOBAWIk8fUYoeHM-"))
    print(m.get_recordings_by_puid("070359fc-8219-e62b-7bfd-5a01e742b490"))
    print(m.get_recordings_by_isrc("GBAYE9300106"))

    m.auth("", "")
    m.submit_barcodes(
        {"e94757ff-2655-4690-b369-4012beba6114": "9421021463277"})
    m.submit_tags(recording_tags={
        "cb4d4d70-930c-4d1a-a157-776de18be66a": ["these", "are", "my", "tags"]
    })
    m.submit_tags(
        artist_tags={"952a4205-023d-4235-897c-6fdb6f58dfaa": ["NZ", "twee"]})

    m.submit_ratings(
        recording_ratings={"cb4d4d70-930c-4d1a-a157-776de18be66a": 20})
    m.submit_echoprints(
        {"e97f805a-ab48-4c52-855e-07049142113d": "anechoprint1234567"})
示例#4
0
def get_work_type(id):
    l = musicbrainzngs.get_work_by_id(id)
    try:
        t = l['work']['type'].lower()
    except KeyError:
        t = 'song'
    return t
示例#5
0
    def stats_for_recording(self, recordingid):
        """ Given a recording id, get its work (if it exists) and
            the composer and lyricist of the work """
        self.recordings.add(recordingid)
        recording = mb.get_recording_by_id(recordingid, includes=["work-rels", "artist-rels"])
        recording = recording["recording"]
        for relation in recording.get("artist-relation-list", []):
            artist = relation.get("artist", {}).get("id")
            if artist:
                self.artists.add(artist)

        for relation in recording.get("work-relation-list", []):
            workid = relation.get("work", {}).get("id")
            self.works.add(workid)
            self.work_recording_counts[workid] += 1
            work = mb.get_work_by_id(workid, includes=["artist-rels"])
            work = work["work"]
            for artist in work.get("artist-relation-list", []):
                t = artist["type"]
                aid = artist.get("artist", {}).get("id")
                if aid:
                    if t == "composer":
                        self.composers.add(aid)
                    elif t == "lyricist":
                        self.lyricists.add(aid)
示例#6
0
文件: stats.py 项目: EQ4/pycompmusic
    def stats_for_recording(self, recordingid):
        """ Given a recording id, get its work (if it exists) and
            the composer and lyricist of the work """
        self.recordings.add(recordingid)
        recording = mb.get_recording_by_id(recordingid, includes=["work-rels", "artist-rels"]) 
        recording = recording["recording"]
        for relation in recording.get("artist-relation-list", []):
            artist = relation.get("artist", {}).get("id")
            if artist:
                self.artists.add(artist)

        for relation in recording.get("work-relation-list", []):
            workid = relation.get("work", {}).get("id")
            self.works.add(workid)
            self.work_recording_counts[workid] += 1
            work = mb.get_work_by_id(workid, includes=["artist-rels"])
            work = work["work"]
            for artist in work.get("artist-relation-list", []):
                t = artist["type"]
                aid = artist.get("artist", {}).get("id")
                if aid:
                    if t == "composer":
                        self.composers.add(aid)
                    elif t == "lyricist":
                        self.lyricists.add(aid)
示例#7
0
 def recordingids_for_work(self, workid):
     work = mb.get_work_by_id(workid, includes=["recording-rels"])
     work = work["work"]
     ret = []
     for rel in work.get("recording-relation-list", []):
         recid = rel["target"]
         ret.append(recid)
     return ret
示例#8
0
 def recordingids_for_work(self, workid):
     work = mb.get_work_by_id(workid, includes=["recording-rels"])
     work = work["work"]
     ret = []
     for rel in work.get("recording-relation-list", []):
         recid = rel["target"]
         ret.append(recid)
     return ret
示例#9
0
def find_parentwork_info(mb_workid):
    """Get the MusicBrainz information dict about a parent work, including
    the artist relations, and the composition date for a work's parent work.
    """
    parent_id, work_date = work_parent_id(mb_workid)
    work_info = musicbrainzngs.get_work_by_id(parent_id,
                                              includes=["artist-rels"])
    return work_info, work_date
def getComposers(workRelatios):
    for workRel in workRelatios:
        if (workRel['type'] == 'performance'):
            workId = workRel['work']['id']
            workAttrs = mb.get_work_by_id(id=workId, includes=['artist-rels'])
            if ('artist-relation-list' in workAttrs['work'].keys()):
                return extractComposersOtherwiseWriters(
                    workAttrs['work']['artist-relation-list'])
    return []
示例#11
0
def get_composers(work_relatios):
    for workRel in work_relatios:
        if workRel['type'] == 'performance':
            work_id = workRel['work']['id']
            work_attrs = mb.get_work_by_id(id=work_id,
                                           includes=['artist-rels'])
            if 'artist-relation-list' in work_attrs['work'].keys():
                return extract_composers_otherwise_writers(
                    work_attrs['work']['artist-relation-list'])
    return []
示例#12
0
def direct_parent_id(mb_workid, work_date=None):
    """Given a Musicbrainz work id, find the id one of the works the work is
    part of and the first composition date it encounters.
    """
    work_info = musicbrainzngs.get_work_by_id(
        mb_workid, includes=["work-rels", "artist-rels"])
    if 'artist-relation-list' in work_info['work'] and work_date is None:
        for artist in work_info['work']['artist-relation-list']:
            if artist['type'] == 'composer':
                if 'end' in artist.keys():
                    work_date = artist['end']

    if 'work-relation-list' in work_info['work']:
        for direct_parent in work_info['work']['work-relation-list']:
            if direct_parent['type'] == 'parts' \
                    and direct_parent.get('direction') == 'backward':
                direct_id = direct_parent['work']['id']
                return direct_id, work_date
    return None, work_date
示例#13
0
    def _get_oldest_date(self, recording_id, item_date):
        recording = self._get_recording(recording_id)
        is_cover = _is_cover(recording)
        work_id = _get_work_id_from_recording(recording)
        artist_ids = _get_artist_ids_from_recording(recording)

        # If no work id, check this recording against embedded date
        starting_date = item_date if item_date is not None and (
                self.config['use_file_date'] or not work_id) else datetime.date.today()

        if not work_id:  # Only look through this recording
            return self._iterate_dates([recording], starting_date, is_cover, artist_ids)

        # Fetch work, including associated recordings
        work = musicbrainzngs.get_work_by_id(work_id, ['recording-rels'])['work']

        if 'recording-relation-list' not in work:
            self._log.error(
                'Work {0} has no valid associated recordings! Please choose another recording or amend the data!',
                work_id)
            return None

        return self._iterate_dates(work['recording-relation-list'], starting_date, is_cover, artist_ids)
示例#14
0
    def from_musicbrainz(self, mbid):
        included_rels = (['artist-rels', 'recording-rels']
                         if self.get_recording_rels else ['artist-rels'])
        work = mb.get_work_by_id(mbid, includes=included_rels)['work']

        data = {
            'makam': [],
            'form': [],
            'usul': [],
            'title': work['title'],
            'mbid': mbid,
            'composer': dict(),
            'lyricist': dict(),
            'url': 'http://musicbrainz.org/work/' + mbid,
            'language': ''
        }

        # assign makam, form, usul attributes to data
        self._assign_makam_form_usul(data, mbid, work)

        # language
        self._assign_language(data, work)

        # composer and lyricist
        self._assign_composer_lyricist(data, work)

        # add recordings
        self._assign_recordings(data, work)

        # add scores
        self._add_scores(data, mbid)

        # warnings
        self._chk_warnings(data)

        return data
示例#15
0
    def from_musicbrainz(cls,
                         mbid,
                         get_recording_rels=True,
                         print_warnings=None):
        included_rels = (['artist-rels', 'recording-rels']
                         if get_recording_rels else ['artist-rels'])
        work = mb.get_work_by_id(mbid, includes=included_rels)['work']

        metadata = {
            'makam': [],
            'form': [],
            'usul': [],
            'title': work['title'],
            'mbid': mbid,
            'composer': dict(),
            'lyricist': dict(),
            'url': 'http://musicbrainz.org/work/' + mbid,
            'language': ''
        }

        # assign makam, form, usul attributes to data
        cls._assign_makam_form_usul(metadata, mbid, work)

        # language
        cls._assign_language(metadata, work)

        # composer and lyricist
        cls._assign_composer_lyricist(metadata, work)

        # add recordings
        cls._assign_recordings(metadata, work)

        # warnings
        cls._check_warnings(metadata, print_warnings)

        return metadata
示例#16
0
def get_work_title(id):
    l = musicbrainzngs.get_work_by_id(id)
    return l['work']['title']
示例#17
0
        return data[object_type][id]

    print(type_id)


    time.sleep(1)

    try:
        if object_type == 'release-group':
            result = musicbrainzngs.get_release_group_by_id(id, includes=['releases','release-rels'])
        elif object_type == 'release':
            result =  musicbrainzngs.get_release_by_id(id, includes=['discids','recordings','artists','instrument-rels'])
        elif object_type == 'recording':
             result =  musicbrainzngs.get_recording_by_id(id, includes=['artists','instrument-rels','work-rels','artist-rels','releases'])
        elif object_type == 'work':
             result =  musicbrainzngs.get_work_by_id(id, includes=['artist-rels','work-rels'])


    except  musicbrainzngs.ResponseError as err:
        if err.cause.code == 404:
            sys.exit("Not found")
            return None
        else:
            sys.exit("received bad response {} from the MB server".format(err.cause.code))
            return None

    mb_cache[object_type][id] = copy.deepcopy(result)
    data[object_type][id] = copy.deepcopy(result)
    return result

def catalogue_recordings():
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"
 def testGetWork(self):
     musicbrainzngs.get_work_by_id("c6dfad5a-f915-41c7-a1c0-e2b606948e69")
     self.assertEqual(
         "http://musicbrainz.org/ws/2/work/c6dfad5a-f915-41c7-a1c0-e2b606948e69",
         self.opener.get_url())
示例#20
0
def get_work_attributes(workid):
    work = mb.get_work_by_id(workid)["work"]
    return work.get("attribute-list", [])
 def testGetWork(self):
     musicbrainzngs.get_work_by_id("c6dfad5a-f915-41c7-a1c0-e2b606948e69")
     self.assertEqual("http://musicbrainz.org/ws/2/work/c6dfad5a-f915-41c7-a1c0-e2b606948e69", self.opener.get_url())
示例#22
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))