wolffd@0: function [fmartist_name, fmartist_name_names] = fm_corresponding_artists(artists) wolffd@0: %[artists, fmartists] = fm_corresponding_artists(artists) 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: % returns -1 of no matches found wolffd@0: maxtry = 10; wolffd@0: wolffd@0: % artists = unique(artists); wolffd@0: i = 1; wolffd@0: numtry = 0; wolffd@0: while i <= numel(artists) 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(artists)),char(artists{i})); wolffd@0: try wolffd@0: [tmp, tmpid] = fm_retrieve_album(char(artists{i})); wolffd@0: fmartist_name(i,:) = {artists{i}, tmp{1}, tmpid{1}}; wolffd@0: catch err wolffd@0: wolffd@0: % no work :( wolffd@0: warning(err.message); wolffd@0: fmartist_name(i,:) = {artists{i}, '-1', '-1'}; wolffd@0: wolffd@0: numtry = numtry + 1; wolffd@0: wolffd@0: % --- wolffd@0: % NOTE: we try gain 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: fmartist_name_names = {'magnatagatune_album', 'fm_album', 'mbid'};