Skip to content

Commit

Permalink
Finished cleanup. See summary below for changes:
Browse files Browse the repository at this point in the history
* Added verbosity when downloading/playing
* Cleaned stdout by quitening mplayer
* Removed polling when checking if download has completed
* Remove forks from the function itself: the caller should decide this
  • Loading branch information
Tom Vincent committed Aug 28, 2010
1 parent 626c5d3 commit 484c06d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions ytmp.conf
Expand Up @@ -3,3 +3,4 @@ MAXQUAL=35
#GUI="kdialog"
#GUI="zenity"
GUI="none"
DWN=""
30 changes: 16 additions & 14 deletions ytmpc
Expand Up @@ -8,41 +8,43 @@ else
fi

ytplay() {
mplayer -cache 2048 "$vidurl" &
echo "[ytmc] Now playing: $title"
mplayer -cache 2048 "$vidurl" > /dev/null 2>&1
}

ytdownload() {
youtube-dl --max-quality="$MAXQUAL" -o "${DWN:-$HOME}/$title".%\(ext\)s "$url" &
echo "[ytmc] Now downloading: $title"
youtube-dl --max-quality="$MAXQUAL" -o "${DWN:-$HOME}/%(stitle)s.%(ext)s" "$url"
}

ytdlandplay() {
ytdownload
while ! [[ -a $title* ]]; do sleep 3; done
mplayer $title* &
local log="/tmp/youtube-dl.log"
ytdownload | tee "$log"
vidurl="$(grep -F Destination "$log" | awk '{print $3}')"
ytplay &
}

_zenity() {
choice=$(zenity --list --checklist --text="$title" --hide-header --column "1" \
--column "2" TRUE "View in mplayer" FALSE "Download")

case "$choice" in
"View in mplayer") ytplay;;
"Download") ytdownload;;
"View in mplayer|Download") ytdlandplay;;
"View in mplayer") ytplay &;;
"Download") ytdownload &;;
"View in mplayer|Download") ytdlandplay &;;
esac
}

_kdialog() {
choice="$(kdialog --checklist "$title" 1 "View with mplayer (default)" on \
2 "Download" off)"
2 "Download" off)"

case "$choice" in
"1") ytplay;;
"2") ytdownload;;
"1|2") ytdlandplay;;
"1") ytplay &;;
"2") ytdownload &;;
"1|2") ytdlandplay &;;
esac
}

lasturl=""
while(true); do
if [[ -f /tmp/ytmdurls ]]; then
Expand All @@ -51,7 +53,7 @@ while(true); do
title="$(youtube-dl -e "$url")"
vidurl="$(youtube-dl --max-quality="$MAXQUAL" -g "$url")"
case "$GUI" in
"none") ytplay;;
"none") ytplay &;;
"zenity") _zenity;;
"kdialog") _kdialog;;
esac
Expand Down

0 comments on commit 484c06d

Please sign in to comment.