Pass in user session for nndownload

This commit is contained in:
MMaker 2025-02-27 07:43:10 -05:00
parent 1ce10dfae4
commit fe5c547055
Signed by: mmaker
GPG Key ID: CCE79B8FEDA40FB2

10
app.py
View File

@ -32,9 +32,11 @@ CACHE_SIZE_LIMIT = 100 * 1024 * 1024 # 100 MB
cache = None if os.environ.get('NICONICOGAY_DISABLE_CACHE', '') != '' else Cache("disk_cache", size_limit=CACHE_SIZE_LIMIT)
user_session = None
cookie_jar = http.cookiejar.MozillaCookieJar('cookies.txt')
try:
cookie_jar.load(ignore_discard=True, ignore_expires=True)
user_session = next((cookie.value for cookie in cookie_jar if cookie.name == 'user_session'), None)
except FileNotFoundError:
logger.warning("cookies.txt not found, starting with empty cookie jar")
@ -79,13 +81,17 @@ def download_and_upload_video(video_id, url, video_quality):
try:
logger.info(f"Starting download for video ID: {video_id}")
nndownload.execute(
nndownload_args = [
"--no-login",
"--user-agent", "Googlebot/2.1",
"--video-quality", video_quality,
"--output-path", temp_path,
url
)
]
if user_session:
nndownload_args += ["--session-cookie", user_session]
nndownload_args = nndownload_args[1:]
nndownload.execute(*nndownload_args)
if os.path.exists(temp_path) and s3_client:
logger.info(f"Downloaded video {video_id}, uploading to CDN")