annotate core/magnatagatune/fm_corresponding_artists.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [fmartist_name, fmartist_name_names] = fm_corresponding_artists(artists)
wolffd@0 2 %[artists, fmartists] = fm_corresponding_artists(artists)
wolffd@0 3 %
wolffd@0 4 % searches last.fm for the artist given in a cell
wolffd@0 5 % array of strings and saves the first hit into the output.
wolffd@0 6 %
wolffd@0 7 % returns -1 of no matches found
wolffd@0 8 maxtry = 10;
wolffd@0 9
wolffd@0 10 % artists = unique(artists);
wolffd@0 11 i = 1;
wolffd@0 12 numtry = 0;
wolffd@0 13 while i <= numel(artists)
wolffd@0 14
wolffd@0 15 % ---
wolffd@0 16 % as sometimes this fails due to connection problems
wolffd@0 17 % or other problems not yet identified, we TRY
wolffd@0 18 %
wolffd@0 19 % for fails, we may try one time again!
wolffd@0 20 % ---
wolffd@0 21 fprintf('%d percent: %s\n',floor(i*100/numel(artists)),char(artists{i}));
wolffd@0 22 try
wolffd@0 23 [tmp, tmpid] = fm_retrieve_album(char(artists{i}));
wolffd@0 24 fmartist_name(i,:) = {artists{i}, tmp{1}, tmpid{1}};
wolffd@0 25 catch err
wolffd@0 26
wolffd@0 27 % no work :(
wolffd@0 28 warning(err.message);
wolffd@0 29 fmartist_name(i,:) = {artists{i}, '-1', '-1'};
wolffd@0 30
wolffd@0 31 numtry = numtry + 1;
wolffd@0 32
wolffd@0 33 % ---
wolffd@0 34 % NOTE: we try gain in case it fails for < maxtry times
wolffd@0 35 % ---
wolffd@0 36 if numtry < maxtry
wolffd@0 37 i = i - 1;
wolffd@0 38 else
wolffd@0 39 numtry = 0;
wolffd@0 40 end
wolffd@0 41 end
wolffd@0 42 i = i + 1;
wolffd@0 43 end
wolffd@0 44
wolffd@0 45 fmartist_name_names = {'magnatagatune_album', 'fm_album', 'mbid'};