29 lines
2.2 KiB
JavaScript
29 lines
2.2 KiB
JavaScript
/* Plain-language save failures, with the original diagnostic kept on demand. */
|
||
(function(root) {
|
||
'use strict';
|
||
function message(error) {
|
||
const raw = String(error?.message || error || '').trim();
|
||
if (!raw) return 'Could not save this video. Try Retry.';
|
||
if (/not available in your country|geo.?restricted/i.test(raw)) return 'This video is unavailable in the server’s region. It may still play on your device.';
|
||
if (/private video|members.only|join this channel|confirm your age|age.restricted/i.test(raw)) return 'YouTube requires access this server does not have to save this video.';
|
||
if (/removed by|video has been removed|copyright claim/i.test(raw)) return 'YouTube is no longer making this video available to the server.';
|
||
if (/sign in to confirm|not a bot/i.test(raw)) return 'YouTube temporarily blocked the server’s download request. Try Retry later.';
|
||
if (/video unavailable/i.test(raw)) return 'YouTube isn’t letting the server save this video. Try Retry; it may still play on YouTube.';
|
||
if (/requested format (?:is )?not available|no video formats found/i.test(raw)) return 'No downloadable version was available. Try Retry to check other download methods.';
|
||
if (/^ERROR:|^WARNING:|Traceback|yt-dlp exited|yt-dlp not found/i.test(raw)) return 'The server could not save this video. Try Retry.';
|
||
// Existing plain-language connection/quota/validation messages remain useful.
|
||
return raw.length <= 180 && !raw.includes('\n') ? raw : 'Could not save this video. Try Retry.';
|
||
}
|
||
function appendDetails(container, error) {
|
||
if (!error) return;
|
||
const doc = container.ownerDocument;
|
||
const details = doc.createElement('details'); details.className = 'download-error-details';
|
||
const summary = doc.createElement('summary'); summary.textContent = 'Technical details';
|
||
const pre = doc.createElement('pre'); pre.textContent = String(error?.message || error);
|
||
details.append(summary, pre); container.append(details);
|
||
return details;
|
||
}
|
||
const api = { message, appendDetails };
|
||
if (typeof module !== 'undefined') module.exports = api; else root.DownloadErrors = api;
|
||
})(typeof window !== 'undefined' ? window : globalThis);
|