示例#1
0
def tag_item(item, timid=False, search_artist=None, search_title=None,
             search_id=None):
    """Attempts to find metadata for a single track. Returns a
    `(candidates, recommendation)` pair where `candidates` is a list
    of `(distance, track_info)` pairs. `search_artist` and 
    `search_title` may be used to override the current metadata for
    the purposes of the MusicBrainz title; likewise `search_id`.
    """
    candidates = []

    # First, try matching by MusicBrainz ID.
    trackid = search_id or item.mb_trackid
    if trackid:
        log.debug('Searching for track ID: ' + trackid)
        track_info = mb.track_for_id(trackid)
        if track_info:
            dist = track_distance(item, track_info, incl_artist=True)
            candidates.append((dist, track_info))
            # If this is a good match, then don't keep searching.
            rec = recommendation(candidates)
            if rec == RECOMMEND_STRONG and not timid:
                log.debug('Track ID match.')
                return candidates, rec

    # If we're searching by ID, don't proceed.
    if search_id is not None:
        if candidates:
            return candidates, rec
        else:
            return [], RECOMMEND_NONE
    
    # Search terms.
    if not (search_artist and search_title):
        search_artist, search_title = item.artist, item.title
    log.debug(u'Item search terms: %s - %s' % (search_artist, search_title))

    # Candidate metadata from search.
    for track_info in mb.match_track(search_artist, search_title):
        dist = track_distance(item, track_info, incl_artist=True)
        candidates.append((dist, track_info))

    # Add candidates from plugins.
    for track_info in plugins.item_candidates(item):
        dist = track_distance(item, track_info, incl_artist=True)
        candidates.append((dist, track_info))

    # Sort by distance and return with recommendation.
    log.debug('Found %i candidates.' % len(candidates))
    candidates.sort()
    rec = recommendation(candidates)
    return candidates, rec
示例#2
0
def _item_candidates(item, artist, title):
    """Search for item matches. ``item`` is the Item to be matched.
    ``artist`` and ``title`` are strings and either reflect the item or
    are specified by the user.
    """
    out = []

    # MusicBrainz candidates.
    out.extend(mb.match_track(artist, title))

    # Plugin candidates.
    out.extend(plugins.item_candidates(item))

    return out
示例#3
0
def _item_candidates(item, artist, title):
    """Search for item matches. ``item`` is the Item to be matched.
    ``artist`` and ``title`` are strings and either reflect the item or
    are specified by the user.
    """
    out = []

    # MusicBrainz candidates.
    out.extend(mb.match_track(artist, title))

    # Plugin candidates.
    out.extend(plugins.item_candidates(item))

    return out