Bash: Watch 5 QVC YouTube live-streams at once, using MPV


For no other reason than "just because". The Bash script is generic enough to be used in other scenarios. Most work is done by MPV and its '--ytdl-format' option. A small delay is added before each mpv call, to avoid swamping YouTube with concurrent video requests.

#!/bin/bash

# Stream 5 QVC YouTube live-streams simultaneously.
# - Requires 'mpv' - N.B. Kills all running instances of mpv when exiting.
# - See YouTube format codes, for video quality, below.
# ver. 2017.02.11.21.46.52

### YOUTUBE VIDEO IDS ##########################################################

# QVC ...... USA .......... UK ........ Italy ....... Japan ...... France
videos=('2oG7ZbZnTcA' '8pHCfXXZlts' '-9RIKfrDP2E' 'wMo3F5IouNs' 'uUwo_p57g5c')

### FUNCTIONS ##################################################################

function finish() # Kill all mpv players when exiting
{
  killall mpv
}
trap finish EXIT

function playVideo() # Takes YouTube video ID
{
   sleep "$2" # The "be nice" delay
   mpv --quiet --ytdl-format 91 https://www.youtube.com/watch?v="$1" 
}

### BEGIN ######################################################################

for ytid in "${videos[@]}"; do ((x+=2)); (playVideo "$ytid" "$x" &); done
read -p "Press Enter key to exit"$'\n' # Hold before exiting
#zenity --warning --text="End it all?" --icon-name="" # Zenity hold alternative
exit

### FORMAT CODES ###############################################################

# format code  extension  resolution note
# 91           mp4        144p       HLS , h264, aac  @ 48k
# 92           mp4        240p       HLS , h264, aac  @ 48k
# 93           mp4        360p       HLS , h264, aac  @128k
# 94           mp4        480p       HLS , h264, aac  @128k
# 95           mp4        720p       HLS , h264, aac  @256k
# 96           mp4        1080p      HLS , h264, aac  @256k