Advertisement
Guest User

video-dl.rb

a guest
Nov 1st, 2021
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.82 KB | None | 0 0
  1. # このコードは @taroyanaka様 が書いてくれた以下の記事をコピーし、必要な部分だけ残したものです。
  2. # https://qiita.com/taroyanaka/items/c40f8d5df3ea67ba0b5a
  3.  
  4. require 'open3'
  5.  
  6. class Mediadl
  7.   def initialize(file_name="./download_urls.txt")
  8.     @file = file_name
  9.   end
  10.  
  11.   def line_counter
  12.     File.open(@file) do |f|
  13.       while f.gets
  14.         @total_lines = f.lineno
  15.       end
  16.     end
  17.     return @total_lines
  18.   end
  19.  
  20.   def dl
  21.     counter = 0
  22.     total_lines = self.line_counter
  23.     File.open(@file,'r').each do |url|
  24.       counter += 1
  25.       puts "start file:#{counter}/#{total_lines}"
  26.       Open3.capture3('youtube-dl -f mp4 ' + "#{url}")
  27.       puts  "finish file:#{counter}/#{total_lines}"
  28.     end
  29.     Process.waitall
  30.   end
  31. end
  32.  
  33. download = Mediadl.new
  34. download.dl
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement