alexta69 / metube

Self-hosted YouTube downloader (web UI for youtube-dl / yt-dlp)
GNU Affero General Public License v3.0
6.89k stars 434 forks source link

How to set user-agent & Pass http_headers in YTDL_OPTIONS #160

Open amjiddader opened 2 years ago

amjiddader commented 2 years ago

Hi,

1. User-Agent

how to set custom user-agent

I notice that user-agent if passed from YTDL_OPTIONS if we set.
Could not understand how to set new user-agent (This does not work)

On some videos user_agent is required and when i try them in CLI as yt-dlp --user-agent "Mozilla/5" https://vim.........m3u8 it works very well and downloads videos. In metube i am getting 400 error ( Link only opens if user-agent is set to AppleWebKit/603.1.30 (KHTML, like Gecko)

2. http_headers .

how to pass http_headers options?

If i ass http_headers in YTDL_OPTIONS i get error (server error popup) error log pasted at bottom of file ERROR_1 - 'YTDL_OPTIONS={"user_agent":"AppleWebKit/603.1.30 (KHTML, like Gecko)","http_headers":"user-agent Mozilla"}' Also for http_headers i used a file that contains headers 1 per line ( does not work)

3 Use multiple connections to download?

yt-dlp supports downloading over multiple connections

i have 10GBPS dedi server and to download some 4K files it takes about 2-5 minutes ( speed remains approx 30Mbps) While if download same stuff from yt-dlp cli with --concurrent-fragments 16 speed shoots to 300Mbps ( i know using multiple connections is an bad idea but i download a very few videos from youtube so i dont care if my server gets blocked) i tried concurrent_fragment_downloads but it never worked for me..

( sorry for my bad engush and i am not good in posting pretty message)


ERROR_1 metube | INFO:ytdl:adding https://www.youtube.com/watch?v=NhuBsXZXiCc metube | ERROR:aiohttp.server:Error handling request metube | Traceback (most recent call last): metube | File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request metube | resp = await request_handler(request) metube | File "/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py", line 504, in _handle metube | resp = await handler(request) metube | File "app/main.py", line 83, in add metube | status = await dqueue.add(url, quality, format) metube | File "/app/app/ytdl.py", line 253, in add metube | entry = await asyncio.get_running_loop().run_in_executor(None, self.extract_info, url) metube | File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run metube | result = self.fn(*self.args, **self.kwargs) metube | File "/app/app/ytdl.py", line 203, in __extract_info metube | return yt_dlp.YoutubeDL(params={ metube | File "/usr/local/lib/python3.8/site-packages/yt_dlp/YoutubeDL.py", line 689, in init__ metube | self.params['http_headers'] = merge_headers(std_headers, self.params.get('http_headers', {})) metube | File "/usr/local/lib/python3.8/site-packages/yt_dlp/utils.py", line 5596, in merge_headers metube | return {k.title(): v for k, v in itertools.chain.from_iterable(map(dict.items, dicts))} metube | File "/usr/local/lib/python3.8/site-packages/yt_dlp/utils.py", line 5596, in metube | return {k.title(): v for k, v in itertools.chain.from_iterable(map(dict.items, dicts))} metube | TypeError: descriptor 'items' for 'dict' objects doesn't apply to a 'str' object

alexta69 commented 2 years ago

Hi @amjiddader , You can see the options that you can pass to YTDL_OPTIONS here: https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/YoutubeDL.py#L176 (the link also appears in the README). I don't see there a way to set the user agent, unfortunately. HTTP headers, as per the documentation, are passed as a dictionary: "http_headers": {"Header-Name":"Value"} . (Never tried but that's what the doc says.) Not sure what's the deal with concurrent_fragment_downloads either...

amjiddader commented 2 years ago

Thanks ..

"http_headers": {"Header-Name":"Value"} . never worked for me....

I have now cloned the repo and will make changes -- by adding default configuration file inside docker and use config by default. Hope it will get UA ..

Lets leave this open 👐 Hope someone will come with an solution.