mirror of
https://github.com/tubearchivist/tubearchivist.git
synced 2024-12-22 09:50:12 +00:00
handle cookiejar.LoadError dont import invalid cookie
This commit is contained in:
parent
09a94d0df5
commit
2ad093a9a8
@ -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
|
||||
|
||||
|
@ -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":
|
||||
self.process_cookie(config, updated_value)
|
||||
|
||||
@staticmethod
|
||||
def process_cookie(config, updated_value):
|
||||
"""import and validate cookie"""
|
||||
handler = CookieHandler(config)
|
||||
if updated_value:
|
||||
CookieHandler(config).import_cookie()
|
||||
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:
|
||||
CookieHandler(config).revoke()
|
||||
handler.revoke()
|
||||
|
||||
|
||||
def progress(request):
|
||||
|
Loading…
Reference in New Issue
Block a user