mirror of
https://github.com/tubearchivist/tubearchivist.git
synced 2024-12-22 18:00:13 +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
|
import os
|
||||||
|
from http import cookiejar
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
import yt_dlp
|
import yt_dlp
|
||||||
@ -54,9 +55,12 @@ class YtWrap:
|
|||||||
"""make extract request"""
|
"""make extract request"""
|
||||||
try:
|
try:
|
||||||
response = yt_dlp.YoutubeDL(self.obs).extract_info(url)
|
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):
|
except (yt_dlp.utils.ExtractorError, yt_dlp.utils.DownloadError):
|
||||||
print(f"{url}: failed to get info from youtube")
|
print(f"{url}: failed to get info from youtube")
|
||||||
response = False
|
return False
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@ -829,18 +829,38 @@ class SettingsView(View):
|
|||||||
sleep(1)
|
sleep(1)
|
||||||
return redirect("settings", permanent=True)
|
return redirect("settings", permanent=True)
|
||||||
|
|
||||||
@staticmethod
|
def post_process_updated(self, updated, config):
|
||||||
def post_process_updated(updated, config):
|
|
||||||
"""apply changes for config"""
|
"""apply changes for config"""
|
||||||
if not updated:
|
if not updated:
|
||||||
return
|
return
|
||||||
|
|
||||||
for config_value, updated_value in updated:
|
for config_value, updated_value in updated:
|
||||||
if config_value == "cookie_import":
|
if config_value == "cookie_import":
|
||||||
if updated_value:
|
self.process_cookie(config, updated_value)
|
||||||
CookieHandler(config).import_cookie()
|
|
||||||
else:
|
@staticmethod
|
||||||
CookieHandler(config).revoke()
|
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):
|
def progress(request):
|
||||||
|
Loading…
Reference in New Issue
Block a user