Last active
July 22, 2017 17:09
-
-
Save trickart/124846be85b600cbe95b4476f4bce729 to your computer and use it in GitHub Desktop.
ニコニコの動画をアレするやつ。要niconico gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.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