handle cookiejar.LoadError dont import invalid cookie

This commit is contained in:
simon 2022-06-15 10:39:48 +07:00
parent 09a94d0df5
commit 2ad093a9a8
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 31 additions and 7 deletions

View File

@ -5,6 +5,7 @@ functionality:
"""
import os
from http import cookiejar
from io import StringIO
import yt_dlp
@ -54,9 +55,12 @@ class YtWrap:
"""make extract request"""
try:
response = yt_dlp.YoutubeDL(self.obs).extract_info(url)
except cookiejar.LoadError:
print("cookie file is invalid")
return False
except (yt_dlp.utils.ExtractorError, yt_dlp.utils.DownloadError):
print(f"{url}: failed to get info from youtube")
response = False
return False
return response

View File

@ -829,18 +829,38 @@ class SettingsView(View):
sleep(1)
return redirect("settings", permanent=True)
@staticmethod
def post_process_updated(updated, config):
def post_process_updated(self, updated, config):
"""apply changes for config"""
if not updated:
return
for config_value, updated_value in updated:
if config_value == "cookie_import":
if updated_value:
CookieHandler(config).import_cookie()
else:
CookieHandler(config).revoke()
self.process_cookie(config, updated_value)
@staticmethod
def process_cookie(config, updated_value):
"""import and validate cookie"""
handler = CookieHandler(config)
if updated_value:
handler.import_cookie()
valid = handler.validate()
if not valid:
RedisArchivist().set_message(
"config", False, path=".downloads.cookie_import"
)
handler.revoke()
message = {
"status": "message:setting",
"level": "error",
"title": "Cookie import failed",
"message": "",
}
RedisArchivist().set_message(
"message:setting", message=message
)
else:
handler.revoke()
def progress(request):