2016-12-11 19:33:57 -06:00
|
|
|
#####################
|
|
|
|
# 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
|
|
|
|
|
|
|
|
if echo "$1" | grep "youtube.com"
|
|
|
|
then
|
|
|
|
id="$(echo $1 | sed 's/.*video_id=//')"
|
|
|
|
elif [ -z $1 ]
|
|
|
|
then
|
2016-12-23 11:12:07 -06:00
|
|
|
echo "No video specified."
|
2016-12-11 19:33:57 -06:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
id="$1"
|
|
|
|
fi
|
|
|
|
|
2017-01-05 22:38:38 -06:00
|
|
|
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
|
|
|
|
|
2016-12-11 19:33:57 -06:00
|
|
|
|
2016-12-23 13:28:20 -06:00
|
|
|
video_file="/tmp/$(mktemp -u yt-video_XXXXXX)"
|
2016-12-11 19:33:57 -06:00
|
|
|
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/".*//')"
|
|
|
|
echo "$title"
|
|
|
|
echo "$author | $views | $duration | $date | $1"
|