Commit 9cfff239 authored by sebaro's avatar sebaro

Add second source for YouTube videos

parent 6f900ea2
......@@ -3,8 +3,11 @@
/* SaveTube Changelog */
#2019.09.12
- YouTube: adds a second source for videos in case the first fails or is not available
#2019.09.01
- YouTube: exclude multi segment DASH videos
- YouTube: excludes multi segment DASH videos
#2019.08.17
- YouTube: adds VLD/240, LD/360 DASH videos
......
......@@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "SaveTube",
"version": "2019.9.1",
"version": "2019.9.12",
"description": "Download videos from video sharing web sites.",
......
// ==UserScript==
// @name SaveTube
// @version 2019.09.01
// @version 2019.09.12
// @description Download videos from video sharing web sites.
// @author sebaro
// @namespace http://sebaro.pro/savetube
......@@ -582,7 +582,33 @@ function SaveTube() {
/* Get Videos Content */
var ytVideosEncodedFmts, ytVideosAdaptiveFmts, ytVideosContent, ytHLSVideos, ytHLSContent;
ytVideosEncodedFmts = getMyContent(page.url, '"url_encoded_fmt_stream_map\\\\?":\\s*\\\\?"(.*?)\\\\?"', false);
if (!ytVideosEncodedFmts) {
ytVideosEncodedFmtsNew = getMyContent(page.url, '"formats\\\\?":\\s*(\\[.*?\\])', false);
if (ytVideosEncodedFmtsNew) {
ytVideosEncodedFmts = '';
ytVideosEncodedFmtsNew = cleanMyContent(ytVideosEncodedFmtsNew, false);
ytVideosEncodedFmtsNew = ytVideosEncodedFmtsNew.match(new RegExp('"url":\s*".*?"', 'g'));
if (ytVideosEncodedFmtsNew) {
for (var i = 0 ; i < ytVideosEncodedFmtsNew.length; i++) {
ytVideosEncodedFmts += ytVideosEncodedFmtsNew[i].replace(/"/g, '').replace('url:', 'url=') + ',';
}
}
}
}
ytVideosAdaptiveFmts = getMyContent(page.url, '"adaptive_fmts\\\\?":\\s*\\\\?"(.*?)\\\\?"', false);
if (!ytVideosAdaptiveFmts) {
ytVideosAdaptiveFmtsNew = getMyContent(page.url, '"adaptiveFormats\\\\?":\\s*(\\[.*?\\])', false);
if (ytVideosAdaptiveFmtsNew) {
ytVideosAdaptiveFmts = '';
ytVideosAdaptiveFmtsNew = cleanMyContent(ytVideosAdaptiveFmtsNew, false);
ytVideosAdaptiveFmtsNew = ytVideosAdaptiveFmtsNew.match(new RegExp('"url":\s*".*?"', 'g'));
if (ytVideosAdaptiveFmtsNew) {
for (var i = 0 ; i < ytVideosAdaptiveFmtsNew.length; i++) {
ytVideosAdaptiveFmts += ytVideosAdaptiveFmtsNew[i].replace(/"/g, '').replace('url:', 'url=') + ',';
}
}
}
}
if (!ytVideosAdaptiveFmts) {
var ytDASHVideos, ytDASHContent;
ytDASHVideos = getMyContent(page.url, '"dashmpd\\\\?":\\s*\\\\?"(.*?)\\\\?"', false);
......@@ -626,18 +652,49 @@ function SaveTube() {
var ytVideoID = page.url.match(/(\?|&)v=(.*?)(&|$)/);
ytVideoID = (ytVideoID) ? ytVideoID[2] : null;
if (ytVideoID) {
var ytVideosInfo = getMyContent(page.win.location.protocol + '//' + page.win.location.hostname + '/get_video_info?video_id=' + ytVideoID + '&eurl=https://youtube.googleapis.com/v/', 'TEXT', false);
if (ytVideosInfo) {
ytVideosEncodedFmts = ytVideosInfo.match(/url_encoded_fmt_stream_map=(.*?)&/);
ytVideosEncodedFmts = (ytVideosEncodedFmts) ? ytVideosEncodedFmts[1] : null;
if (ytVideosEncodedFmts) {
ytVideosEncodedFmts = cleanMyContent(ytVideosEncodedFmts, true);
ytVideosContent = ytVideosEncodedFmts;
var ytVideosInfoPage = page.win.location.protocol + '//' + page.win.location.hostname + '/get_video_info?video_id=' + ytVideoID + '&eurl=https://youtube.googleapis.com/v/';
ytVideosEncodedFmts = getMyContent(ytVideosInfoPage, 'url_encoded_fmt_stream_map=(.*?)&', false);
if (ytVideosEncodedFmts) {
ytVideosEncodedFmts = cleanMyContent(ytVideosEncodedFmts, true);
ytVideosContent = ytVideosEncodedFmts;
}
else {
ytVideosEncodedFmtsNew = getMyContent(ytVideosInfoPage, 'formats%22%3A(%5B.*?%5D)', false);
if (ytVideosEncodedFmtsNew) {
ytVideosEncodedFmts = '';
ytVideosEncodedFmtsNew = cleanMyContent(ytVideosEncodedFmtsNew, true);
ytVideosEncodedFmtsNew = ytVideosEncodedFmtsNew.match(new RegExp('"(url|cipher)":\s*".*?"', 'g'));
if (ytVideosEncodedFmtsNew) {
for (var i = 0 ; i < ytVideosEncodedFmtsNew.length; i++) {
ytVideosEncodedFmts += ytVideosEncodedFmtsNew[i].replace(/"/g, '').replace('url:', 'url=').replace('cipher:', '') + ',';
}
if (ytVideosEncodedFmts.indexOf('%3A%2F%2F') != -1) {
ytVideosEncodedFmts = cleanMyContent(ytVideosEncodedFmts, true);
}
ytVideosContent = ytVideosEncodedFmts;
}
}
}
if (!ytVideosAdaptiveFmts) {
ytVideosAdaptiveFmts = getMyContent(ytVideosInfoPage, 'adaptive_fmts=(.*?)&', false);
if (ytVideosAdaptiveFmts) {
ytVideosAdaptiveFmts = cleanMyContent(ytVideosAdaptiveFmts, true);
}
if (!ytVideosAdaptiveFmts) {
ytVideosAdaptiveFmts = ytVideosInfo.match(/adaptive_fmts=(.*?)&/);
ytVideosAdaptiveFmts = (ytVideosAdaptiveFmts) ? ytVideosAdaptiveFmts[1] : null;
if (ytVideosAdaptiveFmts) ytVideosAdaptiveFmts = cleanMyContent(ytVideosAdaptiveFmts, true);
else {
ytVideosAdaptiveFmtsNew = getMyContent(ytVideosInfoPage, 'adaptiveFormats%22%3A(%5B.*?%5D)', false);
if (ytVideosAdaptiveFmtsNew) {
ytVideosAdaptiveFmts = '';
ytVideosAdaptiveFmtsNew = cleanMyContent(ytVideosAdaptiveFmtsNew, true);
ytVideosAdaptiveFmtsNew = ytVideosAdaptiveFmtsNew.match(new RegExp('"(url|cipher)":\s*".*?"', 'g'));
if (ytVideosAdaptiveFmtsNew) {
for (var i = 0 ; i < ytVideosAdaptiveFmtsNew.length; i++) {
ytVideosAdaptiveFmts += ytVideosAdaptiveFmtsNew[i].replace(/"/g, '').replace('url:', 'url=').replace('cipher:', '') + ',';
}
if (ytVideosAdaptiveFmts.indexOf('%3A%2F%2F') != -1) {
ytVideosAdaptiveFmts = cleanMyContent(ytVideosAdaptiveFmts, true);
}
}
}
}
}
}
......
// ==UserScript==
// @name SaveTube
// @version 2019.09.01
// @version 2019.09.12
// @description Download videos from video sharing web sites.
// @author sebaro
// @namespace http://sebaro.pro/savetube
......@@ -582,7 +582,33 @@ function SaveTube() {
/* Get Videos Content */
var ytVideosEncodedFmts, ytVideosAdaptiveFmts, ytVideosContent, ytHLSVideos, ytHLSContent;
ytVideosEncodedFmts = getMyContent(page.url, '"url_encoded_fmt_stream_map\\\\?":\\s*\\\\?"(.*?)\\\\?"', false);
if (!ytVideosEncodedFmts) {
ytVideosEncodedFmtsNew = getMyContent(page.url, '"formats\\\\?":\\s*(\\[.*?\\])', false);
if (ytVideosEncodedFmtsNew) {
ytVideosEncodedFmts = '';
ytVideosEncodedFmtsNew = cleanMyContent(ytVideosEncodedFmtsNew, false);
ytVideosEncodedFmtsNew = ytVideosEncodedFmtsNew.match(new RegExp('"url":\s*".*?"', 'g'));
if (ytVideosEncodedFmtsNew) {
for (var i = 0 ; i < ytVideosEncodedFmtsNew.length; i++) {
ytVideosEncodedFmts += ytVideosEncodedFmtsNew[i].replace(/"/g, '').replace('url:', 'url=') + ',';
}
}
}
}
ytVideosAdaptiveFmts = getMyContent(page.url, '"adaptive_fmts\\\\?":\\s*\\\\?"(.*?)\\\\?"', false);
if (!ytVideosAdaptiveFmts) {
ytVideosAdaptiveFmtsNew = getMyContent(page.url, '"adaptiveFormats\\\\?":\\s*(\\[.*?\\])', false);
if (ytVideosAdaptiveFmtsNew) {
ytVideosAdaptiveFmts = '';
ytVideosAdaptiveFmtsNew = cleanMyContent(ytVideosAdaptiveFmtsNew, false);
ytVideosAdaptiveFmtsNew = ytVideosAdaptiveFmtsNew.match(new RegExp('"url":\s*".*?"', 'g'));
if (ytVideosAdaptiveFmtsNew) {
for (var i = 0 ; i < ytVideosAdaptiveFmtsNew.length; i++) {
ytVideosAdaptiveFmts += ytVideosAdaptiveFmtsNew[i].replace(/"/g, '').replace('url:', 'url=') + ',';
}
}
}
}
if (!ytVideosAdaptiveFmts) {
var ytDASHVideos, ytDASHContent;
ytDASHVideos = getMyContent(page.url, '"dashmpd\\\\?":\\s*\\\\?"(.*?)\\\\?"', false);
......@@ -626,18 +652,49 @@ function SaveTube() {
var ytVideoID = page.url.match(/(\?|&)v=(.*?)(&|$)/);
ytVideoID = (ytVideoID) ? ytVideoID[2] : null;
if (ytVideoID) {
var ytVideosInfo = getMyContent(page.win.location.protocol + '//' + page.win.location.hostname + '/get_video_info?video_id=' + ytVideoID + '&eurl=https://youtube.googleapis.com/v/', 'TEXT', false);
if (ytVideosInfo) {
ytVideosEncodedFmts = ytVideosInfo.match(/url_encoded_fmt_stream_map=(.*?)&/);
ytVideosEncodedFmts = (ytVideosEncodedFmts) ? ytVideosEncodedFmts[1] : null;
if (ytVideosEncodedFmts) {
ytVideosEncodedFmts = cleanMyContent(ytVideosEncodedFmts, true);
ytVideosContent = ytVideosEncodedFmts;
var ytVideosInfoPage = page.win.location.protocol + '//' + page.win.location.hostname + '/get_video_info?video_id=' + ytVideoID + '&eurl=https://youtube.googleapis.com/v/';
ytVideosEncodedFmts = getMyContent(ytVideosInfoPage, 'url_encoded_fmt_stream_map=(.*?)&', false);
if (ytVideosEncodedFmts) {
ytVideosEncodedFmts = cleanMyContent(ytVideosEncodedFmts, true);
ytVideosContent = ytVideosEncodedFmts;
}
else {
ytVideosEncodedFmtsNew = getMyContent(ytVideosInfoPage, 'formats%22%3A(%5B.*?%5D)', false);
if (ytVideosEncodedFmtsNew) {
ytVideosEncodedFmts = '';
ytVideosEncodedFmtsNew = cleanMyContent(ytVideosEncodedFmtsNew, true);
ytVideosEncodedFmtsNew = ytVideosEncodedFmtsNew.match(new RegExp('"(url|cipher)":\s*".*?"', 'g'));
if (ytVideosEncodedFmtsNew) {
for (var i = 0 ; i < ytVideosEncodedFmtsNew.length; i++) {
ytVideosEncodedFmts += ytVideosEncodedFmtsNew[i].replace(/"/g, '').replace('url:', 'url=').replace('cipher:', '') + ',';
}
if (ytVideosEncodedFmts.indexOf('%3A%2F%2F') != -1) {
ytVideosEncodedFmts = cleanMyContent(ytVideosEncodedFmts, true);
}
ytVideosContent = ytVideosEncodedFmts;
}
}
}
if (!ytVideosAdaptiveFmts) {
ytVideosAdaptiveFmts = getMyContent(ytVideosInfoPage, 'adaptive_fmts=(.*?)&', false);
if (ytVideosAdaptiveFmts) {
ytVideosAdaptiveFmts = cleanMyContent(ytVideosAdaptiveFmts, true);
}
if (!ytVideosAdaptiveFmts) {
ytVideosAdaptiveFmts = ytVideosInfo.match(/adaptive_fmts=(.*?)&/);
ytVideosAdaptiveFmts = (ytVideosAdaptiveFmts) ? ytVideosAdaptiveFmts[1] : null;
if (ytVideosAdaptiveFmts) ytVideosAdaptiveFmts = cleanMyContent(ytVideosAdaptiveFmts, true);
else {
ytVideosAdaptiveFmtsNew = getMyContent(ytVideosInfoPage, 'adaptiveFormats%22%3A(%5B.*?%5D)', false);
if (ytVideosAdaptiveFmtsNew) {
ytVideosAdaptiveFmts = '';
ytVideosAdaptiveFmtsNew = cleanMyContent(ytVideosAdaptiveFmtsNew, true);
ytVideosAdaptiveFmtsNew = ytVideosAdaptiveFmtsNew.match(new RegExp('"(url|cipher)":\s*".*?"', 'g'));
if (ytVideosAdaptiveFmtsNew) {
for (var i = 0 ; i < ytVideosAdaptiveFmtsNew.length; i++) {
ytVideosAdaptiveFmts += ytVideosAdaptiveFmtsNew[i].replace(/"/g, '').replace('url:', 'url=').replace('cipher:', '') + ',';
}
if (ytVideosAdaptiveFmts.indexOf('%3A%2F%2F') != -1) {
ytVideosAdaptiveFmts = cleanMyContent(ytVideosAdaptiveFmts, true);
}
}
}
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment