Created
September 10, 2016 09:36
-
-
Save KristupasSavickas/f220ee6da9ba79f931739dc1a58dcaf4 to your computer and use it in GitHub Desktop.
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 'google/apis/youtube_v3' | |
require 'youtube-dl.rb' | |
api_key = "xxx" | |
youtube = Google::Apis::YoutubeV3::YouTubeService.new | |
youtube.key = api_key | |
videos = ["https://www.youtube.com/watch?v=G-Vg2YS-sFE", | |
"https://www.youtube.com/watch?v=-gJysRyO21Q", | |
"https://www.youtube.com/watch?v=9yJMbfBw2Ec", | |
"https://www.youtube.com/watch?v=gAY9Yxsp1rw", | |
"https://www.youtube.com/watch?v=a5ITPHgfp1k", | |
"https://www.youtube.com/watch?v=Hj2o_kGMbcg", | |
"https://www.youtube.com/watch?v=WRFRkQjCqtY", | |
"https://www.youtube.com/watch?v=E3zAivZRPUc" | |
] | |
def find_video_official_api(query, youtube) | |
result = youtube.list_searches('snippet', q: query, type: 'video', max_results: 1).items.first | |
return nil unless result | |
result.id.video_id | |
rescue => e | |
puts "Error: #{e}" | |
nil | |
end | |
def find_video_youtube_dl(query) | |
youtube_dl = YoutubeDL::Video.new(query) | |
youtube_dl.information | |
end | |
official_avg = 0 | |
youtube_dl_avg = 0 | |
videos.each do |video| | |
t = Time.now | |
find_video_official_api(video, youtube) | |
official_avg += Time.now - t | |
t = Time.now | |
find_video_youtube_dl(video) | |
youtube_dl_avg += Time.now - t | |
end | |
puts "Youtube-dl.rb average: #{youtube_dl_avg / videos.length}" | |
puts "Official api average: #{official_avg / videos.length}" |
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 'google/apis/youtube_v3' | |
require 'youtube-dl.rb' | |
api_key = "xxx" | |
youtube = Google::Apis::YoutubeV3::YouTubeService.new | |
youtube.key = api_key | |
videos = ["https://www.youtube.com/watch?v=G-Vg2YS-sFE", | |
"https://www.youtube.com/watch?v=-gJysRyO21Q", | |
"https://www.youtube.com/watch?v=9yJMbfBw2Ec", | |
"https://www.youtube.com/watch?v=gAY9Yxsp1rw", | |
"https://www.youtube.com/watch?v=a5ITPHgfp1k", | |
"https://www.youtube.com/watch?v=Hj2o_kGMbcg", | |
"https://www.youtube.com/watch?v=WRFRkQjCqtY", | |
"https://www.youtube.com/watch?v=E3zAivZRPUc" | |
] | |
def find_video_official_api(query, youtube) | |
result = youtube.list_searches('snippet', q: query, type: 'video', max_results: 1).items.first | |
return nil unless result | |
result.id.video_id | |
rescue => e | |
puts "Error: #{e}" | |
nil | |
end | |
def find_video_youtube_dl(query) | |
youtube_dl = YoutubeDL::Video.new(query) | |
youtube_dl.information | |
end | |
official_avg = 0 | |
youtube_dl_avg = 0 | |
videos.each do |video| | |
t = Time.now | |
find_video_official_api(video, youtube) | |
official_avg += Time.now - t | |
t = Time.now | |
find_video_youtube_dl(video) | |
youtube_dl_avg += Time.now - t | |
end | |
puts "Youtube-dl.rb average: #{youtube_dl_avg / videos.length}" | |
puts "Official api average: #{official_avg / videos.length}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment