1

I'm sorry if a Ubuntu forum isn't the right place for this. I should say firstly that I am a beginner programmer. I know a fair bit about bash, but not much more than average. I'm currently trying to write a script that will download entire youtube channels in an orderly way, with labeled folders.

So here's my script, a work in progress.

#!/bin/bash

# script for downloading youtube channels.

youtube-dl --format best --ignore-errors --geo-bypass --no-overwrites --write-description --verbose --output "home/(myname)/Videos/Youtube/%(title)s-%(id)s.%(ext)s"

My questions are:

  1. I tested this script, but it didn't seem to work, despite outputting that it had in fact, worked. The folder I specified was empty.

  2. How can I make it accept arguments in the command line, instead of having to write it in the text file itself? I guess I would have to do something with stdin, right?

  3. Can I put the different options on different lines? I tried that and it had very odd output. I'll post it if requested.

Thanks for any help. Tips to improve this are much appreciated!

Here's the output:

[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: [u'https://www.youtube.com/watch?v=5Z0wEVxL30Q', u'--format', u'best', u'--ignore-errors', u'--geo-bypass', u'--no-overwrites', u'--write-description', u'--verbose', u'--output', u'home/daniel/Videos/Youtube/%(title)s-%(id)s.%(ext)s']
[debug] Encodings: locale UTF-8, fs UTF-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2019.09.28
[debug] Python version 2.7.17 (CPython) - Linux-5.0.0-37-generic-x86_64-with-Ubuntu-18.04-bionic
[debug] exe versions: ffmpeg 3.4.6, ffprobe 3.4.6, phantomjs 2.1.1, rtmpdump 2.4
[debug] Proxy map: {}
[youtube] 5Z0wEVxL30Q: Downloading webpage
[youtube] 5Z0wEVxL30Q: Downloading video info webpage
[youtube] {18} signature length 108, html5 player vfl22ubNH
[youtube] {22} signature length 108, html5 player vfl22ubNH
[youtube] {43} signature length 108, html5 player vfl22ubNH
[youtube] {137} signature length 104, html5 player vfl22ubNH
[youtube] {248} signature length 108, html5 player vfl22ubNH
[youtube] {136} signature length 108, html5 player vfl22ubNH
[youtube] {247} signature length 108, html5 player vfl22ubNH
[youtube] {135} signature length 108, html5 player vfl22ubNH
[youtube] {244} signature length 104, html5 player vfl22ubNH
[youtube] {397} signature length 108, html5 player vfl22ubNH
[youtube] {134} signature length 104, html5 player vfl22ubNH
[youtube] {243} signature length 108, html5 player vfl22ubNH
[youtube] {396} signature length 104, html5 player vfl22ubNH
[youtube] {133} signature length 108, html5 player vfl22ubNH
[youtube] {242} signature length 104, html5 player vfl22ubNH
[youtube] {395} signature length 108, html5 player vfl22ubNH
[youtube] {160} signature length 108, html5 player vfl22ubNH
[youtube] {278} signature length 104, html5 player vfl22ubNH
[youtube] {394} signature length 108, html5 player vfl22ubNH
[youtube] {140} signature length 108, html5 player vfl22ubNH
[youtube] {249} signature length 104, html5 player vfl22ubNH
[youtube] {250} signature length 108, html5 player vfl22ubNH
[youtube] {251} signature length 108, html5 player vfl22ubNH
[youtube] {256} signature length 104, html5 player vfl22ubNH
[youtube] {258} signature length 108, html5 player vfl22ubNH
[info] Writing video description to: home/daniel/Videos/Youtube/Skyfall - Glass Marksman Shot (1080p)-5Z0wEVxL30Q.description
[debug] Invoking downloader on u'https://r1---sn-5goeen7r.googlevideo.com/videoplayback?expire=1577358216&ei=KD8EXpPXBIrFyQWU-YywAg&ip=141.98.255.143&id=o-AKv0MWwSrx9RvyT95fq0Q_YtOhrP5TbXi6Q0sjSMgIjX&itag=22&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-5goeen7r%2Csn-5go7yne6&ms=au%2Crdu&mv=m&mvi=0&pl=24&initcwndbps=1542500&mime=video%2Fmp4&ratebypass=yes&dur=230.016&lmt=1576681868572996&mt=1577336499&fvip=1&fexp=23842630&c=WEB&txp=5535432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cratebypass%2Cdur%2Clmt&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHylml4wRAIgP-oMuqfqPY881XjbcdN6zXRrP_J9JyvEgV4IycmrZ5YCIFbDK3B6ZjlE9bidVpMUKgrGPB8gwPoT7eHsc0CwS-J0&sig=ALgxI2wwRQIhALG8pUVKSEm97ndTb_i8Vd_uqcVshLbbbfNuYoV9PBWLAiAy92m5Qqh3i0DK05AdaCbQohVT8nNtam_Pf-cYKDJRPg=='
[download] Destination: home/daniel/Videos/Youtube/Skyfall - Glass Marksman Shot (1080p)-5Z0wEVxL30Q.mp4
[download] 100% of 15.78MiB in 00:39
  • did you make the script executable? chmod +x filename . Since the script is only one bash command, please edit your question with the full output after running that command. The --verbose tag (if that is the correct usage) should provide detailed information – Nmath Dec 26 '19 at 5:25
  • It is executable. And I edited in the output. – DirtyDan77 Dec 26 '19 at 6:09
  • 1
    Your problem might be in the directory pass to the tool, you have home/, when it should /home change and lets see what happens! – George Udosen Dec 26 '19 at 7:41
0

You should pass some argument to your script
See : https://stackoverflow.com/questions/18003370/script-parameters-in-bash

An example script could look like this ytchandl.sh:

#!/bin/bash
# If no Argument found then don't proceed:exit
if [ -z "$1" ]; then exit 1; fi

ChanURL=$1
youtube-dl -f best --geo-bypass --write-description -civw \
           -o "/home/$USER/Video/Youtube/%(title)s-%(id)s.%(ext)s" \
           "$ChanURL"

Then call the script with

./ytchandl.sh https://www.youtube.com/user/ubuntudevelopers

Of course you could add more tests on the arguments to check if URL exists and so...

You may also use the embedded uploader and playlist output templates
Get more info : http://manpages.ubuntu.com/manpages/bionic/man1/youtube-dl.1.html

# Download all playlists of YouTube channel/user keeping each playlist in separate directory:
$ youtube-dl -o '%(uploader)s/%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s' https://www.youtube.com/user/ubuntudevelopers/playlists
| improve this answer | |
  • Since you changed it to: /home/$USER/ already, you can change that to $HOME/ to make it shorter. – WinEunuuchs2Unix Dec 26 '19 at 16:57
  • @WinEunuuchs2Unix - Why not. Could be ~/ too. The idea was to take over the writing of OP. As i think he forgot the starting /, i specially wrote like this for him to catch something. – cmak.fr Dec 26 '19 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.