Skip to content

Commit

Permalink
7.7.5: throw a critical error when youtube api returns a stub
Browse files Browse the repository at this point in the history
merge pull request #283 from wukko/detect-youtube-stub
  • Loading branch information
wukko authored Dec 25, 2023
2 parents 0014c8b + a4349b4 commit 64790b9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cobalt",
"description": "save what you love",
"version": "7.7.4",
"version": "7.7.5",
"author": "wukko",
"exports": "./src/cobalt.js",
"type": "module",
Expand Down
12 changes: 9 additions & 3 deletions src/modules/processing/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,15 @@ export default async function(host, patternMatch, url, lang, obj) {
if (r.isAudioOnly) isAudioOnly = true;
let isAudioMuted = isAudioOnly ? false : obj.isAudioMuted;

if (r.error) return apiJSON(0, {
t: Array.isArray(r.error) ? loc(lang, r.error[0], r.error[1]) : loc(lang, r.error)
})
if (r.error && r.critical)
return apiJSON(6, { t: loc(lang, r.error) })

if (r.error)
return apiJSON(0, {
t: Array.isArray(r.error)
? loc(lang, r.error[0], r.error[1])
: loc(lang, r.error)
})

return matchActionDecider(r, host, obj.aFormat, isAudioOnly, lang, isAudioMuted, disableMetadata, obj.filenamePattern)
} catch (e) {
Expand Down
6 changes: 6 additions & 0 deletions src/modules/processing/services/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ export default async function(o) {
youtubeDubName: isDubbed ? o.dubLang : false
}

if (filenameAttributes.title === "Video Not Available" && filenameAttributes.author === "YouTube Viewers")
return {
error: 'ErrorCantConnectToServiceAPI',
critical: true
}

if (hasAudio && o.isAudioOnly) return {
type: "render",
isAudioOnly: true,
Expand Down
4 changes: 3 additions & 1 deletion src/modules/sub/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ export function apiJSON(type, obj) {
break;
}
return { status: 200, body: { status: "picker", pickerType: pickerType, picker: obj.picker, audio: audio } };
case 6: // critical error, action should be taken by balancer/other server software
return { status: 500, body: { status: "error", text: obj.t, critical: true } };
default:
return { status: 400, body: { status: "error", text: "Bad Request" } };
}
} catch (e) {
return { status: 500, body: { status: "error", text: "Internal Server Error" } };
return { status: 500, body: { status: "error", text: "Internal Server Error", critical: true } };
}
}
export function metadataManager(obj) {
Expand Down

0 comments on commit 64790b9

Please sign in to comment.