コード例 #1
0
    #- Nothing found -#
    if len(result) == 0:
        not_found.append(spotify_song)
        print "\tNo result in Grooveshark."
        continue
    grooveshark_song = result[0]
    print "\tGrooveshark: %s, %s, %s." % (grooveshark_song['SongName'], grooveshark_song['AlbumName'], grooveshark_song['ArtistName'])
    found.append((int(grooveshark_song['SongID']), grooveshark_song['SongName'], grooveshark_song['ArtistName'], grooveshark_song['AlbumName']))
    for attempt in xrange(3):
        if gs.add_song_to_queue(grooveshark_song, gs.get_queue_id()):
            break

print "Found: %d" % len(found)

if len(found) == 0:
    exit()

playlist_name = spotify_file.split('/')[-1]
song_ids = map(lambda item: item[0], set(found))
not_found_report = []
if len(not_found) > 0:
    not_found_report.append("%d song/s weren't found on Grooveshark:" % len(not_found))
    for offset, song in enumerate(not_found):
        not_found_report.append("\t%d - %s, %s, %s" % (offset+1, song.get('song'), song.get('album'), song.get('artist')))
    print "\n".join(not_found_report)
playlist_id = gs.create_playlist(playlist_name, song_ids)
playlist_songs = gs.get_playlist_songs(playlist_id)
print "Playlist created with: %d song/s" % len(playlist_songs)
if len(song_ids) < len(found):
    print "There were %d song/s repeated" % (len(found) - len(song_ids))
print "Playlist url: http://grooveshark.com/playlist/%s/%d" % (playlist_name, playlist_id)