Ejemplo n.º 1
0
def get_musicbrainz_release(disc):
    """ Given a Disc object, try a bunch of methods to look up the release in
	musicbrainz.  If a releaseid is specified, use this, otherwise search by
	discid, then search by CD-TEXT and finally search by audio-fingerprinting.
	"""
    if disc.discid is None and disc.releaseid is None:
        raise Exception("Specify at least one of discid or releaseid")

        # If a release id has been specified, that takes precedence
    if disc.releaseid is not None:
        return lookups.get_release_by_releaseid(disc.releaseid)

        # Otherwise, lookup the releaseid using the discid as a key
    results = lookups.get_releases_by_discid(disc.discid)
    if len(results) > 1:
        for result in results:
            print result.release.id + ".html"
        print "Ambiguous DiscID, trying fingerprint matching"
        return get_release_by_fingerprints(disc)

        # We have an exact match, use this.
    if len(results) == 1:
        releaseid = results[0].release.id
        return lookups.get_release_by_releaseid(results[0].release.id)

        # Otherwise, use CD-TEXT if present to guess the release
    if disc.performer is not None and disc.title is not None:
        print "Trying to look up release via CD-TEXT"
        print "Performer: " + disc.performer
        print "Title    : " + disc.title
        results = lookups.get_releases_by_cdtext(
            performer=disc.performer, title=disc.title, num_tracks=len(disc.tracks)
        )
        if len(results) == 1:
            print "Got result via CD-TEXT lookup!"
            print "Suggest submitting TOC and discID to musicbrainz:"
            print "Release URL: " + results[0].release.id + ".html"
            print "Submit URL : " + submit.musicbrainz_submission_url(disc)
            return lookups.get_release_by_releaseid(results[0].release.id)
        elif len(results) > 1:
            for result in results:
                print result.release.id + ".html"
            print "Ambiguous CD-TEXT"
        else:
            print "No results from CD-TEXT lookup."

            # Last resort, fingerprinting
    print "Trying fingerprint search"
    return get_release_by_fingerprints(disc)
Ejemplo n.º 2
0
def get_release_by_fingerprints(disc):
    """ Do a fingerprint based search for a matching release.

        """
    dirinfo = albumidentify.get_dir_info(disc.dirname)
    data = albumidentify.guess_album(dirinfo)
    try:
        (directoryname, albumname, rid, events, asin, trackdata, albumartist, releaseid) = data.next()
    except StopIteration, si:
        raise Exception("Can't find release via fingerprint search. Giving up")

    release = lookups.get_release_by_releaseid(releaseid)
    print "Got result via audio fingerprinting!"
    print "Suggest submitting TOC and discID to musicbrainz:"
    print "Release URL: " + release.id + ".html"
    print "Submit URL : " + submit.musicbrainz_submission_url(disc)
    return release


def get_musicbrainz_release(disc):
    """ Given a Disc object, try a bunch of methods to look up the release in
	musicbrainz.  If a releaseid is specified, use this, otherwise search by
	discid, then search by CD-TEXT and finally search by audio-fingerprinting.
	"""
    if disc.discid is None and disc.releaseid is None:
        raise Exception("Specify at least one of discid or releaseid")

        # If a release id has been specified, that takes precedence
    if disc.releaseid is not None:
        return lookups.get_release_by_releaseid(disc.releaseid)