I am currently playing with ruby and have come up with the following
require 'simple_youtube'
def video_search(term, maxresults, file)
video_search = Youtube::Video.find(:params => {:q => "#{term}", :"max-results" => "#{maxresults}", :v => '2'})
min = 0 # => setting min variable = 0
max = video_search.entry.size # => setting max to #{maxresults}
while min < max do
export_results(file,video_search.entry[min].link[0].href) # => outputs each of the results to the listed file
min +=1
end
run = exec("~/Scripts/BASH/./music.sh #{file}") #=> Automatically downloads the items
end
def export_results(file, item)
open(file, 'a') do |f|
f.puts "#{item}\n"
end
end
video_search(ARGV[0],ARGV[1],ARGV[2]) # => Call the search with arguments
# => ARGV[0] - #{term}
# => ARGV[1] - #{maxresults}
# => ARGV[2] - #{file}
What I would like to do now is have a file of search terms and call the video_search with each item in the file
file='/users/Ondrovic/Desktop/music.txt'
f = File.open(file, "r")
f.each_line { |line|
puts line
}
f.close
The above I can read each line just not sure how to incorporate the two properly.
/users/Ondrovic/Desktop/music.txt would contain something like the following
Trapt Trapt
Godsmack Shine Down
etc
Then read each of them from the file and run the search
Test.txtand what's in/users/Ondrovic/Desktop/music.txtfile?