puts "Creating MUSE folder..."
muselists = container.add_folder "__MUSEPLAYLISTS"
folders.each do |year_label, year|
year.each do |month_label, month|
month.each do |day_label, day|
day_list = container.add day_label, force: true
htracks = day.map { |x| Hallon::Track.new(x['spotify_uri'])
day_list.insert(0,htracks)
muselists.contents.push day_list
day_list.upload
end
end
end
#!/usr/bin/env ruby# encoding: utf-8
require 'hallon'
## CONFIG@spotify_user = "facebo...@gmail.com"@spotify_password = "PASSWORD_HERE"
# PREDEFINED PLAYLIST OBJECT@playlists_object = { "Playlist 1" => [ ], "Playlist 2" => [ ]}
## END CONFIG
## Load and wait looperdef loadandwait(obj) obj.load(5)rescue Interrupt puts "Interrupted!" exitrescue Exception => e puts e.message retryend
begin## Initialize Spotify Session session = Hallon::Session.initialize IO.read('./spotify_appkey.key'), {:load_playlists => true } session.login! @spotify_user, @spotify_password
## Get User Container print "Getting Spotify container for #{@spotify_user}..." container = session.container loadandwait(container) puts "Done."
## Create Folder at position / index zero playlist_folder = container.insert_folder 0, "Hallon Playlists"
## Create Playlists puts "Creating 'Hallon Playlists' folder in Spotify..." @playlists_object.reverse_each do |playlist_label, tracks|
## Create Playlist playlist = container.add "#{playlist_label}", true
## Playlist will be at the last index of the container, move to index 1 -- this pushes playlist_folder.end down container.move(container.size-1, 1)
## Create Hallon::Track for each spotify URL, insert into playlist playlist.insert(0, tracks.map { |x| Hallon::Track.new(x) }) if playlist.size > 0 then ## Upload playlist print "\tUploading playlist: #{playlist_label}..." begin print '.' playlist.upload(30) STDOUT.flush rescue Exception => e retry end puts "Done!" else ## Remove playlist from container container.remove(1) end endrescue Exception => e puts e.message puts e.backtracerescue Interrupt puts "Interrupted!" exitend