Last active
December 18, 2015 04:09
-
-
Save MiketoString/5723545 to your computer and use it in GitHub Desktop.
Ruby script to create youtube playlist from a list of keywords Example: Create playlist by listing songs in a file
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
# Build list of videos from keywords.txt file | |
# Each line is it's own youtube search | |
# | |
# Setup instructions | |
# | |
# Requires ruby to be installed and youtube_it gem | |
# sudo gem install youtube_it | |
# | |
# Requires youtube dev account. 2 step signup to get dev key from here if you already have gmail | |
# http://code.google.com/apis/youtube/dashboard | |
# Replace email, password, and dev key below | |
# | |
# Run script, and it will create playlist | |
# ruby playlist-from-keywords.rb | |
#include ruby youtube library | |
require 'youtube_it' | |
# create new youtube client with auth key | |
youtube = YouTubeIt::Client.new( :username => "Your Email", :password => "Your Password", :dev_key => "GET THIS FROM SIGNING UP FOR DEV ACCOUNT") | |
# create new playlist | |
playlist = youtube.add_playlist(:title => "My Plalist" ) | |
#read each line from the file 1 by 1 | |
file = File.new( "keywords.txt", "r" ) | |
while( keyword = file.gets ) | |
# run query against youtube | |
results = youtube.videos_by( :query => keyword ) | |
#if results found, add first one to playlist | |
if( results.total_result_count > 0 ) | |
youtube.add_video_to_playlist( playlist.playlist_id, results.videos[0].video_id ) | |
else | |
puts "Failed to find anything for " + keyword | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment