2

I want to know how I can automate "Livestreamer".

I download movies(series) every week. The command is like this:

livestreamer "hlsvariant://http://Bla_Bla" best -o Filename.ts

I want the change Bla_Bla automatically, and change the file name as NameOfMovie*.ts, where * is the chapter of the movie.

For example if there is a file NameOfMovie1.ts it renames it as NameOfMovie2.ts.

How can I do this?

makgun
  • 357

2 Answers2

4

Instead of having to figure out which number was your last sequence, then increment it, you could add the date to the filename like this:

NameOfMovie`date +%Y%m%d-%H%M%S`.ts

Then it becomes more meaningful & its easier to understand.

jbg
  • 191
3

The following script can help you. You should not be running several copies of the script at the same time to avoid race condition.

name=somefile
if [[ -e $name.ext ]] ; then
    i=0
    while [[ -e $name-$i.ext ]] ; do
        let i++
    done
    name=$name-$i
fi
touch $name.ext
armani
  • 586
  • 2
  • 8