将 Bash 脚本中的多个视频排队

将 Bash 脚本中的多个视频排队

- 跳到粗体以跳过绒毛 -

我是 ubuntu 的新手,所以仍在学习 bash 脚本的运作方式。我已经得到了我一直在研究的这段代码,效果很好。 (附带问题 - 我可以优化倒计时部分吗?定义一次,然后在每个部分中调用它?)。使用该totem "/video/location/here.ext"命令,我的问题是视频播放器仅加载一个视频。

实际问题totem "/video.ext":在终端中使用命令时,如何确保当前视频结束后图腾知道自动继续下一个视频?

#!/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

答案1

#!/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

现在,如果你想变得更花哨,tput可能值得研究一下:

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"
}

相关内容