Sha256: 64ec502b23c66603378162f3253184d47609272b3ed4baa8ba48e65e9707e324

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require "youtube_sync/version"
require 'viddl-rb'
require "thor"
require 'yaml'

module YoutubeSync 
  class CLI  < Thor   
    
    default_task :perform
    desc "perform", "Download all links"
    
    long_desc <<-LONGDESC
    Passing a `-d` for a directory and `-f` for the file \n

    example:\n
    > $ youtube_sync -d /Users/Ioannis/Downloads -f list.txt\n
    
    NOTE: file must be in the same directory
      LONGDESC
      
    method_option :dir, 
    :aliases => "-d", 
    :desc => "Directory to store videos",
    :default => File.join(ENV['HOME'], "Desktop", "Youtube")
    
    method_option :file, 
    :aliases => "-f", 
    :desc => "File to load urls",
    :default =>   File.join(ENV['HOME'], "Desktop", "Youtube", "links.txt") 
      
    def perform
      dir, file  = options[:dir], options[:file]
      
      [dir, file].each  do |required|
        say "#{required} not exist", :red and return unless File.exist?(required)
      end
      
      open(file, 'r').each_line do |video|
        video.strip!
        
        if video.start_with? '#'
          say "Skipping  #{video}", :yellow
          next 
        end
        
        say "Downloading: #{video}", :green
        
        `cd #{dir} && viddl-rb -a #{video}`
      end  
      say "Done!", :green
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
youtube_sync-0.0.1 lib/youtube_sync.rb