Class: Nv::CLI
Instance Method Summary collapse
- #browse(filepath) ⇒ Object
- #config(key = nil, value = nil) ⇒ Object
- #dl(ptr, output = ".") ⇒ Object
- #info(ptr) ⇒ Object
- #version ⇒ Object
Methods included from Niconico::Helper
Instance Method Details
#browse(filepath) ⇒ Object
72 73 74 75 |
# File 'lib/nv/cli.rb', line 72 def browse(filepath) video_id = File.basename(filepath).match(/[^\w]([\w]{2}\d+)[^\w]/)[1] system "open http://www.nicovideo.jp/watch/#{video_id}" end |
#config(key = nil, value = nil) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/nv/cli.rb', line 78 def config(key=nil, value=nil) config = Nv::Config.new(Nv::CONFIG_PATH) unless key puts "=== config(#{Nv::CONFIG_PATH}) ===" config.to_h.each do |k, v| puts "#{k}=#{v}" end return end if value config[key] = value config.save end puts "=== config(#{Nv::CONFIG_PATH}) ===" puts "#{key}=#{config[key]}" end |
#dl(ptr, output = ".") ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/nv/cli.rb', line 10 def dl(ptr, output=".") config = Nv::Config.new(Nv::CONFIG_PATH) config.verify_for_authentication!('dl') nico = Niconico::Base.new.sign_in(config.email, config.password) if mylist?(ptr) mylist = nico.mylist(ptr) puts "Title : #{mylist.title}" puts "Desc : #{mylist.description}" unless mylist.description.empty? escaped_title = escape_string(mylist.title) output = ['without-dir'] ? '.' : escaped_title mylist.items.each do |item| dl(item.link, output) end else video = nico.video(ptr) # Inspect puts "Downloading... #{video.title}" output ||= ['with-dir'] ? escape_string(video.title) : '.' # Download video.download output video.download_comments output if ['with-comments'] puts "+ done" end end |
#info(ptr) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/nv/cli.rb', line 45 def info(ptr) config = Nv::Config.new(Nv::CONFIG_PATH) config.verify_for_authentication!('info') nico = Niconico::Base.new.sign_in(config.email, config.password) if mylist?(ptr) mylist = nico.mylist(ptr) puts "Title : #{mylist.title}" puts "Desc : #{mylist.description}" mylist.items.each_with_index do |item, i| puts " #{i+1}. #{item.title}" end else video = nico.video(ptr) puts video.title puts '=' * 40 puts video.description puts '=' * 40 puts "URL: #{video.watch_url}" end end |