Skip to content

Instantly share code, notes, and snippets.

@trickart
Last active July 22, 2017 17:09
Show Gist options
  • Save trickart/124846be85b600cbe95b4476f4bce729 to your computer and use it in GitHub Desktop.
Save trickart/124846be85b600cbe95b4476f4bce729 to your computer and use it in GitHub Desktop.
ニコニコの動画をアレするやつ。要niconico gem
#!/usr/bin/ruby
require 'uri'
def usage
puts "\nUsage: nico_dl video_url"
end
if ARGV[0] !~ URI.regexp then
puts "ARGV[0] is not URI"
usage
elsif ARGV[0].split("/")[2] != "www.nicovideo.jp" then
puts "URI is not www.nicovideo.jp"
usage
else
require 'niconico'
require '~/.config/nicologin'
video_id = ARGV[0].split("/")[-1]
nico = Niconico.new(MAIL, PASS)
nico.login
title = nico.video(video_id).get.at('title').inner_text.gsub(/\/| - ニコニコ動画/, "\/" => "/", " - ニコニコ動画" => "")
puts "download \"#{title}\""
video = nico.video(video_id).get_video
File.binwrite("#{Dir::pwd}/#{title}.mp4", video)
end
# ~/.config/に置く
MAIL = "YOUR ADRESS"
PASS = "YOUR PASSWORD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment