61d3cbbed9
This reverts commit d6d4b0e56e
.
118 lines
3.1 KiB
Bash
Executable File
118 lines
3.1 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
#####################
|
|
# Name: yt-meta.sh
|
|
# Date: 2016-12-10
|
|
# Lisc: ISC
|
|
# Main: jadedctrl
|
|
# Desc: Fetches metadata about
|
|
# a specific YT video.
|
|
#####################
|
|
|
|
# Usage: yt-meta.sh $video_id
|
|
|
|
optnum=0
|
|
|
|
for argument in $@
|
|
do
|
|
if echo $argument | grep "^-" > /dev/null
|
|
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"
|
|
optnum=$((optnum+1)) ;;
|
|
d) # duration
|
|
options="$options d"
|
|
optnum=$((optnum+1)) ;;
|
|
D) # date
|
|
options="$options D"
|
|
optnum=$((optnum+1)) ;;
|
|
v)
|
|
options="$options v"
|
|
optnum=$((optnum+1)) ;;
|
|
t)
|
|
options="$options t"
|
|
optnum=$((optnum+1)) ;;
|
|
i)
|
|
options="$options i"
|
|
optnum=$((optnum+1)) ;;
|
|
-) ;;
|
|
esac
|
|
charcount=$((charcount-1))
|
|
done
|
|
else
|
|
preid="$argument"
|
|
fi
|
|
done
|
|
|
|
|
|
if echo "$preid" | grep "youtube.com" > /dev/null
|
|
then
|
|
id="$(echo $preid | sed 's/.*v=//')"
|
|
elif [ -z $preid ]
|
|
then
|
|
echo "No video specified."
|
|
exit 1
|
|
else
|
|
id="$preid"
|
|
fi
|
|
|
|
if [ -e "./lib/yt-meta" ]
|
|
then
|
|
alias yt-channel="./lib/yt-channel"
|
|
alias yt-search="./lib/yt-down"
|
|
alias yt-meta="./lib/yt-meta"
|
|
alias yt-search="./lib/yt-search"
|
|
alias yt-down="./lib/yt-channel"
|
|
alias st-download="./lib/st-download"
|
|
alias st-video="./lib/st-video"
|
|
fi
|
|
|
|
|
|
video_file="/tmp/$(mktemp -u yt-video_XXXXXX)"
|
|
if type "wget" &> /dev/null
|
|
then
|
|
wget -q https://youtube.com/watch?v=$id -O $video_file
|
|
wget -q https://youtube.com/results?search_query=$id -O $video_file.1
|
|
elif type "curl" &> /dev/null
|
|
then
|
|
curl -s https://youtube.com/watch?v=$id -o $video_file
|
|
curl -s https://youtube.com/results?search_query=$id -o $video_file.1
|
|
fi
|
|
|
|
# Now for displaying the metadata
|
|
title="$(grep "\"title\":\"" $video_file | sed 's/.*"title":"//' | sed 's/".*//')"
|
|
author="$(grep "\"author\":\"" $video_file | sed 's/.*"author":"//' | 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/\..*//')"
|
|
date="$(grep "datePublished" $video_file | sed 's/.*"datePublished" content="//' | sed 's/".*//')"
|
|
|
|
if [ $optnum -eq 0 ]
|
|
then
|
|
echo "$author | $views | $duration | $date | $id"
|
|
fi
|
|
|
|
for option in $options
|
|
do
|
|
case $option in
|
|
c) printf "$author" ;;
|
|
t) printf "$title" ;;
|
|
d) printf "$duration" ;;
|
|
D) printf "$date" ;;
|
|
v) printf "$views" ;;
|
|
i) printf "$id" ;;
|
|
esac
|
|
if [ $optnum -ge 2 ]
|
|
then
|
|
printf " | "
|
|
optnum=$((optnum-1))
|
|
else
|
|
printf "\n"
|
|
fi
|
|
done
|