Skip to content

Instantly share code, notes, and snippets.

@dylan-conlin
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylan-conlin/a9afcb81d0f55bcf381c to your computer and use it in GitHub Desktop.
Save dylan-conlin/a9afcb81d0f55bcf381c to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'net/http'
require 'youtube_it'
require 'awesome_print'
uri = URI('http://www.kimonolabs.com/api/9zx1t7xi?apikey=xxxxxx')
response = Net::HTTP.get uri
results = JSON.parse response
tracks = results['results']['collection1']
queries = []
tracks.each do |track|
queries.push(track['artist']['text'] + ' ' + track['track']['text'])
end
@client = YouTubeIt::Client.new(
username: 'dylanconlin',
password: 'xxxxxxxxxxxxxxxxx',
dev_key: 'xxxxxxxxxxxxxxxxx',
)
video_results = []
queries.each do |query|
results = @client.videos_by(query: query)
if results
unless results.videos.first.nil?
ap results.videos.first.title
video_results.push(results.videos.first.video_id)
end
else
ap "cannot find #{query}"
end
end
File.open('/Users/dylanconlin/ra_songs.json', 'w') do |f|
f.write(JSON.pretty_generate(video_results))
end
playlist = @client.add_playlist(
title: 'Resident Advisor - Top 100 Tracks - 2014',
description: 'This playlist is generated programatically from http://www.residentadvisor.net/dj-charts.aspx?top=100&yr=2014'
)
video_ids.each do |v|
@client.add_video_to_playlist(playlist.playlist_id, v)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment