wolffd@0: function [fmalbums, fmalbum_names] = fm_corresponding_albums(albums) wolffd@0: %fmalbums = fm_corresponding_albums(albums) wolffd@0: % wolffd@0: % searches last.fm for the artist given in a cell wolffd@0: % array of strings and saves the first hit into the output. wolffd@0: % wolffd@0: % fmalbum_names = {magnatagatune_artist, fm_artist}; wolffd@0: % wolffd@0: % returns -1 of no matches found wolffd@0: maxtry = 3; wolffd@0: wolffd@0: albums = unique(albums); wolffd@0: i = 1; wolffd@0: numtry = 0; wolffd@0: while i < numel(albums) wolffd@0: wolffd@0: % --- wolffd@0: % as sometimes this fails due to connection problems wolffd@0: % or other problems not yet identified, we TRY wolffd@0: % wolffd@0: % for fails, we may try one time again! wolffd@0: % --- wolffd@0: fprintf('%d percent: %s\n',floor(i*100/numel(albums)),char(albums{i})); wolffd@0: try wolffd@0: [tmp, tmpid] = fm_retrieve_album(char(albums{i})); wolffd@0: fmalbums(i,:) = {albums{i}, tmp{1}, tmpid{1}}; wolffd@0: catch err wolffd@0: wolffd@0: % no work :( wolffd@0: warning(err.message); wolffd@0: fmalbums{i} = '-1'; wolffd@0: wolffd@0: numtry = numtry + 1; wolffd@0: wolffd@0: % --- wolffd@0: % NOTE: we try again in case it fails for < maxtry times wolffd@0: % --- wolffd@0: if numtry < maxtry wolffd@0: i = i - 1; wolffd@0: else wolffd@0: numtry = 0; wolffd@0: end wolffd@0: end wolffd@0: i = i + 1; wolffd@0: end wolffd@0: wolffd@0: fmalbum_names = {'magnatagatune_album', 'fm_album', 'mbid'};