Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR 500 - when using impersonate yt-dlp works directly but not via metube #559

Open
admapop opened this issue Dec 27, 2024 · 10 comments
Open

Comments

@admapop
Copy link
Contributor

admapop commented Dec 27, 2024

YTDL_OPTIONS={"cookiefile":"/cookies/cookies.txt","verbose":"true","impersonate":"chrome"}

If I enter the docker container and execute yt-dlp directly with the cookiefile and impersonate, the download works.

When I try via the UI I get

INFO:ytdl:adding https://www.udemy.com/course/complete-react-developer-zero-to-mastery/learn/lecture/15090998#overview: quality='best' format='any' already=None folder=None custom_name_prefix='' playlist_strict_mode=False playlist_item_limit=0
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8 (No ANSI), error utf-8 (No ANSI), screen utf-8 (No ANSI)
[debug] yt-dlp version [email protected] from yt-dlp/yt-dlp [65cf46cdd] (pip) API
[debug] params: {'quiet': True, 'no_color': True, 'extract_flat': True, 'ignore_no_formats_error': True, 'noplaylist': False, 'paths': {'home': '/downloads', 'temp': '/downloads'}, 'cookiefile': '/cookies/cookies.txt', 'verbose': 'true', 'impersonate': 'chrome', 'color': 'no_color', 'compat_opts': set(), 'http_headers': {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'en-us,en;q=0.5', 'Sec-Fetch-Mode': 'navigate'}}
[debug] Python 3.11.11 (CPython aarch64 64bit) - Linux-6.8.0-1013-oracle-aarch64-with (OpenSSL 3.3.2 3 Sep 2024)
[debug] exe versions: ffmpeg 6.1.2 (setts), ffprobe 6.1.2
[debug] Optional libraries: Cryptodome-3.21.0, brotli-1.1.0, certifi-2024.08.30, curl_cffi-0.7.1, mutagen-1.47.0, requests-2.32.3, sqlite3-3.47.1, urllib3-2.2.3, websockets-13.1
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests, websockets, curl_cffi
ERROR:aiohttp.server:Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 477, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 559, in _handle
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/app/app/main.py", line 146, in add
    status = await dqueue.add(url, quality, format, folder, custom_name_prefix, playlist_strict_mode, playlist_item_limit, auto_start)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/app/ytdl.py", line 334, in add
    entry = await asyncio.get_running_loop().run_in_executor(None, self.__extract_info, url, playlist_strict_mode)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/app/ytdl.py", line 223, in __extract_info
    return yt_dlp.YoutubeDL(params={
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/yt_dlp/YoutubeDL.py", line 742, in __init__
    if not self._impersonate_target_available(impersonate_target):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/yt_dlp/YoutubeDL.py", line 4146, in _impersonate_target_available
    return any(
           ^^^^
  File "/usr/local/lib/python3.11/site-packages/yt_dlp/YoutubeDL.py", line 4147, in <genexpr>
    rh.is_supported_target(target)
  File "/usr/local/lib/python3.11/site-packages/yt_dlp/networking/impersonate.py", line 119, in is_supported_target
    assert isinstance(target, ImpersonateTarget)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
INFO:aiohttp.access:10.0.7.1 [27/Dec/2024:11:50:53 +0000] "POST /add HTTP/1.1" 500 346 "https://MYDOMAIN/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
INFO:ytdl:adding https://www.udemy.com/course/complete-react-developer-zero-to-mastery/learn/lecture/15090998#overview: quality='best' format='mp4' already=None folder=None custom_name_prefix='' playlist_strict_mode=False playlist_item_limit=0
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8 (No ANSI), error utf-8 (No ANSI), screen utf-8 (No ANSI)
[debug] yt-dlp version [email protected] from yt-dlp/yt-dlp [65cf46cdd] (pip) API
[debug] params: {'quiet': True, 'no_color': True, 'extract_flat': True, 'ignore_no_formats_error': True, 'noplaylist': False, 'paths': {'home': '/downloads', 'temp': '/downloads'}, 'cookiefile': '/cookies/cookies.txt', 'verbose': 'true', 'impersonate': 'safari', 'color': 'no_color', 'compat_opts': set(), 'http_headers': {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'en-us,en;q=0.5', 'Sec-Fetch-Mode': 'navigate'}}
[debug] Python 3.11.11 (CPython aarch64 64bit) - Linux-6.8.0-1013-oracle-aarch64-with (OpenSSL 3.3.2 3 Sep 2024)
[debug] exe versions: ffmpeg 6.1.2 (setts), ffprobe 6.1.2
[debug] Optional libraries: Cryptodome-3.21.0, brotli-1.1.0, certifi-2024.08.30, curl_cffi-0.7.1, mutagen-1.47.0, requests-2.32.3, sqlite3-3.47.1, urllib3-2.2.3, websockets-13.1
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests, websockets, curl_cffi
ERROR:aiohttp.server:Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 477, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 559, in _handle
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/app/app/main.py", line 146, in add
    status = await dqueue.add(url, quality, format, folder, custom_name_prefix, playlist_strict_mode, playlist_item_limit, auto_start)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/app/ytdl.py", line 334, in add
    entry = await asyncio.get_running_loop().run_in_executor(None, self.__extract_info, url, playlist_strict_mode)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/app/ytdl.py", line 223, in __extract_info
    return yt_dlp.YoutubeDL(params={
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/yt_dlp/YoutubeDL.py", line 742, in __init__
    if not self._impersonate_target_available(impersonate_target):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/yt_dlp/YoutubeDL.py", line 4146, in _impersonate_target_available
    return any(
           ^^^^
  File "/usr/local/lib/python3.11/site-packages/yt_dlp/YoutubeDL.py", line 4147, in <genexpr>
    rh.is_supported_target(target)
  File "/usr/local/lib/python3.11/site-packages/yt_dlp/networking/impersonate.py", line 119, in is_supported_target
    assert isinstance(target, ImpersonateTarget)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
INFO:aiohttp.access:10.0.7.1 [27/Dec/2024:11:50:57 +0000] "POST /add HTTP/1.1" 500 346 "https://MYDOMAIN/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
@PikuZheng
Copy link
Contributor

Have you inspected into the container and installed the chrome component?

@admapop
Copy link
Contributor Author

admapop commented Dec 27, 2024

@PikuZheng how do you mean?

I've opened a sh in the container and was able to use yt-dlp directly with impersonate chrome, but didn't do much else.

I also have a custom dockerfile to install some dependencies

@PikuZheng
Copy link
Contributor

[debug] yt-dlp version [email protected] from yt-dlp/yt-dlp [65cf46cdd] (pip) API
[debug] params: {'quiet': True, 'no_color': True, 'extract_flat': True, 'ignore_no_formats_error': True, 'noplaylist': False, 'paths': {'home': '/downloads', 'temp': '/downloads'}, 'cookiefile': '/cookies/cookies.txt', 'verbose': 'true', 'impersonate': 'chrome', 'color': 'no_color', 'compat_opts': set(), 'http_headers': {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8', 'Accept-Language': 'en-us,en;q=0.5', 'Sec-Fetch-Mode': 'navigate'}}
[debug] Python 3.11.11 (CPython aarch64 64bit) - Linux-6.8.0-1013-oracle-aarch64-with (OpenSSL 3.3.2 3 Sep 2024)
[debug] exe versions: ffmpeg 6.1.2 (setts), ffprobe 6.1.2
[debug] Optional libraries: Cryptodome-3.21.0, brotli-1.1.0, certifi-2024.08.30, curl_cffi-0.7.1, mutagen-1.47.0, requests-2.32.3, sqlite3-3.47.1, urllib3-2.2.3, websockets-13.1
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests, websockets, curl_cffi

There is no impersonate named chrome, so I think something is missing in the runtime environment.
On the other hand, if the command line works fine in the same environment but the embedded one doesn't, it may be because the ytdl_options are incorrect. Can you write the command line that works properly so that we can determine the issue?

@admapop
Copy link
Contributor Author

admapop commented Dec 28, 2024

[debug] yt-dlp version [email protected] from yt-dlp/yt-dlp [65cf46cdd] (pip) API
[debug] params: {'quiet': True, 'no_color': True, 'extract_flat': True, 'ignore_no_formats_error': True, 'noplaylist': False, 'paths': {'home': '/downloads', 'temp': '/downloads'}, 'cookiefile': '/cookies/cookies.txt', 'verbose': 'true', 'impersonate': 'chrome', 'color': 'no_color', 'compat_opts': set(), 'http_headers': {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8', 'Accept-Language': 'en-us,en;q=0.5', 'Sec-Fetch-Mode': 'navigate'}}
[debug] Python 3.11.11 (CPython aarch64 64bit) - Linux-6.8.0-1013-oracle-aarch64-with (OpenSSL 3.3.2 3 Sep 2024)
[debug] exe versions: ffmpeg 6.1.2 (setts), ffprobe 6.1.2
[debug] Optional libraries: Cryptodome-3.21.0, brotli-1.1.0, certifi-2024.08.30, curl_cffi-0.7.1, mutagen-1.47.0, requests-2.32.3, sqlite3-3.47.1, urllib3-2.2.3, websockets-13.1
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests, websockets, curl_cffi

There is no impersonate named chrome, so I think something is missing in the runtime environment. On the other hand, if the command line works fine in the same environment but the embedded one doesn't, it may be because the ytdl_options are incorrect. Can you write the command line that works properly so that we can determine the issue?

You might be right about chrome not being right, i just saw in the code that there's a quick mapping between chrome and chrome-110.

This is the command I use that works

yt-dlp https://www.udemy.com/course/complete-react-developer-zero-to-mastery/learn/lecture/14754858#overview --cookies /cookies/cookies.txt --impersonate="chrome-110"

My YTDL options are like this

YTDL_OPTIONS={"cookiefile":"/cookies/cookies.txt","verbose":"true","impersonate":"chrome"}

And loaded in the docker compose via env var

    environment:
      - SERVICE_FQDN_METUBE_8081
      - UID=1000
      - GID=1000
      - YTDL_OPTIONS

@PikuZheng
Copy link
Contributor

YTDL_OPTIONS={"cookiefile":"/cookies/cookies.txt","verbose":"true","impersonate":"chrome"}

according to https://github.com/yt-dlp/yt-dlp/blob/0b6b7742c2e7f2a1fcb0b54ef3dd484bab404b3f/yt_dlp/YoutubeDL.py#L422
impersonate should be an ImpersonateTarget object. metube processes ytdl_options as json, which does not support this

or you need to modify YoutubeDL.py so that json is converted to class object

@admapop
Copy link
Contributor Author

admapop commented Dec 28, 2024

YTDL_OPTIONS={"cookiefile":"/cookies/cookies.txt","verbose":"true","impersonate":"chrome"}

according to https://github.com/yt-dlp/yt-dlp/blob/0b6b7742c2e7f2a1fcb0b54ef3dd484bab404b3f/yt_dlp/YoutubeDL.py#L422 impersonate should be an ImpersonateTarget object. metube processes ytdl_options as json, which does not support this

or you need to modify YoutubeDL.py so that json is converted to class object

Good point. I made a quick PR to create the ImpersonateTarget object if the impersonate property exists

#560

@PikuZheng
Copy link
Contributor

nice job

@PikuZheng
Copy link
Contributor

Depending on your pr, should ytdl_options be written as "impersonate": "chrome-110:windows-10" ?

@admapop
Copy link
Contributor Author

admapop commented Dec 28, 2024

Depending on your pr, should ytdl_options be written as "impersonate": "chrome-110:windows-10" ?

I'm not sure? When running the command directly I can get away with using chrome-110 without specifying OS.

@PikuZheng
Copy link
Contributor

What I tried

YTDL_OPTIONS={ 
  "impersonate": {
    "client": "chrome",
    "version": "110",
    "os": "windows",
    "os_version": "10"
  }
}

main.py

from yt_dlp.networking.impersonate import ImpersonateTarget
class Config:
    def __init__(self):
        ................
        if impersonate_data := self.YTDL_OPTIONS.get("impersonate"):
            self.YTDL_OPTIONS["impersonate"] = ImpersonateTarget(**impersonate_data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants