Skip to content

Instantly share code, notes, and snippets.

@shipstar
Created November 25, 2013 23:09
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 shipstar/7650584 to your computer and use it in GitHub Desktop.
Save shipstar/7650584 to your computer and use it in GitHub Desktop.
Super hacky Turntable --> Plug.dj importer
require 'youtube_it'
PLAYLIST_TITLE = "Turntable to Plug"
auth = {
dev_key: <your key>,
username: <your Youtube username>,
password: <your Youtube password>
}
client = YouTubeIt::Client.new auth
songs = File.open("/Users/kshipley/Desktop/turntable_playlist.json").readlines
processed_songs = songs[1..-1].map do |raw_song|
song = raw_song.split(',').map { |el| el.gsub('"', '') }
{
artist: song[1],
title: song[3]
}
end; nil
playlist = client.playlists.detect { |p| p.title == PLAYLIST_TITLE } || client.add_playlist(title: PLAYLIST_TITLE)
processed_songs.inject({}) do |memo, song|
begin
sleep 1
query = [song[:artist], song[:title]].join(' ')
print "#{query}..."
response = client.videos_by query: query
if response.videos.any?
puts "Found #{response.videos.size} matches"
video = response.videos.first
client.add_video_to_playlist playlist.playlist_id, video.unique_id
else
puts ">>>>>>> No results for #{query}"
end
rescue => e
puts e.inspect
end
end; nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment