示例#1
0
文件: jobs.py 项目: miracatici/dunya
def update_collection(collectionid):
    """ Sync the contents of a collection on musicbrainz.org to our local
        database.

        If new releases have been added, put them in our local database.
        If releases have been removed, remove referenes to them in our
        database.
    """
    found_releases = compmusic.get_releases_in_collection(collectionid)
    coll = models.Collection.objects.get(pk=collectionid)
    existing_releases = [r.mbid for r in coll.musicbrainzrelease_set.all()]
    to_remove = set(existing_releases) - set(found_releases)
    to_add = set(found_releases) - set(existing_releases)

    for relid in to_add:
        try:
            mbrelease = compmusic.mb.get_release_by_id(relid, includes=["artists"])["release"]
            title = mbrelease["title"]
            artist = mbrelease["artist-credit-phrase"]
            rel, created = models.MusicbrainzRelease.objects.get_or_create(
                mbid=relid,
                collection=coll,
                defaults={"title": title, "artist": artist})
        except compmusic.mb.ResponseError:
            coll.add_log_message("The collection had an entry for %s but I can't find a release with that ID" % relid)

    for relid in to_remove:
        coll.musicbrainzrelease_set.filter(mbid=relid).delete()
示例#2
0
文件: jobs.py 项目: darad/dunya
def update_collection(collectionid):
    """ Sync the contents of a collection on musicbrainz.org to our local
        database.

        If new releases have been added, put them in our local database.
        If releases have been removed, remove referenes to them in our
        database.
    """
    found_releases = compmusic.get_releases_in_collection(collectionid)
    coll = models.Collection.objects.get(pk=collectionid)
    existing_releases = [r.mbid for r in coll.musicbrainzrelease_set.all()]
    to_remove = set(existing_releases) - set(found_releases)
    to_add = set(found_releases) - set(existing_releases)

    for relid in to_add:
        try:
            mbrelease = compmusic.mb.get_release_by_id(relid, includes=["artists"])["release"]
            title = mbrelease["title"]
            artist = mbrelease["artist-credit-phrase"]
            rel, created = models.MusicbrainzRelease.objects.get_or_create(
                    mbid=relid,
                    collection=coll,
                    defaults={"title": title, "artist": artist})
        except compmusic.mb.ResponseError:
            coll.add_log_message("The collection had an entry for %s but I can't find a release with that ID" % relid)

    for relid in to_remove:
        coll.musicbrainzrelease_set.filter(mbid=relid).delete()
示例#3
0
        except carnatic.models.Raaga.DoesNotExist:
            raaga = None
    return raaga


recordingtags = {}
In[39]: for r in recordings:
    rid = r["id"]
    if rid not in recordingtags:
        rg, ta = rt_for_recording(r)
        recordingtags[rid] = {"raaga": rg.name.encode("utf-8") if rg else None,
                              "taala": ta.name.encode("utf-8") if ta else None}

json.dump(recordingtags, open("carnatic-recording-to-tag.json", "w"))

releases = compmusic.get_releases_in_collection(compmusic.CARNATIC_COLLECTION)

In[19]: for w in wattr:
    raaga = None
    taala = None
    for a in w["attribute-list"]:
        if a["type"] == u'T\u0101la (Carnatic)':
            taala = a["attribute"]
        elif a["type"] == u'R\u0101ga (Carnatic)':
            raaga = a["attribute"]
    wid = w["id"]
    if wid not in workmap:
        workmap[wid] = {"raaga": raaga, "taala": taala}

In[19]: for rel in releases:
    recs = compmusic.get_recordings_from_release(rel)