Advertisement
sbicknel

Medley Grid Video Player

Aug 29th, 2014
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 22.29 KB | None | 0 0
  1. #!/bin/bash -
  2.  
  3. # vim: set tabstop=8 softtabstop=4 shiftwidth=4 smarttab noexpandtab:
  4.  
  5. ${DEBUG}
  6.  
  7. #========================================================================
  8. #          FILE:  medley
  9. #
  10. #         USAGE:  medley [-h|--help][-V|--version]|-a ASPECT -w WIDTH
  11. #                        -n NUMBER -f -s FILENAME [FILENAME...]
  12. #                 --help    display program help and exit
  13. #
  14. #                 -a ASPECT aspect ratio of videos. Valid values for
  15. #                           ASPECT are cinema|hdtv|widescreen|standard.
  16. #                           Default is standard.
  17. #                 -w WIDTH  width of video viewport. Cannot be used with
  18. #                           -f.
  19. #                 -n NUMBER number of viewports in a row. Valid values
  20. #                           for NUMBER are 1-3. Default is 4.
  21. #                 -f        turn off fullscreen view when playing a list
  22. #                           of videos sequentially. Cannot be used with
  23. #                           -w.
  24. #                 -s        do not unsort FILENAMEs.
  25. #                 -u
  26. #                 --usage   display a usage message and exit
  27. #
  28. #                 -V
  29. #                 --version display the program version number and exit
  30. #                 -x        display debugging information
  31. #
  32. #   DESCRIPTION:  play a medley of videos simultaneously
  33. #
  34. #       OPTIONS:  --help, --version
  35. #  REQUIREMENTS:  ---
  36. #          BUGS:  ---
  37. #         NOTES:  ---
  38. #        AUTHOR:  Scott Bicknell (SB), [email protected]
  39. #       COMPANY:  
  40. #       VERSION:  2.0
  41. #       CREATED:  
  42. #      REVISION:  ---
  43. #
  44. # Copyright 2010 Scott Bicknell, sbicknel (at) gmail dot com
  45. #
  46. # This program is free software: you can redistribute it and/or modify
  47. # it under the terms of the GNU General Public License as published by
  48. # the Free Software Foundation, either version 3 of the License, or
  49. # (at your option) any later version.
  50. #
  51. # This program is distributed in the hope that it will be useful,
  52. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  53. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  54. # GNU General Public License for more details.
  55. #
  56. # You should have received a copy of the GNU General Public License
  57. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  58. #========================================================================
  59.  
  60.  
  61. PROGNAME=${0##*/}
  62. VERSION='2.0'
  63. PATH="${HOME}/bin:/bin:/usr/bin:/usr/local/bin"
  64. PANEL_HEIGHT=$(sed -n '/\[Containments\]\[1\]$/,/^$/p'\
  65.     $(kde4-config --localprefix)/share/config/plasma-desktop-appletsrc |\
  66.     awk -F, '/geometry/ {print $4}')
  67. PANEL_HEIGHT=${PANEL_HEIGHT##*-} # height of the desktop panel or taskbar
  68. umask 077
  69.  
  70. # -----------------------------------------------------------------------
  71. # Display error messages on standard error.
  72. # -----------------------------------------------------------------------
  73. function error () {
  74.     printf '%s: %s\n' $PROGNAME "$@"
  75. } >&2
  76.  
  77.  
  78. # -----------------------------------------------------------------------
  79. # Display warning messages on standard output.
  80. # -----------------------------------------------------------------------
  81. warning () {
  82.     printf '%s: %s\n' $PROGNAME "$@"
  83. }
  84.  
  85. # -----------------------------------------------------------------------
  86. # Display messages on standard output.
  87. # -----------------------------------------------------------------------
  88. function message () {
  89.     printf '%s: %s\n' $PROGNAME "$@"
  90. }
  91.  
  92.  
  93. # -----------------------------------------------------------------------
  94. # Function for exit due to fatal program error
  95. #       Accepts 1 argument:
  96. #               string containing descriptive error message
  97. # -----------------------------------------------------------------------
  98. function error_exit () {
  99.     error "${1:-'Unknown Error'}"
  100.     exit 1
  101. }
  102.  
  103.  
  104. # -----------------------------------------------------------------------
  105. # Function to handle termination signals
  106. #       Accepts 1 argument:
  107. #               signal_spec
  108. # -----------------------------------------------------------------------
  109. function signal_exit () {
  110.     case $1 in
  111.  
  112.         INT)
  113.             error_exit 'Program aborted by user'
  114.         ;;
  115.  
  116.         TERM)
  117.             error_exit 'Program terminated'
  118.         ;;
  119.  
  120.         *)
  121.             error_exit 'Terminating on unknown signal'
  122.         ;;
  123.  
  124.     esac
  125. }
  126.  
  127. trap 'signal_exit TERM' TERM HUP QUIT PIPE
  128. trap 'signal_exit INT'  INT
  129.  
  130.  
  131. # -----------------------------------------------------------------------
  132. # Function called for a graceful exit
  133. #       No arguments
  134. # -----------------------------------------------------------------------
  135. function graceful_exit () {
  136.     exit
  137. }
  138.  
  139.  
  140. # -----------------------------------------------------------------------
  141. # Simulate user activity to inhibit the screensaver
  142. # -----------------------------------------------------------------------
  143. function inhibit_screensaver () {
  144.     qdbus org.freedesktop.ScreenSaver /ScreenSaver SimulateUserActivity
  145. } &>/dev/null
  146.  
  147.  
  148. # -----------------------------------------------------------------------
  149. # Set player variable
  150. # -----------------------------------------------------------------------
  151. set_player () {
  152.     if [[ -n "$player" ]]; then
  153.         return 0
  154.     fi
  155.     if ! type -P mplayer2 &>/dev/null && ! type -P mplayer &>/dev/null; then
  156.         error_exit 'mplayer or mplayer2 is required'
  157.     fi
  158.     if type -P mplayer2 &>/dev/null; then
  159.         player=mplayer2
  160.     elif type -P mplayer &>/dev/null; then
  161.         player=mplayer
  162.     fi
  163. }
  164.  
  165.  
  166. # -----------------------------------------------------------------------
  167. # Display a short message about program usage. This is also used by the
  168. # helptext function to display part of its help text.
  169. # -----------------------------------------------------------------------
  170. function usage () {
  171.     cat <<- EOF
  172.    
  173. USAGE: $PROGNAME: [-a standard|cinema|hdtv|widescreen][-f][-s][-n NUM|-w NUM]|[-h|--help]
  174.                   [-u|--usage][-V|--version]|[-x] FILE [FILE...]
  175. EOF
  176. }
  177.  
  178.  
  179. # -----------------------------------------------------------------------
  180. # Display the program version number
  181. # -----------------------------------------------------------------------
  182. function version () {
  183.     printf '%s %s\n' $PROGNAME $VERSION
  184. }
  185.  
  186.  
  187. # -----------------------------------------------------------------------
  188. # Function to display help message for program
  189. #       No arguments
  190. # -----------------------------------------------------------------------
  191. function helptext () {
  192.     local tab=$(printf '\t\t')
  193.  
  194.     usage
  195.     cat << -EOF-
  196.  
  197.  
  198. DESCRIPTION:
  199.  
  200. Play a medley of videos simultaneously. By default, each video is scaled to fit
  201. in a row four viewports wide. The script fills the display with as many windows
  202. as it can and tiles them in a grid. As each video finishes playing another
  203. video fills the same location in the on-screen grid. The videos are played in
  204. random order by default if unsort is installed.
  205.  
  206.  
  207. Options:
  208.  
  209. -a ASPECT       Aspect ratio. This option affects vertical spacing of viewports
  210.                 in the on-screen grid. Valid names are standard, cinema, hdtv,
  211.                 and widescreen. Default is 'standard'.
  212.                 Name       | Meaning
  213.                 --------------------
  214.                 standard   |     4:3
  215.                 cinema     |    16:9
  216.                 hdtv       |  1.85:1
  217.                 widescreen |  2.35:1
  218. -f              Turn off fullscreen mode when playing videos one at a time.
  219.                 Disables -w. Must be used with -n 1.
  220. -s              Do not randomize play list.  Ignored if unsort not installed
  221.  
  222. -h, --help      Display this help message and exit.
  223. -u, --usage     Display a usage message and exit.
  224. -V, --version   Display program version and exit.
  225.  
  226. -w PIXELS       Width of a video viewport. This option affects how many
  227.                 videos are placed in a row and may affect how may rows
  228.                 are placed in the grid. Default creates a row of four
  229.                 videos and sizes the viewports to fit the width of the
  230.                 display. Cannot be used with -n.
  231. -n NUMBER       Number of windows in a row. Cannot be used with -w. Valid
  232.                 values are 1 to 3. If NUMBER is 1, -f may be used.
  233. -x              Display debugging output when running the program
  234.  
  235. This program requires mplayer or mplayer2.  Unsort is optional.
  236.  
  237.  
  238. -EOF-
  239.     version
  240. }
  241.  
  242. # -----------------------------------------------------------------------
  243. # Verify that the usage function and the helptext function both have
  244. # documentation for each long option. Verify that the header comment
  245. # also has each long option listed.
  246. # -----------------------------------------------------------------------
  247. if [[ "$1" == '--help' ]]; then
  248.     helptext
  249.     graceful_exit
  250. fi
  251. if [[ "$1" == '--version' ]]; then
  252.     version
  253.     graceful_exit
  254. fi
  255. if [[ "$1" == '--usage' ]]; then
  256.     usage
  257.     graceful_exit
  258. fi
  259.  
  260. # dimensions of the current display
  261. # we get this early so we can do early error checking
  262. dimensions=$(xdpyinfo | awk -F' ' '/dimensions/ {print $2}')
  263. dwidth=${dimensions%x*}                     # width of display in pixels
  264. dheight=${dimensions##*x}                   # height of display in pixels
  265. unset dimensions
  266.  
  267. # default width of a video window
  268. maxGridHeight=$(( $dheight - $PANEL_HEIGHT ))
  269. defaultWidth=$(echo "scale=2; $maxGridHeight / 3 * 4 / 3 " | bc | sed 's/...$//')
  270.  
  271. # mplayer/mplayer2 calling syntax differences
  272. declare -A id
  273. declare -A fd
  274. declare -A asp
  275. id[mplayer]='-identify '
  276. fd[mplayer]='-framedrop'
  277. asp[mplayer]='-aspect '
  278. id[mplayer2]='--identify='
  279. fd[mplayer2]='--framedrop'
  280. asp[mplayer2]='--aspect='
  281.  
  282. # ratios
  283. st='4:3'    # standard
  284. ci='16:9'   # cinema
  285. hd='1.85:1' # hdtv
  286. wi='64:27'  # widescreen
  287.  
  288. # -----------------------------------------------------------------------
  289. # Verify that the usage function and the helptext function both have
  290. # documentation for each short option. Verify that the header comment
  291. # also has each short option listed in the usage section.
  292. # -----------------------------------------------------------------------
  293. while getopts :a:fhn:suVw:x opt; do
  294.     case $opt in
  295.  
  296.         a) # aspect ratio
  297.             set_player
  298.             aspect=${asp[$player]}
  299.             case ${OPTARG,,} in
  300.  
  301.                 standard)
  302.                     aspect=${aspect}$st
  303.                     aspRatio=${OPTARG,,}
  304.                     ;;
  305.  
  306.                 cinema)
  307.                     aspect=${aspect}$ci
  308.                     aspRatio=${OPTARG,,}
  309.                     ;;
  310.  
  311.                 hdtv)
  312.                     aspect=${aspect}$hd
  313.                     aspRatio=${OPTARG,,}
  314.                     ;;
  315.  
  316.                 widescreen)
  317.                     aspect=${aspect}$wi
  318.                     aspRatio=${OPTARG,,}
  319.                     ;;
  320.  
  321.                 *)
  322.                     message "$OPTARG: unsupported aspect ratio. Setting aspect ratio to standard"
  323.                     aspect=${aspect}$st
  324.                     aspRatio=standard
  325.                     ;;
  326.  
  327.                 esac
  328.                 ;;
  329.  
  330.         h) # help
  331.             helptext
  332.             graceful_exit
  333.             ;;
  334.  
  335.         f) # turn off fullscreen when playing videos one at a time
  336.             full=no
  337.             width=$(( $dwidth / 2 + 1 ))
  338.             ;;
  339.  
  340.         n) # number of windows in a grid row
  341.             case ${OPTARG} in
  342.  
  343.                 *[!0-9]*)
  344.                     message "$OPTARG: must be a number of windows. Setting number of windows to default"
  345.                     width=$defaultWidth
  346.                     ;;
  347.  
  348.                 [1-3])
  349.                     width=$(( $dwidth / $(( $OPTARG + 1 )) + 1 ))
  350.                     ;;
  351.  
  352.                 *)
  353.                     message "$OPTARG: must be a number from 1 to 3. Setting number of windows to default"
  354.                     width=$defaultWidth
  355.                     ;;
  356.             esac
  357.             ;;
  358.  
  359.         s) # do not unsort videos
  360.             unsort=no
  361.             ;;
  362.  
  363.         u) # usage
  364.             usage
  365.             graceful_exit
  366.             ;;
  367.  
  368.         V) # version
  369.             version
  370.             graceful_exit
  371.             ;;
  372.  
  373.         w) # width of a video window
  374.  
  375.             case $OPTARG in
  376.  
  377.                 *[!0-9]*)
  378.                     message "$OPTARG: video width must be a number. Setting width to $defaultWidth"
  379.                     width=$defaultWidth
  380.                     ;;
  381.  
  382.             esac
  383.             width=${width:-$OPTARG}
  384.             if [[ $width -gt $dwidth ]]; then
  385.                 message "-w: width cannot exceed $dwidth. Setting width to $defaultWidth"
  386.                 width=$defaultWidth
  387.             fi
  388.             ;;
  389.  
  390.         x)  # set debugging output on a per-run basis. The $DEBUG
  391.             # environment variable will enable degugging output at
  392.             # the top of the script.
  393.             set -x
  394.             ;;
  395.  
  396.         :)  # process missing required parameters
  397.             case $OPTARG in
  398.                 a) error_exit "-$OPTARG: required argument missing: standard, cinema, hdtv, or widescreen expected";;
  399.                 n) error_exit "-$OPTARG: required argument missing: 1, 2 or 3 expected";;
  400.                 w) error_exit "-$OPTARG: required argument missing: pixel width of a single video expected (e.g. 300)";;
  401.                 *) error_exit "-$OPTARG: required argument missing";;
  402.             esac
  403.             ;;
  404.  
  405.         *)  # process unknown options
  406.             usage
  407.             error_exit "Unknown option: -$OPTARG"
  408.             ;;
  409.  
  410.     esac
  411. done
  412. shift $(( $OPTIND - 1 ))
  413.  
  414. if [[ $# -eq 0 ]]; then
  415.     error_exit 'nothing to play'
  416. fi
  417. set_player
  418. killall $player &>/dev/null
  419.  
  420. # if aspect is not set, try to determine aspect ratio from folder name
  421. if [[ -z "$aspect" ]]; then
  422.     case ${PWD##*/} in
  423.         standard|cinema|hdtv|widescreen)
  424.             aspRatio=${PWD##*/}
  425.             aspect=${asp[$player]}
  426.             case $aspRatio in
  427.  
  428.                 standard)
  429.                     aspect=${aspect}$st
  430.                     ;;
  431.  
  432.                 cinema)
  433.                     aspect=${aspect}$ci
  434.                     ;;
  435.  
  436.                 hdtv)
  437.                     aspect=${aspect}$hd
  438.                     ;;
  439.  
  440.                 widescreen)
  441.                     aspect=${aspect}$wi
  442.                     ;;
  443.  
  444.             esac
  445.             ;;
  446.     esac
  447. fi
  448.  
  449. width=${width:-$defaultWidth}                               # width of a video window
  450. case $width in
  451.  
  452.     *[!0-9]*)
  453.         message "$OPTARG: video width must be a number. Setting width to $defaultWidth pixels."
  454.         width=$defaultWidth
  455.         ;;
  456. esac
  457.  
  458. # height of a video window
  459. aspRatio=${aspRatio:-standard}
  460. aspRatio=${aspRatio,,}
  461. case $aspRatio in
  462.      standard) height=$(echo "scale=2; $width /  4 *  3"  | bc | sed 's/...$//');;
  463.        cinema) height=$(echo "scale=2; $width / 16 *  9"  | bc | sed 's/...$//');;
  464.          hdtv) height=$(echo "scale=2; $width /    1.85"  | bc | sed 's/...$//');;
  465.    widescreen) height=$(echo "scale=2; $width / 64 * 27"  | bc | sed 's/...$//');;
  466.             *)
  467.                 message 'unsupported aspect ratio. Using standard aspect ratio to set height'
  468.                 height=$(echo "scale=2; $width / 4 *  3"  | bc | sed 's/...$//')
  469.                 ;;
  470. esac  
  471. unset aspRatio
  472. maxxp=$(( $dwidth - $width )) # maximum horizontal window position
  473.  
  474. # pixel dimensions of the entire grid
  475. maxWWide=$(( $dwidth / $width )) # maximum windows wide
  476.  
  477. # maximum windows high
  478. maxWHigh=$(( $dheight - $PANEL_HEIGHT ))
  479. maxWHigh=$(( $maxWHigh  / $height ))
  480.  
  481. numWindows=$(( $maxWWide * $maxWHigh ))  # number of windows in a grid
  482. maxPixelsWide=$(( $width * $maxWWide ))  # maximum pixels in a row
  483. unset maxWWide
  484. maxPixelsHigh=$(( $height * $maxWHigh )) # maximum pixels in a column
  485. unset maxWHigh
  486.  
  487. # screen coordinates of first video window
  488. xstart=$(( $(( $dwidth - $maxPixelsWide )) / 2 ))                  # initial horizontal window position
  489. unset dwidth
  490. unset maxPixelsWide
  491. ystart=$(( $(( $dheight - $maxPixelsHigh - $PANEL_HEIGHT )) / 2 )) # initial vertical window position
  492. unset dheight
  493. unset maxPixelsHigh
  494. x=$xstart                                                          # horizontal window position
  495. y=$ystart                                                          # vertical window position
  496. unset ystart
  497.  
  498. # make a list of all window positions
  499. for (( w=1; w<=$numWindows; w++ )); do
  500.     window[$w]="$x:$y"
  501.     x=$(( $x + $width ))
  502.     if [[ $x -gt $maxxp ]]; then
  503.         x=$xstart
  504.         y=$(( $y + $height ))
  505.     fi
  506. done
  507. unset height
  508. unset maxxp
  509. unset xstart
  510. unset x
  511. unset y
  512.  
  513. # set fullscreen mode if only one window position in list
  514. declare -A fs
  515. if [[ ${#window[@]} -eq 1 ]] && [[ ${full:-yes} == yes ]]; then
  516.     fs[mplayer2]='--fs'
  517.     fs[mplayer]='-fs'
  518. fi
  519.  
  520. unset COLUMNS   # This setting prevents some data from reaching grep
  521.  
  522. v=0 # video list index
  523.  
  524. # create an indexed list of video files, skipping files not recognized as videos
  525. # explicite index assignment is necessary to prevent word splitting on spaces
  526. for f in "$@"; do
  527.     if ! [[ $(file --mime-type -b "$f" | awk -F/ '{print $1}') == 'video' ]] &&
  528.         ! [[ $(file --mime-type -b "$f" | awk -F/ '{print $2}') == 'ogg'   ]]; then
  529.         warning "Video file not recognized. $f: $(file --mime-type -b $f)"
  530.  
  531.         # ensures that the number of parameters equals the number of valid video files
  532.         # we can throw away parameters because we are storing valid ones in flist
  533.         shift
  534.         continue
  535.     fi
  536.     flist[$v]="$f"
  537.     (( v++ ))
  538. done
  539.  
  540. # create a list of video files in input order if unsort is not installed
  541. if ! type -P unsort &>/dev/null || [[ ${unsort:-yes} == no ]]; then
  542.     rlist=( "${flist[@]}" )
  543.  
  544. # create a random list of video files otherwise
  545. else
  546.     v=0
  547.  
  548.     # create a random list of indexes ($rn) for each video file in $flist
  549.     # $rn is our random list of indexes into $flist
  550.     rn=( $(for (( r=0; r<${#flist[@]}; r++ )); do
  551.         echo $r
  552.     done | sed 's/ /\n/g' | unsort 2>/dev/null) )
  553.  
  554.     # this random list is used to store video file names from random
  555.     # index locations in $flist to sequential locations in $rlist
  556.     for r in ${rn[@]}; do
  557.         rlist[$v]="${flist[$r]}"
  558.         (( v++ ))
  559.     done
  560. fi
  561. unset v
  562. unset flist
  563.  
  564. if [[ ${#rlist[@]} -eq 0 ]]; then
  565.     message 'video detection failed. Try: file --mime-type -b FILE'
  566.     error_exit 'no video files in file list'
  567. fi
  568.  
  569. # set fullscreen mode if only one video in list
  570. if [[ ${#rlist[@]} -eq 1 ]] && [[ ${full:-yes} == yes ]]; then
  571.     fs[mplayer2]='--fs'
  572.     fs[mplayer]='-fs'
  573. fi
  574.  
  575. # video format ratios
  576. WIDESCREEN=$(echo "scale=2; 64 / 27 * 100" | bc | sed -e 's/...$//')
  577. HDTV=$(      echo "scale=2;    1.85 * 100" | bc | sed -e 's/...$//')
  578. CINEMA=$(    echo "scale=2;  16 / 9 * 100" | bc | sed -e 's/...$//')
  579. STANDARD=$(  echo "scale=2;   4 / 3 * 100" | bc | sed -e 's/...$//')
  580.  
  581. rindex=0                      # index into rlist
  582. started=0                     # number of videos started in previous check
  583.  
  584. # delay between checks for empty slots.  Longer delays when playing more
  585. # videos; shorter delays when more cpu cores are installed.
  586. numProc=$(grep '^processor' /proc/cpuinfo | wc -l)
  587. [[ $numProc -lt 2 ]] && numProc=2
  588. delay=$(( $numWindows / $(( $numProc / 2 )) ))
  589. [[ $delay -lt 1 ]] && delay=1
  590.  
  591. # play each video in an empty slot. Shift each file name off the list as each video is played.
  592. while [[ $# -gt 0 ]]; do
  593.  
  594.     inhibit_screensaver
  595.  
  596.     # if all slots are filled with videos, sleep and skip further processing
  597.     if [[ $(ps aux | grep 'mplayer.*noborder.*zoom.*xy.*geometry.*' | grep -v grep | wc -l) -eq $numWindows ]]; then
  598.         if [[ $started -gt 0 ]]; then
  599.             sleep $(( $delay - 1 ))s
  600.             started=0
  601.         else
  602.             sleep ${delay}s
  603.         fi
  604.         continue
  605.     fi
  606.     started=0
  607.  
  608.     # fill empty slots with videos
  609.     for slot in ${window[@]}; do
  610.         if ! ps aux | grep "geometry $slot " | grep -vq grep; then
  611.  
  612.             # quit here if at end of file list
  613.             if [[ $# -eq 0 ]]; then
  614.                 break
  615.             fi
  616.  
  617.             # get dimensions of video
  618.             widthDim=$($player -frames 0 ${id[$player]} ${rlist[$rindex]} 2>/dev/null | awk -F=  '/^ID_VIDEO_WIDTH/ {print $2}' 2>/dev/null)
  619.             heightDim=$($player -frames 0 ${id[$player]} ${rlist[$rindex]} 2>/dev/null | awk -F=  '/^ID_VIDEO_HEIGHT/ {print $2}' 2>/dev/null)
  620.  
  621.             # compute format ratio
  622.             format=$(echo "scale=2; $widthDim / $heightDim * 100" | bc | sed -e 's/...$//')
  623.  
  624.             # set aspect ratio for each video
  625.             aspect=${asp[$player]}
  626.             if [[ "$format" -ge "$WIDESCREEN" ]]; then
  627.                 aspect=${aspect}$wi
  628.             elif [[ "$format" -ge "$HDTV" ]]; then
  629.                 aspect=${aspect}$hd
  630.             elif [[ "$format" -ge "$CINEMA" ]]; then
  631.                 aspect=${aspect}$ci
  632.             else
  633.                 aspect=${aspect}$st
  634.             fi
  635.             $player ${fd[$player]} $aspect -noborder -zoom ${fs[$player]} -xy $width -geometry "$slot" "${rlist[$rindex]}" &>/dev/null &
  636.             unset rlist[$rindex]
  637.             (( started++ ))
  638.             (( rindex++ ))
  639.             sleep 1s
  640.             shift
  641.         fi
  642.     done
  643. done
  644.  
  645. # inhibit the screensaver until the last video ends
  646. while ps aux | grep 'mplayer.*noborder.*zoom.*xy.*geometry.*' | grep -vq grep; do
  647.     sleep $delay
  648.     inhibit_screensaver
  649. done
  650.  
  651. graceful_exit
  652.  
  653. This script makes several assumptions that will not hold for many users.  It assumes you are using KDE.  It gets the value
  654. for $PANEL_HEIGHT from KDE's configuration.  It also relies on qdbus to inhibit the screensaver while videos are playing.
  655. The script uses either mplayer or mplayer2 and adjusts its syntax according to which one is installed.  If you have a version
  656. of unsort installed, the script will randomize the play list by default.  While running, the script will sleep for a period
  657. calculated by the number of videos it is playing simultaneously while taking into account the number of processor cores
  658. installed on the system.  The more videos it plays, the longer the sleep interval; the more processor cores installed, the
  659. shorter the sleep interval.  $PANEL_HEIGHT can be hard-coded or the code that sets it replaced with code that works for your
  660. environment.  The same goes for inhibiting the screensaver.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement