Skip to content

Instantly share code, notes, and snippets.

@nebs
Created July 24, 2016 18:53
Show Gist options
  • Save nebs/9f69595e7dd918d6fd83a6af9f7716cd to your computer and use it in GitHub Desktop.
Save nebs/9f69595e7dd918d6fd83a6af9f7716cd to your computer and use it in GitHub Desktop.
Ruby script for downloading multiple YouTube video thumbnail images.
# This gist is used to batch download thumbnails for YouTube videos.
# You must create a txt file that includes a list of video IDs (one per line).
#
# To get the IDs for your videos:
# 1. Goto: https://www.youtube.com/my_videos
# 2. Open a JS Console
# 3. Run: var o="";var v=document.getElementsByClassName("vm-video-title-container");for(var i in v){o+=v[i].id.replace("title_","")+"\n";}
# 4. The variable "o" contains a string with all the IDs, type "o" to print it.
# 5. Copy the IDs into a text file (one per line)
#
# Once you have a txt file with the IDs, simply run (replacing video_ids.txt with your txt file):
# ruby thumbdown.rb video_ids.txt
require "open-uri"
require 'fileutils'
thumbnails_dir = "thumbnails"
unless File.directory?(thumbnails_dir)
FileUtils.mkdir_p(thumbnails_dir)
end
File.open(ARGV[0], "r").each_line do |line|
video_id = line.strip
url = "http://img.youtube.com/vi/#{video_id}/maxresdefault.jpg"
puts "Downloading #{url}"
File.open("#{thumbnails_dir}/thumb_#{video_id}.jpg", 'wb') do |fo|
fo.write open(url).read
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment