- Code:
// ==UserScript==
// @name Download YouTube Videos as MP4
// @description Adds a button that lets you download YouTube videos.
// @namespace http://googlesystem.blogspot.com
// @include http://*.youtube.com/watch?*
// @include https://*.youtube.com/watch?*
// @match http://*.youtube.com/watch?*
// @match https://*.youtube.com/watch?*
// @source http://userscripts.org/scripts/show/109103
// @author Gantt
// @version 1.3
// @date 2011-08-11
// @license MIT License
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAB3RJTUUH2wMOCgIoGUYEAQAAAAlwSFlzAAALEgAACxIB0t1+/AAAAARnQU1BAACxjwv8YQUAAAGSUExURfi/JO/v797e3sbGxq2traWlpZSUlJycnNbW1oyEhIRaWow5OZQhIZwYGKUQEKUICK0ICJQxMYxKSoxzc4x7e4RCQpQYGKUAAK0AALUAAL0AAK0QEIxra5QpKa0YGIxSUsYAAKUhIZR7e87Ozr0ICJRSUr29vYxjY6U5OaUpKa0hIb21tZwAALUICO/Ozu/GxqUxMZSEhLUYGO/W1r0YGKVCQpQQEL0pKffe3vfW1pxra5Q5OcZCQvfn585CQr2trZx7e8ZSUs5SUq05Oc5jY9ZjY84AAKWMjM5zc957e60pKdaMjOelpbWcnLWUlLVCQsYYGMYICNbOzpQICMYhIbV7e5xaWt6cnPfv79bGxt6lpe+9vc5KSs6lpb0xMc6EhM69vbUxMbUhIb1aWs61tcZaWuecnMYxMb1KSsZjY96UlNa1td7W1r17e9a9vZwQEN6trb1jY8YQENZra+fOzr1zc85aWufe3t6MjMY5OdZaWt61tdZ7e+/n5+e9vc6MjMZra+/e3ue1tdalpd7GxrUpKalL4aAAAAABdFJOUwBA5thmAAACxklEQVR42uXX/1/SQBgH8NuAoEQ2ijgbBivJLznBAiUUKiyJSgOVAk0tKZKw75mRRt/7v4MBY8ezjW39Vs8v8rqHz/u1jbvbidC/XL8KmcpOqVT6nSjXjooGw8WfFd+QWGfE4oLbtbr++PdMOy0BDYLjEj/0xevfWIyVAI7b/aIj/9WHsRrA8Yf9bqSexVgD4Lic9kWE/LgPwPGfNfJHDO4P8Iuq+S2M9QD8oUp+nxEAcFCtfgIA/14x/9ElAKDQbNQAwN9VAiYEABy0OgsAWAnB/AcBAtVWawkAfJ4CD0BQADZavYcQgI9h3CCQjpD5PcEgwG+SwLRhIL0vz78SjAPEU3hrHODfyX4I6rUJIP0G3oExoNwFXpoB+HwXmDEFpF9IwKA5YK+Tp9fMAdUOsC6YA553gKcmgdTfAhV1oMQqADndQDmJ0AZLAsFnCIV3VYDHJLAjDkZKciAaFz/lCeBJB1glgXBrNLndBWLJ9uZGAI+keTBLANL8SnWAzWRniAC2pG+6lQF0hfjTqCIBrEvjDwiggFSLuIUoLY0vEwAbUcsnc/LlnO02HGvEz+hXEeJ5Yj+4L2vNkxOJDSnlQzliIq2synr3embiUBjmw0FyU83KX04Ob+9aAK/Ppd5deZloz4HFlCHzt3sX0x2a6LcvQb4ab8r7i+DVdqvnCq/D5ZzqdhfAcr5B9wD0PNwPEu0ZnLwK9oPgNfCQJ2fhhhITJ3E8BjeUOXA+QNQlBh5xLjemVCgKjzgzNIJFjWF4yJoKhafgIWt6VHGmjgR0HvMuTipPdWQJ6AImbBRSE8aY/sC4er5xFx5vHyB4YRRpFWUf0AL4c+dHkHZRFo9TDeB9Aa3Llwjr8FlFwB+wO/rHm0VbPae9mPini/O5h/XGxatw2I6fGHAOuhiGZVxO98lTdgutP94yaIvVdqxZdpvFYTT9X9UfqQQlTXlm8wkAAAAASUVORK5CYII=
// ==/UserScript==
(function () {
var FORMAT_LABELS={'5':'FLV 240p','18':'MP4 360p','22':'MP4 720p (HD)','34':'FLV 360p','35':'FLV 480p','37':'MP4 1080p (HD)','38':'MP4 4K (HD)','43':'WebM 360p','44':'WebM 480p','45':'WebM 720p (HD)'};
var FORMAT_EXTENSIONS={'5':'flv','18':'mp4','22':'mp4','34':'flv','35':'flv','37':'mp4','38':'mp4','43':'webm','44':'webm','45':'webm'};
var FORMAT_LIST=['5','18','34','35','22','37','38'];
var DOWNLOAD_LINK_MESSAGES={'en':'Download'};
var DOWNLOAD_TOOLTIP_MESSAGES={'en':'Download this video'};
var DOWNLOAD_LINK_MESSAGE='Download';
var DOWNLOAD_TOOLTIP_MESSAGE='Download this video';
var DOWNLOAD_YOUTUBE_SPAN_ID='download-youtube-video';
var DOWNLOAD_YOUTUBE_FMT_ID='download-youtube-video-fmt';
var DOWNLOAD_YOUTUBE_BUTTON_ID='download-youtube-video-button';
var OLD_UI=1, NEW_UI=2;
var videoId, videoTicket, videoFormats, videoTitle='';
var interfaceVersion=OLD_UI;
run();
function run() {
// download-youtube-video is a container for the download button
if (document.getElementById(DOWNLOAD_YOUTUBE_SPAN_ID)) return;
// obtain video ID, temporary ticket, formats map
var videoPlayer=document.getElementById('watch-player');
if (videoPlayer && videoPlayer.getAttribute('class').indexOf('html5')==-1) { // Flash
var flashValues=videoPlayer.innerHTML;
var videoIdMatches=flashValues.match(/(?:"|\&)video_id=([^(\&|$)]*)/);
videoId=(videoIdMatches)?videoIdMatches[1]:null;
var videoTicketMatches=flashValues.match(/(?:"|\&)t=([^(\&|$)]*)/);
videoTicket=(videoTicketMatches)?videoTicketMatches[1]:null;
var videoFormatsMatches=flashValues.match(/(?:"|\&)url_encoded_fmt_stream_map=([^(\&|$)]*)/);
videoFormats=(videoFormatsMatches)?videoFormatsMatches[1]:null;
}
if (videoId==null || videoTicket==null) { // HTML5 - Firefox, Opera
var config=null;
if(typeof(unsafeWindow)=='undefined') { // Opera
unsafeWindow=window;
}
if (unsafeWindow.yt && unsafeWindow.yt.getConfig) {
config=unsafeWindow.yt.getConfig('PLAYER_CONFIG');
}
if (config && config.args) {
var args=config.args;
videoId=args['video_id'];
videoTicket=args['t'];
videoFormats=args['url_encoded_fmt_stream_map'];
}
}
if (videoId==null || videoTicket==null) { // everything else (HTML5 - Chrome)
var bodyContent=document.body.innerHTML;
var videoIdMatches=bodyContent.match(/\"video_id\":\s*\"([^\"]*)\"/);
videoId=(videoIdMatches)?videoIdMatches[1]:null;
var videoTicketMatches=bodyContent.match(/\"t\":\s*\"([^\"]*)\"/);
videoTicket=(videoTicketMatches)?videoTicketMatches[1]:null;
var videoFormatsMatches=bodyContent.match(/\"url_encoded_fmt_stream_map\":\s*\"([^\"]*)\"/);
videoFormats=(videoFormatsMatches)?videoFormatsMatches[1]:null;
}
if (videoId==null || videoTicket==null) return;
// video title
var headerTitle=document.getElementById('eow-title');
if (headerTitle!=null) {
videoTitle=headerTitle.textContent || headerTitle.innerText || '';
}
if (videoTitle=='') {
var titleTag=document.title;
if (titleTag!=null) {
videoTitle=titleTag.replace(/^YouTube \- /i,'');
}
}
videoTitle=videoTitle.replace(/[#"\?:\*]/g,'').replace(/[&\|\\\/]/g,'_').replace(/'/g,'\'').replace(/^\s+|\s+$/g, '').replace(/\.+$/g, '');
if (videoTitle=='') {
videoTitle='video';
}
// parse fmt_url_map
var videoURL=new Array();
var sep1='%2C', sep2='%26', sep3='%3D';
if (videoFormats.indexOf(',')>-1) {
sep1=',';
sep2='\\u0026';
sep3='=';
if (videoFormats.indexOf('&')>-1) {
sep2='&';
}
}
var videoFormatsGroup=videoFormats.split(sep1);
for (var i=0;i<videoFormatsGroup.length;i++){
var videoFormatsElem=videoFormatsGroup[i].split(sep2);
var url=videoFormatsElem[0].split(sep3)[1];
var itag=videoFormatsElem[4].split(sep3)[1];
videoURL[itag]=unescape(unescape(url)).replace(/\\\//g,'/').replace(/\\u0026/g,'&');
}
var downloadCodeList=[];
arr = [];
for (var i in videoURL) {
if (videoURL.hasOwnProperty(i) && !isNaN(+i)) {
arr.push(i);
}
}
//for (var i=0;i<FORMAT_LIST.length;i++){
// var format=FORMAT_LIST[i];
for (var i=0;i<arr.length;i++){
var format=arr[i];
if (!(FORMAT_EXTENSIONS[format])) continue;
// don't add lower quality FLV versions to prevent clutter
//if (format=='5' && (videoURL['34']!=undefined||videoURL['35']!=undefined)) continue;
//if (format=='34' && videoURL['35']!=undefined) continue;
if (videoURL[format]!=undefined && FORMAT_LABELS[format]!=undefined) {
downloadCodeList.push({url:videoURL[format]+'&title='+videoTitle,format:format,label:FORMAT_LABELS[format]});
}
}
var uiLanguage=document.documentElement.getAttribute('lang');
if (/^lt|bg|uk$/.test(uiLanguage)) {
var likeButton=document.getElementById('watch-like');
if (likeButton) {
var spanElements=likeButton.getElementsByTagName('span');
if (spanElements) {
spanElements[0].style.display='none';
}
}
}
if (DOWNLOAD_LINK_MESSAGES[uiLanguage]!=null) {
DOWNLOAD_LINK_MESSAGE=DOWNLOAD_LINK_MESSAGES[uiLanguage];
}
if (DOWNLOAD_TOOLTIP_MESSAGES[uiLanguage]!=null) {
DOWNLOAD_TOOLTIP_MESSAGE=DOWNLOAD_TOOLTIP_MESSAGES[uiLanguage];
}
// find parent container
var parentElement=document.getElementById('watch-actions');
var rightElement=document.getElementById('watch-actions-right');
if (!rightElement && parentElement) {
interfaceVersion=NEW_UI;
}
if (parentElement==null) return;
// generate download code
var mainSpan=document.createElement('span');
var spanButton=document.createElement('span');
spanButton.setAttribute('class', 'yt-uix-button-content');
spanButton.appendChild(document.createTextNode(DOWNLOAD_LINK_MESSAGE));
mainSpan.appendChild(spanButton);
var spanSpace=document.createElement('span');
spanSpace.appendChild(document.createTextNode('\u00a0 '));
mainSpan.appendChild(spanSpace);
var imgButton=document.createElement('img');
imgButton.setAttribute('class', 'yt-uix-button-arrow');
mainSpan.appendChild(imgButton);
var listItems=document.createElement('ol');
listItems.setAttribute('style', 'display:none;');
listItems.setAttribute('class', 'yt-uix-button-menu');
for (var i=0;i<downloadCodeList.length;i++) {
var listItem=document.createElement('li');
var listLink=document.createElement('a');
listLink.setAttribute('style', 'text-decoration:none;');
listLink.setAttribute('href', downloadCodeList[i].url);
var listSpan=document.createElement('span');
listSpan.setAttribute('class', 'yt-uix-button-menu-item');
listSpan.setAttribute('loop', i+'');
listSpan.setAttribute('id', DOWNLOAD_YOUTUBE_FMT_ID+downloadCodeList[i].format);
listSpan.appendChild(document.createTextNode(downloadCodeList[i].label));
listLink.appendChild(listSpan);
listItem.appendChild(listLink);
listItems.appendChild(listItem);
}
mainSpan.appendChild(listItems);
var buttonElement=document.createElement('button');
buttonElement.setAttribute('id', DOWNLOAD_YOUTUBE_BUTTON_ID);
buttonElement.setAttribute('class', 'yt-uix-button yt-uix-tooltip' + ((interfaceVersion==OLD_UI)?' yt-uix-tooltip-reverse':''));
buttonElement.setAttribute('data-tooltip-timer', '271');
buttonElement.setAttribute('data-tooltip', DOWNLOAD_TOOLTIP_MESSAGE);
buttonElement.setAttribute('onclick', 'return false;');
buttonElement.setAttribute('type', 'button');
buttonElement.appendChild(mainSpan);
// add the button
var containerSpan=document.createElement('span');
containerSpan.setAttribute('id', DOWNLOAD_YOUTUBE_SPAN_ID);
var leftmostButton=document.getElementById('watch-transcript') || document.getElementById('watch-flag') || null;
if (leftmostButton && leftmostButton.parentNode==parentElement) {
containerSpan.appendChild(buttonElement);
containerSpan.appendChild(document.createTextNode(' '));
parentElement.insertBefore(containerSpan,leftmostButton);
} else {
containerSpan.appendChild(document.createTextNode(' '));
containerSpan.appendChild(buttonElement);
parentElement.appendChild(containerSpan);
}
for (var i=0;i<downloadCodeList.length;i++) {
var downloadFMT=document.getElementById(DOWNLOAD_YOUTUBE_FMT_ID+downloadCodeList[i].format);
if (downloadFMT.addEventListener) {
downloadFMT.addEventListener('click', downloadVideo, false);
} else if (downloadFMT.attachEvent) { // IE
downloadFMT.attachEvent('onclick', downloadVideo);
}
}
function downloadVideo(e) {
var e=e||window.event; // IE
var elem=e.target||e.srcElement;
e.returnValue=false;
if (e.preventDefault) {
e.preventDefault();
}
var loop=elem.getAttribute('loop');
document.location.href=downloadCodeList[loop].url;
}
}
})();
1 Script Download YOUTUBE Sat 08 Mar 2014, 17:16
girilayabot
Spammer
2 Re: Script Download YOUTUBE Sat 08 Mar 2014, 17:17
girilayabot
Spammer
cara mudah menggunakannya dengan menggunakan BOOKMARK script diatas. .
masukin script diatas sebagai LOCATION di BOOKMARK
- Code:
javascript:d=document;s=d.createElement("script");s.src="FILEJS";d.body.appendChild(s);void(0);
masukin script diatas sebagai LOCATION di BOOKMARK
Similar topics
Permissions in this forum:
Anda tidak dapat menjawab topik