def find_album_in_database(title, metadata_database): """ Looks for an album by title in the given metadata database. If no matching albums were found, asks the user for help. The user may choose to skip. Returns: (user-selection-type, album-metadata). """ print("* * * * * Searching Album * * * * *") print("For:", cui.get_printable_string(title)) possible_matches = metadata_database.find_album(title) # find_album only returns good matches, simply take the first. first_match = next(possible_matches, None) if first_match is None: print("Couldn't find metadata for album. Skipping..") user_selection_type = user_selection_types.NO_ITEMS_TO_SELECT_FROM album = None else: user_selection_type = user_selection_types.ITEM_SELECTED album, probability = first_match print(cui.get_printable_string( 'Match [{:.2%}]: {} - {}'.format( probability, album.artist, album.title ) )) print() print() return (user_selection_type, album)
def find_torrent_for_album(album, tracker, allow_fancy_releases=False, allow_remasters=False, **kwargs): """ Finds a torrent of the given album in the given tracker. Returns a tuple: (user-selection-type, torrent-details). """ print("* * * * * Searching Torrent * * * * *") print( "For:", cui.get_printable_string(" - ".join([album.artist, album.title])) ) # Try to search: "artist title". # If no results, search: "artist" "title". torrent = tracker.find_best_torrent_by_keywords( [" ".join([album.artist, album.title])], allow_fancy_releases=allow_fancy_releases, allow_remasters=allow_remasters ) if torrent is None: torrent = tracker.find_best_torrent_by_keywords( [album.artist, album.title], allow_fancy_releases=allow_fancy_releases, allow_remasters=allow_remasters ) if torrent is None: print("No matching torrents. Looking for discography..") torrent = tracker.find_best_discography_torrent( album.artist, allow_fancy_releases=allow_fancy_releases, allow_remasters=allow_remasters ) if torrent is None: print("No matching torrents were found.") user_selection_type = user_selection_types.NO_ITEMS_TO_SELECT_FROM else: print(cui.get_printable_string( "Match: {} [{}s/{}l, {}]".format( torrent.title, torrent.seeders, torrent.leechers, build_data_size_string(torrent.size_in_bytes) ) )) user_selection_type = user_selection_types.ITEM_SELECTED print() return (user_selection_type, torrent)