Last active
December 27, 2015 21:19
-
-
Save h-collector/7390680 to your computer and use it in GitHub Desktop.
Download video from nicovideo.jp
This file contains hidden or 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
(function() { | |
if (location.href.indexOf("http://www.nicovideo.jp/watch/")!=-1) { | |
// find "watch/smXXX" style URI | |
$link = $('link').find('[rel=canonical]'); | |
origURI = $link.length ? $link.attr('href') : window.location.href; | |
// find title | |
var $title = jQuery('.videoHeaderTitle'); | |
// collect file information | |
var videoIdentifier = location.href.replace(/http.*?watch\/([^?]*)(\?.*)?$/g,"$1"); | |
// replace title | |
$input = $('<input type="text" value="[' + videoIdentifier + '] ' + $title.text() + '" />'); | |
$input.click($input.get(0).select); | |
$input.css({width: $title.width()}); | |
$title.text('').css({'font-size':'12px'}); | |
$title=jQuery('#videoHeader').append($input); | |
console.log('video id: ' + videoIdentifier); | |
jQuery.ajax({ | |
url: "http://flapi.nicovideo.jp/api/getflv?v="+videoIdentifier, | |
crossDomain: true, | |
xhrFields: { withCredentials: true }, | |
//headers: { "X-Requested-With": "XMLHttpRequest" }, | |
success: function(response){ | |
var tid=unescape(/thread_id\=(.*?)\&l/.exec(response)[1]); | |
var vn=/watch\/(.*?)$/.exec(origURI)[1]; | |
var flvURL=unescape(/url\=(.*?)\&link/.exec(response)[1]); | |
if (/nm/.exec(videoIdentifier)) { | |
flvURL += "as3"; | |
} | |
$title.append($('<a/>', {text: '[DL]', href: flvURL})); | |
if (tid != "") {// make links for "bgm" (custom banner above video) | |
jQuery.ajax({ | |
url: "http://flapi.nicovideo.jp/api/getbgm?v="+videoIdentifier, | |
crossDomain: true, | |
xhrFields: { withCredentials: true }, | |
success: function(xml, success, jqXHR){ | |
var $url = $(xml).find('url'); | |
if ($url.length > 0) { | |
var bgmURL=$url.eq(0).text(); | |
var bgmIdentifier=/s=(.*?)\./.exec(bgmURL)[1]; | |
$title.append($('<a/>', {text: '[BGM]', href: "http://www.nicovideo.jp/watch/nm"+bgmIdentifier})); | |
$title.append($('<a/>', {text: '[BGM DL]', href: bgmURL})); | |
} | |
} | |
}); | |
} | |
}, | |
error: function(request, status, error) { | |
console.log("on error: " + error + " status: " + status); | |
} | |
}); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment