• When I use this line

    ./download_youtube.sh https://www.youtube.com/watch?v=T1n5gXIPyws 00:00:25 00:00:42 intro_test.mp4

    in my macOS terminal to start your script, then I get the error message

    date: illegal time format
    usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
                [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]

    What's wrong?

    Edited by Alexander Brehm
  • To support macOS:

    change: date "+%s" -d "UTC 01/01/1970 $XX" to: date -j -u -f "%m/%d/%Y %T" "01/01/1970 $XX" "+%s"

    change: date -u "+%T" -d @$XX to: date -u -r $XX "+%T"

  • Thank you very much for helping. Unfortunately, I didn't get it to work … I am not savvy in bash scripts, so I was not quite sure how to alter the code according to your posting. I attached the altered, not working code.


  • modified based on soflare's comment - macOS version below:

    #taken from https://unix.stackexchange.com/a/388148/48971
    if [ $# -lt 4 ]; then
            echo "Usage: $0 <youtube's URL> <HH:mm:ss.milisecs from time> <HH:mm:ss.milisecs to time> <output_file_name>"
            echo "e.g.:"
            echo "$0 https://www.youtube.com/watch?v=T1n5gXIPyws 00:00:25 00:00:42 intro.mp4"
            exit 1
    echo "processing..."
    from=$(date -j -u -f "%m/%d/%Y %T" "01/01/1970 $2" "+%s")
    to=$(date -j -u -f "%m/%d/%Y %T" "01/01/1970 $3" "+%s")
    from_pre=$(($from - 30))
    if [ $from_pre -lt 0 ]
    from_pre_command_print=$(date -u -r $from_pre "+%T")
    from_command_print=$(date -u -r $(($from - $from_pre)) "+%T" )$(grep -o "\..*" <<< $2)
    to_command_print=$(date -u -r  $(($to - $from_pre)) "+%T")$(grep -o "\..*" <<< $3)
    command="ffmpeg "
    for uri in $(youtube-dl -g $1)
            command+="-ss $from_pre_command_print -i $uri "
    command+="-ss $from_command_print -to $to_command_print $4"
    echo "downloading with the following command:"
    echo "$command" 
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment