From 7fb2e6d8d982c3708e669c596b8ebfe48be3ff08 Mon Sep 17 00:00:00 2001 From: wukko Date: Fri, 7 Jun 2024 21:46:45 +0600 Subject: [PATCH] youtube: proper age & sign in limit errors --- src/localization/languages/en.json | 6 ++++-- src/localization/languages/ru.json | 3 ++- src/modules/processing/services/youtube.js | 13 ++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/localization/languages/en.json b/src/localization/languages/en.json index e2f26c5e..fc4d7f80 100644 --- a/src/localization/languages/en.json +++ b/src/localization/languages/en.json @@ -100,7 +100,7 @@ "FollowSupport": "keep in touch with cobalt for news, support, and more:", "SourceCode": "explore source code, report issues, star or fork the repo:", "PrivacyPolicy": "cobalt's privacy policy is simple: no data about you is ever collected or stored. zero, zilch, nada, nothing.\nwhat you download is solely your business, not mine or anyone else's.\n\nif your download requires rendering, then data about requested content is encrypted and temporarily stored in server's RAM. it's necessary for this feature to function.\n\nencrypted data is stored for 90 seconds and then permanently removed.\n\nstored data is only possible to decrypt with unique encryption keys from your download link. furthermore, the official cobalt codebase doesn't provide a way to read temporarily stored data outside of processing functions.\n\nyou can check cobalt's source code yourself and see that everything is as stated.", - "ErrorYTUnavailable": "this youtube video is unavailable. it could be age or region restricted. try another one!", + "ErrorYTUnavailable": "this youtube video is unavailable. it could be visibility or region restricted. try another one!", "ErrorYTTryOtherCodec": "i couldn't find anything to download with your settings. try another codec or quality in settings!", "SettingsCodecSubtitle": "youtube codec", "SettingsCodecDescription": "h264: best support across apps/platforms, average detail level. max quality is 1080p.\nav1: best quality, small file size, most detail. supports 8k & HDR.\nvp9: same quality as av1, but file is x2 bigger. supports 4k & HDR.\n\npick h264 if you want best compatibility.\npick av1 if you want best quality and efficiency.", @@ -156,6 +156,8 @@ "SettingsYoutubeDub": "use browser language", "SettingsYoutubeDubDescription": "uses your browser's default language for youtube dubbed audio tracks. works even if cobalt ui isn't translated to your language.", "ErrorInvalidContentType": "invalid content type header", - "UpdateOneMillion": "1 million users and blazing speed" + "UpdateOneMillion": "1 million users and blazing speed", + "ErrorYTAgeRestrict": "this youtube video is age-restricted, so i can't see it. try another one!", + "ErrorYTLogin": "couldn't get this youtube video because it requires sign in.\n\nthis limitation is an a/b test done by google to seemingly stop scraping, coincidentally affecting all 3rd party tools and even their own clients.\n\nyou can track the issue on github." } } diff --git a/src/localization/languages/ru.json b/src/localization/languages/ru.json index e50725ec..6487e531 100644 --- a/src/localization/languages/ru.json +++ b/src/localization/languages/ru.json @@ -157,6 +157,7 @@ "SettingsTikTokH265Description": "скачивает видео с tiktok в 1080p и h265/hevc, когда это возможно.", "SettingsYoutubeDub": "использовать язык браузера", "SettingsYoutubeDubDescription": "использует главный язык браузера для аудиодорожек на youtube. работает даже если кобальт не переведён в твой язык.", - "UpdateOneMillion": "миллион и невероятная скорость" + "UpdateOneMillion": "миллион и невероятная скорость", + "ErrorYTAgeRestrict": "это видео ограничено по возрасту, поэтому я не могу его скачать. попробуй другое!" } } diff --git a/src/modules/processing/services/youtube.js b/src/modules/processing/services/youtube.js index 558fe691..39a94f3a 100644 --- a/src/modules/processing/services/youtube.js +++ b/src/modules/processing/services/youtube.js @@ -73,7 +73,18 @@ export default async function(o) { if (!info) return { error: 'ErrorCantConnectToServiceAPI' }; - if (info.playability_status.status !== 'OK') return { error: 'ErrorYTUnavailable' }; + const playability = info.playability_status; + + if (playability.status === 'LOGIN_REQUIRED') { + if (playability.reason.endsWith('bot')) { + return { error: 'ErrorYTLogin' } + } + if (playability.reason.endsWith('age')) { + return { error: 'ErrorYTAgeRestrict' } + } + } + + if (playability.status !== 'OK') return { error: 'ErrorYTUnavailable' }; if (info.basic_info.is_live) return { error: 'ErrorLiveVideo' }; // return a critical error if returned video is "Video Not Available"