Created
November 25, 2013 23:09
-
-
Save shipstar/7650584 to your computer and use it in GitHub Desktop.
Super hacky Turntable --> Plug.dj importer
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
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