3

It was recommended to me by a user on here that I make a post asking how I can combine several youtube-dl downloads into on single script to be run. I'm downloading lots of youtube channels and currently have every channel in a different .sh file that I can run, but was told I can just combine them all into one file. An example of my scripts is:

./youtube-dl ytuser:user -ciw -o "/path/to/directory/%(upload_date)s-% \
(title)s.%(ext)s" --download-archive "/path/to/directory/downloaded.txt" \
--add-metadata --write-info-json --write-description --write-thumbnail \
--write-annotations --embed-subs -f \
"bestvideo[height<=720]+bestaudio/best[height<=720]" --merge-output-format \
"mkv"

So I have that exact script for every different channel, except of course modified so that each channel has it's own directory. Since I have so many I wanted to put them all in .sh files and then have a script to run all the .sh files, but again was told that this method was way over complicated and that there was a way to put all of the different command lines into a single script to be run.

Clarification: So the /path/to/directory/ is going to be different for every channel, usually I don't need a URL since that is taken care of by the ytuser:*user* section of the code. If there is a URL it will just be added at the very end of the code and the ytuser:*user* will be deleted.

Currently I have lots of different .sh files that all have code specific for one channel, so for example running h3h3Productions.sh will open a terminal that downloads the channel "h3h3Productions" from YouTube into a directory like /youtube-dl/videos/vlogs/h3h3Productions/ and running WarLeaks.sh will download the YouTube channel "WarLeaks" into the directory youtube-dl/videos/footage/WarLeaks/.

So the code in each .sh file is relatively the same, but the /path/to/directory/ and /path/to/directory/.downloaded.txt, for the --archive-download code, is different for all of them and the ytuser:*user* is also different for every channel.

What I want to be able to do is just have one .sh file that has the code for several different channels in it. That way, instead of running every .sh file individually I can just have one .sh file that when run will activate all of the downloads contained inside, since it will have the code for eight or ten different channels inside of it.

I hope that helps clarify if not please let me know.

7
  • I'm not sure what your question is or what you want to achieve precisely. Could you please edit your question to include an explicit question and an example? Thanks. May 2, 2017 at 1:53
  • Yes, please edit and tell us what changes between each script and what needs to be the same. Is /path/to/directory different for every URL? Where is the URL, anyway? Shouldn't you be downloading something?
    – terdon
    May 2, 2017 at 9:43
  • I think the most simple solution here is to have an additional script for each group of Youtube channels that does little more than to invoke the individual downloader scripts. I'll write a proper answer if someone notifies me when this question is reopened. May 2, 2017 at 21:37
  • @DavidFoerster I VTR. What do you think about simply using a text file to contain all the ytuser:*user* and target names and using a while loop to read them in and use them as needed to build the command line with the target being a suffix to the path? I don't know how critical the differences are between vlog and footage as mentioned in the question, but the same approach could be taken for both by perhaps having separate lists for each type. Perhaps @Bencc can clarify whether the aforementioned seperation is needed or if /blah/blah/videos/target would suffice
    – Elder Geek
    May 2, 2017 at 21:47
  • 1
    @ElderGeek: Yes, that is my other idea. I'll describe both in my answer. May 2, 2017 at 21:57

1 Answer 1

1

This screams for a function, how 'bout:

#! /bin/bash

yt(){
./youtube-dl "ytuser:"$1 -ciw -o $2"/%(upload_date)s-%(title)s.%(ext)s" --download-archive $2"/downloaded.txt" --add-metadata --write-info-json --write-description --write-thumbnail --write-annotations --embed-subs -f "bestvideo[height<=720]+bestaudio/best[height<=720]" --merge-output-format "mkv"
}

yt "user" "/path/to/directory/"
yt "differentuser" "/path/to/other/directory/"
…

The steps to achieve this are simple, just determine what parts of the command really change, substitute it by variables, write a function and call it as needed. There may be a better solution, but we'll need some of your precise scripts to find it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .