if downloaded_counter > 0 and (downloaded_counter % SONGS_DOWNLOADED_IN_A_ROW_LIMIT) == 0: wait_time_minutes = WAITING_TIME_MINS print "\t\tLets wait %d minutes before downloading the next song to avoid getting blocked." % wait_time_minutes time.sleep(wait_time_minutes*60) #- Download the song -# grooveshark_song = search_result[0] grooveshark_songs_list.append(grooveshark_song) found.append((grooveshark_song['SongID'], grooveshark_song['SongName'], grooveshark_song['ArtistName'], grooveshark_song['AlbumName'])) print "\tGrooveshark: %s, %s, %s, %d." % (grooveshark_song['SongName'], grooveshark_song['AlbumName'], grooveshark_song['ArtistName'], int(grooveshark_song['SongID'])) album_name = grooveshark_song['AlbumName'] if grooveshark_song['AlbumName'] != '' else 'no-album' directory = "%s/%s/%s/%s" % (DOWNLOADS_DIR, spotify_file, gs.clean_file_path(grooveshark_song['ArtistName']), gs.clean_file_path(album_name)) print "\tTrying download." #- Retry loop -# max_retries = 5 for attempt in xrange(max_retries): download_result = gs.download_song(grooveshark_song, directory) if download_result == gs.SONG_ALREADY_DOWNLOADED: already_downloaded_counter += 1 print "\t\tAlready downloaded. %d" % already_downloaded_counter elif download_result == gs.STREAM_RETRIEVAL_BLOCKED: waiting_minutes = WAITING_TIME_MINS * (attempt+1)# minutes. print "\t\tGrooveshark is temporaly blocking you, lets wait %d minutes and retry." % waiting_minutes time.sleep(waiting_minutes*60) #- Searching again, some times old results don't work -# search_result = gs.search_song(spotify_song.get('song'), spotify_song.get('album'), spotify_song.get('artist')) grooveshark_song = search_result[0] #- Retrying -# continue else: #- Download ok -# downloaded_counter += 1
for song_offset, song in enumerate(playlist['Songs']): song_number = song_offset + 1 #- Wait some time after a certain amount of downloaded songs to avoid being banned -*/ if downloaded_counter > 0 and (downloaded_counter % SONGS_DOWNLOADED_IN_A_ROW_LIMIT) == 0: wait_time_mins = WAITING_TIME_MINS print "\t\tLets wait %d minutes before downloading the next song to avoid getting blocked." % wait_time_mins time.sleep(wait_time_mins*60) album_name = song['AlbumName'] if song['AlbumName'] != '' else 'no-album' print " %d: %s - %s - %s" % (song_number, song['Name'], song['AlbumName'], song['ArtistName']) dir = "%s/%s/%s/%s" % (DOWNLOADS_DIR, playlist_name, song['ArtistName'].replace('/', ' - '), album_name) make_sure_dir_exists(dir) #- Retry loop -# max_retries = 5 for attempt in xrange(max_retries): print "\tDownload attempt: %d." % (attempt+1) download_result = gs.download_song(song, dir) if download_result == gs.SONG_ALREADY_DOWNLOADED: already_downloaded_counter += 1 print "\t\tAlready downloaded. %d" % already_downloaded_counter elif download_result == gs.STREAM_RETRIEVAL_BLOCKED: waiting_minutes = WAITING_TIME_MINS * (attempt+1) # minutes print "\t\tGrooveshark is temporaly blocking you, lets wait %d minutes and retry." % waiting_minutes time.sleep(waiting_minutes*60) #- Retrying -# continue else: #- Download ok -# downloaded_counter += 1 print "\t\tDownloaded. %d" % downloaded_counter #- Exiting the loop -# break