From 484c06d2436628357a62a83ce8b4785ad572ae16 Mon Sep 17 00:00:00 2001 From: Tom Vincent Date: Sat, 28 Aug 2010 14:49:42 +0800 Subject: [PATCH] Finished cleanup. See summary below for changes: * 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 --- ytmp.conf | 1 + ytmpc | 30 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/ytmp.conf b/ytmp.conf index a2cd963..d6dca9c 100644 --- a/ytmp.conf +++ b/ytmp.conf @@ -3,3 +3,4 @@ MAXQUAL=35 #GUI="kdialog" #GUI="zenity" GUI="none" +DWN="" diff --git a/ytmpc b/ytmpc index 61a4740..d608ed0 100755 --- a/ytmpc +++ b/ytmpc @@ -8,17 +8,20 @@ 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() { @@ -26,23 +29,22 @@ _zenity() { --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 @@ -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