tartube icon indicating copy to clipboard operation
tartube copied to clipboard

Code location

Open ceonelson opened this issue 3 years ago • 5 comments
trafficstars

Could you let me know where in the code the "download option" command line is generated?

For example, I have download option 1080p in channel test. Where in the code are those combined to generate the command line that is used to download it?

Thanks Axcore!

ceonelson avatar May 16 '22 09:05 ceonelson

It's a little complicated because most of this code is inherited from youtube-dl-gui.

First take a look at options.py. There we have OptionsManager, which is a collection of download options. This collection is what you see when you click Edit > General download options..., for example.

Then we have OptionsParser. This is created at the start of every download. It converts Tartube's internal data (e.g. write_subs) into a list of actual yt-dlp download options (e.g. --write-sub). It also provides default values for each download option, when required.

So, the first step is to call OptionsParser.parse(). This returns a list of yt-dlp download options. However, it is an incomplete list, because some yt-dlp download options are handled separately.

The second step is to call utils.generate_ytdl_system_cmd(), passing the incomplete list as an argument.

This function adds the final parts of the system command - for example, if we are checking rather than downloading, it adds --dump-json. It also adds the binary, for example youtube-dl or yt-dlp or /home/user/yt-dlp or whatever.

axcore avatar May 16 '22 10:05 axcore

For example, I have download option 1080p in channel test. Where in the code are those combined to generate the command line that is used to download it?

Code in downloads.py decides which set of download options (OptionsManager) applies to the URL to be downloaded. Then it calls the two functions described above.

Specifically, each URL to be downloaded has its own DownloadItem. The DownloadItem is created in a call to DownloadList.create_item(). That function calls utils.get_options_manager() to decide which download options apply to which DownloadItem.

axcore avatar May 16 '22 10:05 axcore

Going through the code more it looks like this is where the output string is generated, either putting in the full path to the file or using the --paths folders specified in download options, is that right?

https://github.com/axcore/tartube/blob/f4d2927cd2fa4fab9a39209889856597fdf9de1e/tartube/options.py#L1716

ceonelson avatar May 18 '22 13:05 ceonelson

Sorry, I forgot this conversation was in progress. Feel free to ping me continuously if I forget again,

Going through the code more it looks like this is where the output string is generated, either putting in the full path to the file or using the --paths folders specified in download options, is that right?

Ok, I have been examining the code and discovered that the internal value save_path_list doesn't actually do anything; that might be the source of your confusion, because comments throughout options.py say something different.

(Before v2.3.228 there was an intermediate stage; the current version of .build_paths() dispenses with that intermediate stage, and adds --output and --paths to the system command directly.)

I've updated the code and comments.

axcore avatar May 30 '22 10:05 axcore

The updated code/comments are in v2.4.065.

axcore avatar May 31 '22 15:05 axcore

Closed for inactivity

axcore avatar Nov 25 '22 06:11 axcore