Last active
August 29, 2015 14:19
-
-
Save criztovyl/39153d923f1dd3bc4e1f to your computer and use it in GitHub Desktop.
Watch!
This file contains 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 | |
# ToDo: Usage. | |
### | |
# Programs | |
### | |
ZENITY="/usr/bin/zenity" | |
YOUTUBEDL="/usr/local/bin/youtube-dl" | |
XCLIP="/usr/bin/xclip" | |
### | |
# Error Codes | |
### | |
EX_EXIT=0 | |
EX_NO_INPUT=1 | |
### | |
# Functions | |
### | |
# User-input what to watch | |
# Args: responseVar | |
function whatToWatch { | |
# Var name | |
_watch_var=$1 | |
_clip=`$XCLIP -o` | |
# Input handling zenity/cli | |
if [ "$GUI" == "zenity" ]; then | |
_what=`$ZENITY --entry --text "Watch what?" --title "Wana watch!" --entry-text "$_clip"` | |
if [ ! "$?" == "0" ] || [ -z "$_what" ]; then | |
$ZENITY --question --text "Exit or refresh?\nTimeout 3 seconds." --ok-label "Exit" --cancel-label "Refresh?" --timeout 3 | |
_ec=$? | |
if [ "$_ec" == "0" ]; then | |
echo "Exit." | |
exit $EX_EXIT | |
fi | |
echo "No exit" | |
_EXIT=1 | |
fi | |
else | |
read -p "What to watch? [$_clip]" _what | |
if [ -z "$_what" ]; then | |
_what="$_clip" | |
fi | |
fi | |
# Respond | |
eval $_watch_var="'$_what'" | |
} | |
# Try to use String as Video URL that have to be extracted. | |
# If it's such an URL, extracts it, if not doesn't touch it. | |
# Args: stringVar responseVar | |
function tryAsYouTubeDL { | |
# Var names | |
stringVar=$1 | |
responseVar=$2 | |
# set responseVar if empty | |
if [ -z "$responseVar" ]; then | |
responseVar=$stringVar | |
fi | |
# String input | |
eval "_string=\$${stringVar}" | |
# Try to extract | |
_url=`$YOUTUBEDL -g $_string` | |
# Determine success | |
if [ "$?" == 0 ]; then | |
# Success, respond url | |
eval $responseVar="'$_url'" | |
else | |
# Failure, respond input string | |
eval $responseVar="'$_string'" | |
fi | |
} | |
### | |
# Script | |
### | |
while true; do | |
# Reset _NOEXIT | |
_EXIT=0 | |
# User input | |
whatToWatch watch | |
# Exit if there was no input and should exit | |
if [ -z "$watch" ]; then | |
echo "Empty" | |
if [ "$_EXIT" == "0" ]; then | |
echo "Exit." | |
exit $EX_NO_INPUT | |
else | |
echo "Should not exit." | |
continue | |
fi | |
fi | |
# Convert if needed | |
tryAsYouTubeDL watch | |
# Play | |
vlc --one-instance --playlist-enqueue $watch & # | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment