ytdl-org / youtube-dl

Command-line program to download videos from YouTube.com and other video sites
http://ytdl-org.github.io/youtube-dl/
The Unlicense
132.31k stars 10.03k forks source link

Not able to set correct ydl_opts to download a video as mp4 with resolution height as 1080p #32909

Closed ishandutta2007 closed 3 months ago

ishandutta2007 commented 3 months ago

Checklist

Question

To download youtube videos I typically use : https://y2meta.app/en/youtube/rU8_Fg103ZQ [1080p (.mp4) full-HD] resolution. Now I am looking to replicate the same vis code. I realised "format": "bestvideo[height=1080]/best[height=1080]", errors out.

What doesnt error out is this:

        ydl_opts = {
            "format": "bestvideo[ext=mp4]+bestaudio[ext=mp4]/mp4+best[height<=720]",
            "recode-video": "mp4",
            "outtmpl": os.path.join(myvidconfig.video_path, myvidconfig.videoname,),
        }

but here I get a resolution with height mere 360p.

PS: I dont care about the audio, a mute mp4 with height = 1080p is enough for me.

EDIT: I have run with versbose mode the following and it download first fragment without issue but fails to succeeding ones.

        ydl_opts = {
            "format": "bestvideo[ext=mp4]", 
            "merge_output_format": "mp4",
            "verbose": True,
            "fragment_retries": 100,
            "outtmpl": "some/path/to/my.mp4"
            ),
        }

The warning:

[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 3 (attempt 2 of 100)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 3 (attempt 3 of 100)...

probably sites like y2meta.app use some sort of proxy setting which I need, What is it ?

dirkf commented 3 months ago

The 403 problem is #32905. Possibly format 18 (640x60 + audio) may be accessible.

If you want to get just video or combined audio+video at 1080 if available: - "(bestvideo/best)[height>=1080]/bestvideo/best"

However because of #32905, that may not be effective at present.

ishandutta2007 commented 3 months ago

@dirkf I read through the post but I still don't have clarity on how to solve it. They seem to safeguard with Cloudflare, captcha and what not . I am curious if it's so difficult how does y2meta.app guys do it?

dirkf commented 3 months ago

No, I don't know how to solve your problem either because #32905 is still open and it's not clear from your problem explanation whether that's the only problem that you're asking about. Which "They" is seeming to safeguard with [etc]?

As to your .app service, maybe they run a headless browser in their server or behind the scenes in your client device to run all the necessary JS challenges. Better ask them.

ishandutta2007 commented 3 months ago

You mean y2meta.app either use Selenium/Appium or are doing it entirely from clientside (ie my browser) ? Here is y2meta.app's tampermonkey script https://y2meta.app/extensions/chrome/helper.user.js?t=638588954439378072 They seem to be making a server call .

            var t = "https://y2meta.com/youtube/" + MaxMain.vid + "/?utm_source=chrome_addon";

Let me know if I am missing something .

ishandutta2007 commented 3 months ago

@dirkf do you know any good Selenium/Puppeteer open-source project doing the same. Given that youtube-dl is so popular I was under the impression it covers all those use-cases. y2meta.app is not the only youtube downloader site/addon, there seem to a dozen other doing it. It would be strange if there aren't any open-source equivalent of any of them ?

dirkf commented 3 months ago

The browser script just sends the YT URL to the server. Then it's up to them how to generate the video that is presumably then offered in the browser downloads.

Generally sites that people want yt-dl to handle have relied on custom video players that don't offer the rightful Save Video As... function (why yt-dl exists), and then by more or less trivial obfuscation of the player, which determined users can often reverse or bypass, or by DRM encryption of the media, which we don't address. Now that almost everyone's client is a supercomputer (by Web 1.0 standards), it's realistic for sites to make their challenges much more complex and correspondingly difficult to solve. This is why a YT video page that could use a plain HTML5 video tag instead sends ~4MB of JS.

As linked in #32905, eg, Invidious has a tool for grabbing valid poToken data from a browser and possibly (I didn't check) that data could then be injected to get valid media from YT to show in their low-bloat client.

ishandutta2007 commented 3 months ago

Generally sites that people want yt-dl to handle have relied on custom video players that don't offer the rightful Save Video As

I see. So I need custom video player too ? If so in that case yt-dl library alone isn't very useful. You referred to this one I guess: https://github.com/iv-org/youtube-trusted-session-generator . I am surprised that it isn't more popular. My hunch was end to end downloader project would be more popular that youtube-dl library. Do you know of any popular end to end project (open-source) who have integrated youtube-dl . By end to end I mean, I can simply start the server and use it like these downloader sites ?

antivirtel commented 3 months ago

@dirkf do you know any good Selenium/Puppeteer open-source project doing the same. Given that youtube-dl is so popular I was under the impression it covers all those use-cases. y2meta.app is not the only youtube downloader site/addon, there seem to a dozen other doing it. It would be strange if there aren't any open-source equivalent of any of them ?

I use this: https://github.com/FlareSolverr/FlareSolverr - with another app - would this help?

dirkf commented 3 months ago

I presume that the original question has been solved; the remaining issue of 403 on media download is continued in #32905.