ydls icon indicating copy to clipboard operation
ydls copied to clipboard

External Downloader

Open arg0nx opened this issue 3 years ago • 21 comments

Hello,

Any possibility to add option for external downloader or add some arguments? eg. "--external-downloader aria2c" and "--http-chunk-size 10M"

On some files I get very slow downloads (same on ydls and youtube-dl directly) but when using external downloader or adding chunk size it goes well with youtube-dl

TY

arg0nx avatar Jun 17 '21 15:06 arg0nx

Hi, interesting, do you have an exempel URL i can test with? Not sure how youtube-dl work with streaming to stdout like ydls do and external downloader

wader avatar Jun 17 '21 17:06 wader

Direct download (YDLS downloads same speed as this)

youtube-dl` https://www.dailymotion.com/video/x8207y9
[dailymotion] Downloading Access Token
[dailymotion] x8207y9: Downloading media JSON metadata
[dailymotion] x8207y9: Downloading metadata JSON
[dailymotion] x8207y9: Downloading m3u8 information
[download] Destination: Virtual and In-person Events to Celebrate Juneteenth Around the U.S.-x8207y9.mp4
[download] 100% of 11.15MiB in 00:06

Adding chunk:

youtube-dl --http-chunk-size 10M https://www.dailymotion.com/video/x8207y9
[dailymotion] Downloading Access Token
[dailymotion] x8207y9: Downloading media JSON metadata
[dailymotion] x8207y9: Downloading metadata JSON
[dailymotion] x8207y9: Downloading m3u8 information
[download] Resuming download at byte 8387584
[download] Destination: Virtual and In-person Events to Celebrate Juneteenth Around the U.S.-x8207y9.mp4
[download] 100% of 11.15MiB in 00:00

arg0nx avatar Jun 17 '21 18:06 arg0nx

Thanks, will have a look in a few days, on vacation. If you want to experiment, what would be needed for ydls is for youtube-dl to somehow use external downloader while writing to stdout, which kind i guess might make it a bit harder to do parellell downloads

wader avatar Jun 18 '21 07:06 wader

External downloader is unneded if You can manage to make it possible to use option CHUNK SIZE

That is internal YoutubeDL command

Ty

arg0nx avatar Jun 18 '21 14:06 arg0nx

Hi again, i tried to reproduce without external downloader and only use chunk size but i get about the same speed for dailymotion. But with external downloader aria2c i get much faster speed. Unfortunately it looks like aria2c does not support streaming to stdout which would be required they way ydls works currently, to respond fast with http body and store as little as possible on disk.

There is an open issue for aria2c to support stdout https://github.com/aria2/aria2/issues/190 also found this won't fix issue for youtube-dl about streaming and aria2c https://github.com/ytdl-org/youtube-dl/issues/25345

Could the reason you saw faster download with --http-chunk-size 10M be the log line [download] Resuming download at byte 8387584? you can retry and make sure to delete the .part file to not resume.

There shouldn't in theory be any problems supporting streaming and parallell downloads just have to use a bit more disk or memory to buffer to get ordering right. I had a quick look at the other supported external downloaders but couldn't find any that seem to support it.

wader avatar Jun 20 '21 14:06 wader

Hi, want to investigate or work on this more or should i close?

wader avatar Jun 26 '21 09:06 wader

Hi, Maybe if possible to add chunk size?

This is test from 2 separate videos, so it is not resuming download

TY

youtube-dl https://www.dailymotion.com/video/x7y1b78
[dailymotion] Downloading Access Token
[dailymotion] x7y1b78: Downloading media JSON metadata
[dailymotion] x7y1b78: Downloading metadata JSON
[dailymotion] x7y1b78: Downloading m3u8 information
[download] Destination: Basic Instinct - Scene from the film-x7y1b78.mp4
[download]  47.3% of 26.37MiB at 169.92KiB/s ETA 01:23
youtube-dl --http-chunk-size 10M https://www.dailymotion.com/video/x4gmtws
[dailymotion] Downloading Access Token
[dailymotion] x4gmtws: Downloading media JSON metadata
[dailymotion] x4gmtws: Downloading metadata JSON
[dailymotion] x4gmtws: Downloading m3u8 information
[download] Destination: Bollywood's The Most Shocking Wardrobe Malfunction _ View Pic's-x4gmtws.mp4
[download] 100% of 20.50MiB in 00:04

arg0nx avatar Jun 27 '21 11:06 arg0nx

For me i see this:

https://www.dailymotion.com/video/x7y1b78 (downloads a 27651229 byte file, media bitrate 463 kb/s) no chunk size: 2MB/s at first then slows down 10M chunk size: 2MB/s at first then slows down

https://www.dailymotion.com/video/x4gmtws (downloads a 21496392 byte file, media bitrate 2138 kb/s) no chunk size: 2MB/s at first then slows down 10M chunk size: 2MB/s until done

I wonder if they do some throttling based on media bitrate etc?

wader avatar Jun 27 '21 16:06 wader

Probably some throttling with token because download from YT is getting full speed. Also I get few other sites with same issue where chunk helps a bit

arg0nx avatar Jun 27 '21 18:06 arg0nx

Do you think this would be a global option or a per request option? Also thinking this should probably be off by default? Have some fear sending range requests might affect some sites. And ideas?

wader avatar Jun 27 '21 19:06 wader

Better peer request, there is many sites this is unneeded I believe with multiple request it might get to much memory consuption or something else can go bad...

http://ydls/?format=mp4&chunk=10&url=http.....

Default disabled

arg0nx avatar Jun 27 '21 19:06 arg0nx

Initial version #208 requires https://github.com/wader/goutubedl/pull/89 you can use go module replace directive if you want to try it out.

To test:

curl -OLJ 'http://0:8080?url=https://www.dailymotion.com/video/x4gmtws&format=mp3&httpchunksize=10M'

I noticed that --http-chunk-size options is a bit misleading what it does https://github.com/ytdl-org/youtube-dl/blob/5208ae92fc3e2916cdccae45c6b9a516be3d5796/youtube_dl/downloader/http.py#L87 it also adds some randomness to the chunk size, which make a lot of sense for what the purpose is.

Also been thinking if ydls should have some kind of known sites config? maybe hard to maintain?

wader avatar Jun 28 '21 18:06 wader

Great work mate,

I don't know how much other people would use site config, I personaly don't need it. Maybe just some other usefull Youtube DL command to implement in the magic way YDLS works (post)

OR Making few own Youtube DL config with all commands I need from Youtube DL and pass file to YDLS For example:

Config1= Filetype=mp4 Chunk size 10 --user-agent UA --referer URL

Config2= Filetype=mp3

Then with YDLS Http://ydls:8080/config1/http://youtube.com Http://ydls:8080/config2/http://youtube.com

arg0nx avatar Jun 29 '21 09:06 arg0nx

Was thinking that ydls would ship (in ydls.json etc) with known-good site configurations, ex that dailymotion works and is probably faster with chunk size.

Could be something like this in ydls.json:

...
"URLConfig": {
  "https?://*.\.dailymotion\.com/.*" {
     "httpchunksize": 10M"
  }
}
...

(URL regex might be messy, could possibly look at what extractor youtube-dl choose also)

How would you like to use user-agent and referer? use own hardcoded values for some reason?

wader avatar Jun 29 '21 11:06 wader

Actually, that would be good with json, great idea...

User agend and referrer are just example commands, but for instance some videos need login with commands "-u username -p password"

So to add to json

...
"URLConfig": {
  "https?://*.\.dailymotion\.com/.*" {
     "httpchunksize": 10M"
     "Login": username"
     "Password": password"
     "UserAgent": Mozilla 5.0...."
  }
}
...

arg0nx avatar Jun 29 '21 14:06 arg0nx

But, at least for me, next what I would really much use could be different downloader. Instead youtube dl to use wget or curl?

arg0nx avatar Jun 29 '21 14:06 arg0nx

Yes good idea, i've thought about how to do login, this could be one way.

For downloader i think it should be easy to support as long as youtube-dl can do streaming using it. To support non-streaming would require some bigger changes and also would mean require more temp disk space where ydls is running, maybe also would require doing some trix to keep the connection from timing out if used thru a proxy etc.

wader avatar Jun 29 '21 15:06 wader

Hello,

Would it be possible to make it as follows: HTTP://ydls:8080/&downloader=ffmpeg&filetype=mp4&url=URLtoSTREAM

Where downloader = optional synopsis

So to use YDLS as online transcode services for videos or music with direct link, just to skip YOUTUBE DL completely

For instance one of videos from https://www.nhc.noaa.gov/video/?C=D;O=A

You can use it in ffmpeg directly but it would be good if I can use ydls to transcode it do desired format and have it on the fly without much hustle

arg0nx avatar Jun 30 '21 15:06 arg0nx

I think that should kind of already work. Quite sure if one gives youtube-dl a URL to a plain media file it will just download it. A bit wasteful that is goes thru youtube-dl but shouldnt be much

wader avatar Jul 02 '21 23:07 wader

Remembered that i should mention that because ydls streams it do tell and make ffmpeg to skip writing some seek indexes and fragment depending on conatiner format. Usually not a problem for most players but maybe good to know.

wader avatar Jul 03 '21 07:07 wader

Hey, i switched to yt-dlp some weeks ago, maybe that will make tweaks less needed?

wader avatar Dec 24 '21 18:12 wader