Advertisement
Guest User

thumbnails-dl.rb

a guest
Nov 2nd, 2021
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.49 KB | None | 0 0
  1. require "json"
  2. require "open-uri"
  3. require "fileutils"
  4.  
  5. @hash
  6.  
  7. File.open("youtube-list.json") do |j|
  8.     @hash = JSON.load(j)
  9. end
  10.  
  11. # thumbnails という名前のディレクトリを作る処理をかけ
  12. FileUtils.mkdir_p("thumbnails") unless File.exist?("thumbnails")
  13.  
  14. @hash.each_with_index do |data, i|
  15.     File.open("thumbnails/#{i}-#{data["published_at"]}.jpg", "wb") do |file|
  16.         open(data["thumbnails"]) do |img|
  17.             file.puts img.read
  18.         end
  19.     end
  20. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement