mirror of
https://github.com/goodtube4u/goodtube.git
synced 2025-11-22 10:16:11 +00:00
Playlist downloads fix
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name GoodTube
|
// @name GoodTube
|
||||||
// @namespace http://tampermonkey.net/
|
// @namespace http://tampermonkey.net/
|
||||||
// @version 4.508
|
// @version 4.509
|
||||||
// @description Loads Youtube videos from different sources. Also removes ads, shorts, etc.
|
// @description Loads Youtube videos from different sources. Also removes ads, shorts, etc.
|
||||||
// @author GoodTube
|
// @author GoodTube
|
||||||
// @match https://*.youtube.com/*
|
// @match https://*.youtube.com/*
|
||||||
@@ -5694,6 +5694,9 @@
|
|||||||
})
|
})
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
// Stop if this is no longer a pending download
|
// Stop if this is no longer a pending download
|
||||||
if (typeof goodTube_pendingDownloads[youtubeId] === 'undefined') {
|
if (typeof goodTube_pendingDownloads[youtubeId] === 'undefined') {
|
||||||
return;
|
return;
|
||||||
@@ -5913,77 +5916,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use userscript downloader for mobile because it doesn't support blobs
|
// Use userscript downloader for mobile because it doesn't support blobs
|
||||||
if (goodTube_mobile) {
|
goodTube_pendingDownloads[youtubeId] = GM.download({
|
||||||
goodTube_pendingDownloads[youtubeId] = GM.download({
|
url: url,
|
||||||
url: url,
|
name: fileName+fileExtension,
|
||||||
name: fileName+fileExtension,
|
// Success
|
||||||
// Success
|
onload: (e) => {
|
||||||
onload: (e) => {
|
|
||||||
// Stop if this is no longer a pending download
|
|
||||||
if (typeof goodTube_pendingDownloads[youtubeId] === 'undefined') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debug message
|
|
||||||
if (goodTube_debug) {
|
|
||||||
console.log('[GoodTube] Downloaded '+type+' - '+fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove from pending downloads
|
|
||||||
if (typeof goodTube_pendingDownloads[youtubeId] !== 'undefined') {
|
|
||||||
delete goodTube_pendingDownloads[youtubeId];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hide the downloading indicator
|
|
||||||
goodTube_player_videojs_hideDownloading();
|
|
||||||
},
|
|
||||||
// Error
|
|
||||||
onerror: (e) => {
|
|
||||||
// If anything went wrong, try again (next download server)
|
|
||||||
if (typeof goodTube_pendingRetry['download_'+youtubeId] !== 'undefined') {
|
|
||||||
clearTimeout(goodTube_pendingRetry['download_'+youtubeId]);
|
|
||||||
}
|
|
||||||
|
|
||||||
serverIndex++;
|
|
||||||
|
|
||||||
goodTube_pendingRetry['download_'+youtubeId] = setTimeout(function() {
|
|
||||||
goodTube_download(serverIndex, type, youtubeId, fileName);
|
|
||||||
}, goodTube_retryDelay);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// Download as a blob for desktop
|
|
||||||
else {
|
|
||||||
// Get the file (die after 10s)
|
|
||||||
fetch(url, {
|
|
||||||
signal: AbortSignal.timeout(10000)
|
|
||||||
})
|
|
||||||
.then(response => response.blob())
|
|
||||||
.then(blob => {
|
|
||||||
// Stop if this is no longer a pending download
|
// Stop if this is no longer a pending download
|
||||||
if (typeof goodTube_pendingDownloads[youtubeId] === 'undefined') {
|
if (typeof goodTube_pendingDownloads[youtubeId] === 'undefined') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the blob
|
|
||||||
let blobUrl = URL.createObjectURL(blob);
|
|
||||||
|
|
||||||
// Create a download link element and set params
|
|
||||||
let a = document.createElement('a');
|
|
||||||
a.style.display = 'none';
|
|
||||||
a.href = blobUrl;
|
|
||||||
a.download = fileName+fileExtension;
|
|
||||||
document.body.appendChild(a);
|
|
||||||
|
|
||||||
// Click the link to download
|
|
||||||
a.click();
|
|
||||||
|
|
||||||
// Remove the blob from memory
|
|
||||||
window.URL.revokeObjectURL(blobUrl);
|
|
||||||
|
|
||||||
// Remove the link
|
|
||||||
a.remove();
|
|
||||||
|
|
||||||
// Debug message
|
// Debug message
|
||||||
if (goodTube_debug) {
|
if (goodTube_debug) {
|
||||||
console.log('[GoodTube] Downloaded '+type+' - '+fileName);
|
console.log('[GoodTube] Downloaded '+type+' - '+fileName);
|
||||||
@@ -5996,9 +5938,10 @@
|
|||||||
|
|
||||||
// Hide the downloading indicator
|
// Hide the downloading indicator
|
||||||
goodTube_player_videojs_hideDownloading();
|
goodTube_player_videojs_hideDownloading();
|
||||||
})
|
},
|
||||||
// If anything went wrong, try again (next download server)
|
// Error
|
||||||
.catch((error) => {
|
onerror: (e) => {
|
||||||
|
// If anything went wrong, try again (next download server)
|
||||||
if (typeof goodTube_pendingRetry['download_'+youtubeId] !== 'undefined') {
|
if (typeof goodTube_pendingRetry['download_'+youtubeId] !== 'undefined') {
|
||||||
clearTimeout(goodTube_pendingRetry['download_'+youtubeId]);
|
clearTimeout(goodTube_pendingRetry['download_'+youtubeId]);
|
||||||
}
|
}
|
||||||
@@ -6008,8 +5951,8 @@
|
|||||||
goodTube_pendingRetry['download_'+youtubeId] = setTimeout(function() {
|
goodTube_pendingRetry['download_'+youtubeId] = setTimeout(function() {
|
||||||
goodTube_download(serverIndex, type, youtubeId, fileName);
|
goodTube_download(serverIndex, type, youtubeId, fileName);
|
||||||
}, goodTube_retryDelay);
|
}, goodTube_retryDelay);
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cancel all pending downloads
|
// Cancel all pending downloads
|
||||||
|
|||||||
Reference in New Issue
Block a user