Created
August 5, 2011 09:47
-
-
Save hdclark/1127228 to your computer and use it in GitHub Desktop.
Streamplayer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # These are the kludge commands. If I am on my PC, I want to view things | |
| # with XXXX options. If on my laptop, YYYY options. | |
| if [ "$( uname -n )" = "Crushernator" ] ; then | |
| # Laptop: Bad video card. Use x11 and zoom to reduce strain and choppiness. | |
| extras=" -vo x11 -zoom " | |
| elif [ "$( uname -n )" = "flancrest" ] ; then | |
| # Desktop: So far, nothing. | |
| extras=" " | |
| else | |
| extras=" " | |
| fi | |
| ############################################################################ | |
| #### Heartbeat commands. These are used to inihibit the screensaver. ##### | |
| ############################################################################ | |
| ## Gnome ################################################################### | |
| screensaverinhibit=" gnome-screensaver-command -p " | |
| ## Xscreensaver ############################################################ | |
| screensaverinhibit=" xscreensaver-command -deactivate " | |
| ## Better - simulates user activity with X: shift press.#################### | |
| screensaverinhibit=" ./keepalive " | |
| ############################################################################ | |
| while (( "$#" )) ; | |
| do | |
| screenopts=" -fs " | |
| if [ "$1" == "audio" ] ; then | |
| screenopts=" -vo null " | |
| screensaverinhibit=" " | |
| shift | |
| fi | |
| #Dump info if that is all which is requested. | |
| if [ "$1" == "info" ] ; | |
| then | |
| shift | |
| #Echo information to the user. | |
| echo -n "### Title: " | |
| youtube-dl -e -q "$1" | |
| echo -n "### Description: " | |
| youtube-dl --get-description -q "$1" | |
| elif [ "$1" == "noinfo" ] ; | |
| then | |
| shift | |
| #Make the FIFO. | |
| youtubefifo="$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM.fifo" | |
| mkfifo "./$youtubefifo" | |
| #Dump file into FIFO (ie: fill buffer into FIFO.) | |
| # youtube-dl -q -f 18 -o "./$youtubefifo" "$1" & | |
| youtube-dl -q -o "./$youtubefifo" "$1" & | |
| #Check that no errors have occured. | |
| ytdl_pid=$! #The process id of the previously run youtube-dl. | |
| sleep 2 #Wait for youtube-dl to either die or wait around. | |
| if [ "$(ps -ef | grep " $ytdl_pid " | grep -v grep)" ] ; #Check if youtube-dl is still waiting. | |
| then | |
| #Play it with Mplayer. | |
| # mplayer $extras -really-quiet -heartbeat-cmd "$screensaverinhibit" -cache 65536 -cache-min 1 -ao sdl $screenopts -af scaletempo -speed 1.0 "./$youtubefifo" 2>/dev/null | |
| mplayer $extras -really-quiet -heartbeat-cmd "$screensaverinhibit" -cache 65536 -cache-min 1 $screenopts -af scaletempo -speed 1.0 "./$youtubefifo" 2>/dev/null | |
| fi | |
| #Remove the FIFO. | |
| rm "./$youtubefifo" | |
| else | |
| #Echo information to the user. | |
| echo -n "##Title: " | |
| youtube-dl -e -q "$1" | |
| echo -n "##Description: " | |
| DESCRIPTION=$( youtube-dl --get-description -q "$1" ) | |
| echo $DESCRIPTION | |
| # If this is a Ted talk, we skip the first 15 seconds (the noisy intro.) | |
| if [ "$( echo $DESCRIPTION | grep '.*TED.*\|.*ted.*\|.*Ted.*' )" != "" ]; then | |
| extras="$extras -ss 15" | |
| fi | |
| #Make the FIFO. | |
| youtubefifo="$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM.fifo" | |
| mkfifo "./$youtubefifo" | |
| #Dump file into FIFO (ie: fill buffer into FIFO.) | |
| # youtube-dl -q -f 18 -o "./$youtubefifo" "$1" & | |
| youtube-dl -q -o "./$youtubefifo" "$1" & | |
| #Check that no errors have occured. | |
| ytdl_pid=$! #The process id of the previously run youtube-dl. | |
| sleep 2 #Wait for youtube-dl to either die or wait around. | |
| if ps -ef | grep " $ytdl_pid " | grep -v grep #Check if youtube-dl is still waiting. | |
| then | |
| #Play it with Mplayer. | |
| echo "Playing with mplayer now" | |
| # mplayer $extras -really-quiet -heartbeat-cmd "$screensaverinhibit" -cache 65536 -cache-min 1 -ao sdl $screenopts -af scaletempo -speed 1.0 "./$youtubefifo" 2>/dev/null | |
| mplayer $extras -really-quiet -heartbeat-cmd "$screensaverinhibit" -cache 65536 -cache-min 1 -af scaletempo -speed 1.0 $screenopts "./$youtubefifo" | |
| fi | |
| #Remove the FIFO. | |
| rm "./$youtubefifo" | |
| fi | |
| ################################################################################################################################################ | |
| ######################From back when Mplayer could directly stream the link from youtube-dl##################################################### | |
| ################################################################################################################################################ | |
| # #Mobile format: | |
| # #youtube-dl -m -g "$@" | mplayer -quiet -heartbeat-cmd "gnome-screensaver-command -p" -cache 65536 -cache-min 1 -ao sdl -fs -af scaletempo -speed 0.95 -playlist - | |
| # | |
| #thelink="$( echo $( youtube-dl -f 18 -g "$1" ) )" | |
| #echo The link is now "$thelink" | |
| # #Regular format: | |
| # mplayer -quiet -heartbeat-cmd "gnome-screensaver-command -p" -cache 65536 -cache-min 1 -ao sdl $screenopts -af scaletempo -speed 1.0 $thelink | |
| # | |
| # #Go up to this format, maximum: | |
| # #youtube-dl --max-quality=18 -g "$@" | mplayer -quiet -heartbeat-cmd "gnome-screensaver-command -p" -cache 65536 -cache-min 1 -ao sdl -fs -af scaletempo -speed 0.95 -playlist - | |
| ################################################################################################################################################ | |
| ################################################################################################################################################ | |
| ################################################################################################################################################ | |
| shift | |
| done | |
| exit |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The third keepalive is a c program which periodically simulates an X event (shift key being pressed.) It has been the only reliable way to inhibit screensavers that I have found. Last I heard, gnome-screensaver was outright ignoring the -p command. Lemme know if you want this program.
Also: sorry about the tidyness.