0

-Skip to bold to skip the fluff -

I'm new to ubuntu, so still learning the ropes of how bash scripting goes. I've got this code I've been working on, which works great. (side question - can I optimize the countdown portion at all? Define it once, and call it in each section?). With the totem "/video/location/here.ext" command, my problem is that the video player only loads up the one video.

Actual Question: How can I make sure totem knows to automatically continue to the next video once the current one is over while using the totem "/video.ext" command in terminal?

#!/bin/bash

PS3='
So, you want to watch Elfen Lied? Choose an episode (1-14): '
options=("A Chance Encounter" "Annihilation" "Deep Feelings" "Attack" "Receipt" "Innermost Feelings" "Confrontation" "The Beginning" "Reminiscence" "Infant" "Complication" "Quagmire" "No Return" "Episode 10.5 - OVA" "Quit")
select opt in "${options[@]}"
do
    case $opt in
        "A Chance Encounter")
            echo "You chose Episode 01 - A Chance Encounter"
            sleep 1
            echo "Starting in 3..."
            sleep 1
            echo "Starting in 2..."
            sleep 1
            echo "Starting in 1..."
            sleep 1
            totem "/home/xhynk/Desktop/media/Anime/Elfen Lied/Elfen Lied - 01 - A Chance Encounter.mkv";;
        "Annihilation")
            echo "You chose Episode 02 - Annihilation"
            sleep 1
            echo "Starting in 3..."
            sleep 1
            echo "Starting in 2..."
            sleep 1
            echo "Starting in 1..."
            sleep 1
            totem "/home/xhynk/Desktop/media/Anime/Elfen Lied/Elfen Lied - 02 - Annihilation.mkv";;
        "Deep Feelings")
            echo "You chose Episode 03 - Deep Feelings"
            sleep 1
            echo "Starting in 3..."
            sleep 1
            echo "Starting in 2..."
            sleep 1
            echo "Starting in 1..."
            sleep 1
            totem "/home/xhynk/Desktop/media/Anime/Elfen Lied/Elfen Lied - 03 - Deep Feelings.mkv";;
        "Attack")
            echo "You chose Episode 04 - Attack"
            sleep 1
            echo "Starting in 3..."
            sleep 1
            echo "Starting in 2..."
            sleep 1
            echo "Starting in 1..."
            sleep 1
            totem "/home/xhynk/Desktop/media/Anime/Elfen Lied/Elfen Lied - 04 - Attack.mkv";;
        "Receipt")
            echo "You chose Episode 05 - Receipt"
            sleep 1
            echo "Starting in 3..."
            sleep 1
            echo "Starting in 2..."
            sleep 1
            echo "Starting in 1..."
            sleep 1
            totem "/home/xhynk/Desktop/media/Anime/Elfen Lied/Elfen Lied - 05 - Receipt.mkv";;
        "Innermost Feelings")
            echo "You chose Episode 06 - Innermost Feelings"
            sleep 1
            echo "Starting in 3..."
            sleep 1
            echo "Starting in 2..."
            sleep 1
            echo "Starting in 1..."
            sleep 1
            totem "/home/xhynk/Desktop/media/Anime/Elfen Lied/Elfen Lied - 06 - Innermost Feelings.mkv";;
        "Confrontation")
            echo "You chose Episode 07 - Confrontation"
            sleep 1
            echo "Starting in 3..."
            sleep 1
            echo "Starting in 2..."
            sleep 1
            echo "Starting in 1..."
            sleep 1
            totem "/home/xhynk/Desktop/media/Anime/Elfen Lied/Elfen Lied - 07 - Confrontation.mkv";;
        "The Beginning")
            echo "You chose Episode 08 - The Beginning"
            sleep 1
            echo "Starting in 3..."
            sleep 1
            echo "Starting in 2..."
            sleep 1
            echo "Starting in 1..."
            sleep 1
            totem "/home/xhynk/Desktop/media/Anime/Elfen Lied/Elfen Lied - 08 - The Beginning.mkv";;
        "Reminiscence")
            echo "You chose Episode 09 - Reminiscence"
            sleep 1
            echo "Starting in 3..."
            sleep 1
            echo "Starting in 2..."
            sleep 1
            echo "Starting in 1..."
            sleep 1
            totem "/home/xhynk/Desktop/media/Anime/Elfen Lied/Elfen Lied - 09 - Reminiscence.mkv";;
        "Infant")
            echo "You chose Episode 10 - Infant"
            sleep 1
            echo "Starting in 3..."
            sleep 1
            echo "Starting in 2..."
            sleep 1
            echo "Starting in 1..."
            sleep 1
            totem "/home/xhynk/Desktop/media/Anime/Elfen Lied/Elfen Lied - 10 - Infant.mkv";;
        "Complication")
            echo "You chose Episode 11 - Complication"
            sleep 1
            echo "Starting in 3..."
            sleep 1
            echo "Starting in 2..."
            sleep 1
            echo "Starting in 1..."
            sleep 1
            totem "/home/xhynk/Desktop/media/Anime/Elfen Lied/Elfen Lied - 11 - Complication.mkv";;
        "Quagmire")
            echo "You chose Episode 12 - Quagmire"
            sleep 1
            echo "Starting in 3..."
            sleep 1
            echo "Starting in 2..."
            sleep 1
            echo "Starting in 1..."
            sleep 1
            totem "/home/xhynk/Desktop/media/Anime/Elfen Lied/Elfen Lied - 12 - Quagmire.mkv";;
        "No Return")
            echo "You chose Episode 13 - No Return"
            sleep 1
            echo "Starting in 3..."
            sleep 1
            echo "Starting in 2..."
            sleep 1
            echo "Starting in 1..."
            sleep 1
            totem "/home/xhynk/Desktop/media/Anime/Elfen Lied/Elfen Lied - 13 - No Return.mkv";;
        "Episode 10.5 - OVA")
            echo "You chose Episode 10.5 - OVA"
            sleep 1
            echo "Starting in 3..."
            sleep 1
            echo "Starting in 2..."
            sleep 1
            echo "Starting in 1..."
            sleep 1
            totem "/home/xhynk/Desktop/media/Anime/Elfen Lied/Elfen Lied - 14 (10.5 OVA).mkv";;
        "Quit")
            break;;
        *) echo "Invalid Option. Type 1-14, or type 15 to quit.";;
    esac
done
3
  • Does it have to be totem? Or is vlc also good?
    – Fabby
    Sep 1, 2015 at 21:06
  • I'd rather stick with totem, but if it's not feasible (or will be a massive pain to code), vlc would be acceptable, assuming the code is similar, i.e., vlc /path/to/video.ext
    – Xhynk
    Sep 1, 2015 at 21:14
  • I uninstalled totem and am using vlc and that one has a --play-and-stop command... so it'll exit and return control back to the shell script... Want me to convert that to an answer?
    – Fabby
    Sep 1, 2015 at 21:20

1 Answer 1

2
#!/usr/bin/env bash

countdown() {
  i=$1
  while [ $i -gt 0 ]; do
    printf "Starting in %d...\n" $i
    sleep 1
    i=$(( i - 1 ))
  done
}

countdown 3

Now, if you want to be fancy, tput might be worth looking into:

tcountdown() {
  i=$1
  clear
  while [ $i -gt 0 ]; do
    tput cup $(( i - 1 )) 40
    printf $i
    sleep 1
    i=$(( i - 1 ))
  done
  tput cup 0 40
  printf "0\n"
}
4
  • Awesome, exactly what I needed for the countdowns! Nice to see it's similar to creating PHP functions. Thanks!
    – Xhynk
    Sep 1, 2015 at 21:20
  • edit: I've changed it a hair. Instead of printf, I've used echo -ne "Starting in $i..."\\r which is nice because it overwrites the previous line, which I didn't see a way to do with printf. But thanks for getting me started in the right direction for that :)
    – Xhynk
    Sep 1, 2015 at 21:29
  • printf "no\r"; sleep 3; printf "way\r\n"
    – thrig
    Sep 1, 2015 at 22:40
  • @thrig answered my secondary question flawlessly. However it's the main point the remains unanswered. Automagically loading in the following videos in totem (though in a prior comment, VLC may be a better alternative)
    – Xhynk
    Sep 1, 2015 at 23:26

You must log in to answer this question.

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