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?

Ƭᴇcʜιᴇ007
  • 111,883
  • 19
  • 201
  • 268
makgun
  • 347
  • 9
  • 25

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
  • 5
  • 3
    Welcome to Super User. Your post needs to be expanded. A good [answer](http://superuser.com/help/how-to-answer) includes specific instructions (not just links to them) and an explanation as to how or why the answer addresses the OPs question. Please edit your post to explain how it is a solution in this case. – I say Reinstate Monica Jun 05 '15 at 22:51
  • Yes this code is nice for using. Thanks. Also I need to ask that (Sorry for bad English) I want to make shortcut via aliases command as [link](download Bla_Bla (which is my video link) -o nameofmovie.ts) – makgun Jun 06 '15 at 07:02
  • How can I do this? Instead of long text typing just type the DOWNLOAD. – makgun Jun 06 '15 at 07:04
  • Now I tried this command but it renames the file that what I typed (like filename'date +%Y....)' not filename2015-06-01-19-53.ts It looks with %Y%M e.g – makgun Jun 06 '15 at 07:25
  • use back ticks not single quotes, which causes bash to execute that command and use that output as part of the name – jbg Jun 07 '15 at 13:46
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
  • How can i use this script? My code knowledge is bad. I just know typing code via terminal. – makgun Jun 06 '15 at 06:54
  • Save it in a text file as `something.sh` and run it from bash via `bash something.sh` or `chmod a+x something.sh` followed by `.\something.sh` to execute. – armani Jun 08 '15 at 15:58
  • Ok but how i can use this executable file to save my movie as nameofmovie*.ts? The thing i didn't understand is this. I know sh files how to executable. Thanks your reply. – makgun Jun 08 '15 at 17:27