pl_tracks = [] for a in artists: try: url = '/artist/' + a.strip().title().replace(' ', '_').replace('&', '') + '/' artist_key = r.getObjectFromUrl(url=url)['key'] tracks = r.getTracksForArtist(artist=artist_key, count=args.track_count) # make sure key is for a track and for the right artist track_keys = [t['key'] for t in tracks \ if t['artistUrl'].lower() == url.lower() \ and t['key'].startswith('t')] for t in track_keys: pl_tracks.append(t) except: print 'artist DNE: %s' % a continue # create the playlist try: r.call("createPlaylist", name=args.pl_name, description=args.pl_desc, \ tracks=','.join(pl_tracks)) except: print 'error creating playlist' class InputError(Exception): def __init__(self, message): self.message = message def __str__(self): return repr(self.message)
from rdioapi import Rdio state = {} r = Rdio(RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET, state) import webbrowser webbrowser.open(r.begin_authentication('oob')) verifier = raw_input('Enter the PIN from the Rdio site: ').strip() r.complete_authentication(verifier) from pprint import pprint i = 0 batch = 2500 while True: print "fetching collection tracks %d -> %d" % (i, i+batch) tracks = r.call('getTracksInCollection', count=i+batch, start=i) trackIds = [] for t in tracks: if 'isAvailableOffline' in t and t['isAvailableOffline']: trackIds.append(t['key']) print "\tfound %d synced tracks tracks" % (len(trackIds)) if len(trackIds): keys = ','.join(trackIds) r.call('setAvailableOffline', offline=False, keys=keys) i += batch if len(tracks) < batch: print "that was it" break