Better arg handling yt-meta

This commit is contained in:
Jaidyn Ann 2017-02-19 13:06:56 -06:00
parent 5dc05242f5
commit 7e8764ddb8
2 changed files with 79 additions and 44 deletions

View File

@ -15,35 +15,45 @@ optnum=0
for argument in $@ for argument in $@
do do
case $argument in if echo $argument | grep "^-" > /dev/null
-c) then
charcount=$(echo "$argument" | echo "$(wc -c) - 1" | bc)
while [ $charcount -gt 0 ]
do
character=$(echo "$argument" | head -c1)
argument=$(echo "$argument" | sed 's/^.//')
case $character in
c)
options="$options c" options="$options c"
optnum=$((optnum+1)) optnum=$((optnum+1)) ;;
;; d) # duration
-d) # duration
options="$options d" options="$options d"
optnum=$((optnum+1)) optnum=$((optnum+1)) ;;
;; D) # date
-D) # date
options="$options D" options="$options D"
optnum=$((optnum+1)) optnum=$((optnum+1)) ;;
;; v)
-v)
options="$options v" options="$options v"
optnum=$((optnum+1)) optnum=$((optnum+1)) ;;
;; t)
-t)
options="$options t" options="$options t"
optnum=$((optnum+1)) optnum=$((optnum+1)) ;;
;; i)
*) options="$options i"
preid="$argument" optnum=$((optnum+1)) ;;
-) ;;
esac esac
charcount=$((charcount-1))
done
else
preid="$argument"
fi
done done
if echo "$preid" | grep "youtube.com"
if echo "$preid" | grep "youtube.com" > /dev/null
then then
id="$(echo $1 | sed 's/.*video_id=//')" id="$(echo $preid | sed 's/.*v=//')"
elif [ -z $preid ] elif [ -z $preid ]
then then
echo "No video specified." echo "No video specified."
@ -81,8 +91,11 @@ author="$(grep "\"author\":\"" $video_file | sed 's/.*"author":"//' | sed 's/".*
views="$(grep "\"view_count\":\"" $video_file | sed 's/.*"view_count":"//' | sed 's/".*//')" views="$(grep "\"view_count\":\"" $video_file | sed 's/.*"view_count":"//' | sed 's/".*//')"
duration="$(grep "<a href=\"/watch?v=$1" $video_file.1 | sed 's/.*Duration: //' | sed 's/\..*//')" duration="$(grep "<a href=\"/watch?v=$1" $video_file.1 | sed 's/.*Duration: //' | sed 's/\..*//')"
date="$(grep "datePublished" $video_file | sed 's/.*"datePublished" content="//' | sed 's/".*//')" date="$(grep "datePublished" $video_file | sed 's/.*"datePublished" content="//' | sed 's/".*//')"
echo "$title"
echo "$author | $views | $duration | $date | $1" if [ $optnum -eq 0 ]
then
echo "$author | $views | $duration | $date | $id"
fi
for option in $options for option in $options
do do
@ -92,11 +105,13 @@ do
d) printf "$duration" ;; d) printf "$duration" ;;
D) printf "$date" ;; D) printf "$date" ;;
v) printf "$views" ;; v) printf "$views" ;;
i) printf "$id" ;;
esac esac
if [ $optnum -ge 2 ] if [ $optnum -ge 2 ]
then then
printf " | " printf " | "
optnum=$((optnum-1)) optnum=$((optnum-1))
else
printf "\n"
fi fi
done done
cp $video_file /tmp/mateo

View File

@ -5,20 +5,27 @@
# Lisc: ISC # Lisc: ISC
# Main: jadedctrl # Main: jadedctrl
# Desc: Full-shell YT client that avoids the YT API. # Desc: Full-shell YT client that avoids the YT API.
Vers=0.5.1 Vers=0.5.2
##################### #####################
# Roadmap: # Roadmap 1.0:
# v1.0 - [X] Playlist support # yt-meta:
# [X] Args for specific info
# [X] Better argument handling
# yt-playlist:
# [X] Playlist support
# [ ] Better argument handling
# yt-channel:
# [X] Channel support # [X] Channel support
# [ ] Audio dl/stream # [ ] Better argument handling
# [ ] Show related videos # yt-search:
# [|] Channel & Playlist search # [|] Channel & Playlist search
# [ ] Search filters # [ ] Search filters
# [ ] Search & Channel sort-by # [ ] Better argument handling
# [X] Config video player, etc # general:
# [ ] Overall better interface # [|] Config video player, etc
# [x] Cli args as commands # [|] Cli args as commands
if [ -e "$HOME/.config/shelltube" ] if [ -e "$HOME/.config/shelltube" ]
then then
@ -151,7 +158,14 @@ parse() {
queue | lq ) queue | lq )
cat /tmp/yt-queue | while IFS='' read -r CUR_LINE cat /tmp/yt-queue | while IFS='' read -r CUR_LINE
do do
yt-meta "$CUR_LINE" if [ $row -eq 1 ]
then
printf '\033[1;34m%s\n' "$CUR_LINE"
row=0
else
printf '\033[1;31m%s\n' "$CUR_LINE"
row=1
fi
done done
;; ;;
cqueue | cq ) cqueue | cq )
@ -161,16 +175,22 @@ parse() {
dqueue | dq ) dqueue | dq )
for LINE in $(cat /tmp/yt-queue) for LINE in $(cat /tmp/yt-queue)
do do
yt-down -D "$LINE" itemid="$(echo "$LINE" | sed 's/.*\| //')"
grep -v "$LINE" /tmp/yt-queue > /tmp/yt-queue.tmp echo $itemid
sleep 3
yt-down -D "$itemid"
grep -v "$itemid" /tmp/yt-queue > /tmp/yt-queue.tmp
mv /tmp/yt-queue.tmp /tmp/yt-queue mv /tmp/yt-queue.tmp /tmp/yt-queue
done done
;; ;;
squeue | sq ) squeue | sq )
for LINE in $(cat /tmp/yt-queue) for LINE in $(cat /tmp/yt-queue)
do do
yt-down -S "$LINE" itemid="$(echo "$LINE" | sed 's/.*| //')"
grep -v "$LINE" /tmp/yt-queue > /tmp/yt-queue.tmp echo $itemid
sleep 3
yt-down -S "$itemid"
grep -v "$itemid" /tmp/yt-queue > /tmp/yt-queue.tmp
mv /tmp/yt-queue.tmp /tmp/yt-queue mv /tmp/yt-queue.tmp /tmp/yt-queue
done done
;; ;;