Created
October 2, 2011 17:23
-
-
Save spudtrooper/1257664 to your computer and use it in GitHub Desktop.
Creates a playlist for every artist in your library -- since the Roku app doesn't have browsing by artists.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Creates a playlist for every artist in your library -- since the | |
# Roku app doesn't have browsing by artists. The following need to be | |
# in the ENV: | |
# | |
# export RDIO_KEY=... | |
# export RDIO_SECRET=... | |
# | |
# You can pass in the email or username as the first argument. If not | |
# provided we use the current user. | |
# | |
# You have to install the rdio gem, too. | |
# | |
require 'rubygems' | |
require 'rdio' | |
def main(argv) | |
# Use the first argument as the email or vanity name if available, | |
# otherwise use the current user | |
if argv.empty? | |
user = Rdio::User.current | |
else | |
user = Rdio::User.find argv.shift | |
end | |
# Turn off the warning for not finding symbols...It's quite annoying | |
Rdio::log_couldnt_find_symbols = false | |
# Collect all the artists for this user | |
artists = [] | |
start = 0 | |
count = 10 | |
while true | |
all = user.artists_in_collection start,count | |
break if not all or all.empty? | |
artists += all | |
puts "Found #{all.length} artists, have #{artists.length}" | |
start += count | |
end | |
# Go over all the artists and remove existing playlist, if it | |
# exists, and create a new playlist | |
artists.each do |artist| | |
name = artist.name | |
desc = artist.name + ' All' | |
tracks = user.tracks_for_artist_in_collection artist | |
pl = Rdio::Playlist.create name,desc,tracks | |
next if not pl | |
puts "Added '#{pl.name}' with #{tracks.length} tracks" | |
end | |
end | |
main ARGV |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment