Skip to content

Instantly share code, notes, and snippets.

@ToQoz
Forked from ssig33/nicodown
Created February 3, 2012 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ToQoz/1727085 to your computer and use it in GitHub Desktop.
Save ToQoz/1727085 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#coding:utf-8
require 'mechanize'
require 'xmlsimple'
video_ids = ARGV
mail = ''
password = ''
alice = Mechanize.new
page = alice.get "https://secure.nicovideo.jp/secure/login_form"
f = page.forms.first
f.mail = mail
f.password = password
page = alice.submit f
ARGV.each{|id|
page = alice.get "http://www.nicovideo.jp/watch/#{id}"
page = alice.get "http://www.nicovideo.jp/api/getflv?v=#{id}"
url = CGI.unescape(page.body).split('&url=')[1].split('&').first
page = alice.get "http://ext.nicovideo.jp/api/getthumbinfo/#{id}"
info = XmlSimple.xml_in(page.body)
title = info['thumb'].first['title'].first
type = info['thumb'].first['movie_type'].first
name ="#{id}_#{title}.#{type}".gsub(/\//, '/')
print 'Download '
print name
print '...'
open(name,'w'){|f| f.puts alice.get(url).body}
puts ' Done.'
}
#!/usr/bin/env ruby
#coding:utf-8
require 'net/http'
require 'kconv'
require 'uri'
require 'json'
require 'cgi'
require 'mechanize'
page = Mechanize.new.get(ARGV[0])
info = JSON.parse(page.body.to_s.scan(/yt.playerConfig.*$/).first.sub(/yt.playerConfig\ =\ /, "").chop)
begin
url = CGI.unescape(info["args"]["url_encoded_fmt_stream_map"].split("url=")[1].split("&").first)
title = page.root.xpath("//*[@id='eow-title']").inner_text.to_s.gsub(/\n/, "").sub(/^\ */, '').sub(/\ *?$/, '').gsub(/\//, '/')
type = CGI.unescape(info["args"]["url_encoded_fmt_stream_map"].split("type=")[1].split("&").first).split("video/")[1].split(";").first
system "wget", url, "-O", "#{title}.#{type}"
rescue
url = CGI.unescape info["args"]["url_encoded_fmt_stream_map"].split("conn=")[2].split("&").first
title = page.root.xpath("//*[@id='eow-title']").inner_text.to_s.gsub(/\n/, "").sub(/^\ */, '').sub(/\ *?$/, '').gsub(/\//, '/')
type = CGI.unescape(info["args"]["url_encoded_fmt_stream_map"].split("type=")[1].split("&").first).split("video/")[1].split(";").first
#puts "rtmpdump -r '#{url}' -o \"#{title}.#{type}\""
#system "rtmpdump -r '#{url}' -o \"#{title}.#{type}\" --resume"
#system "rtmpdump", '-r', url, '-o', "#{title}.#{type}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment