ytbrowser-tui/info.sh

21 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
DATA="./info_raw"
curl -s "$1" | sed 's/></>\n</g' > $DATA
ID=$(cat $DATA | grep '<meta itemprop="videoId"' | awk -F "content=" '{print $2}' | tr -d '">')
export Length_RAW=$(cat $DATA | grep '<meta itemprop="duration"' | awk -F "content=" '{print $2}' | tr -d '">')
Title=$(cat $DATA | grep '<meta itemprop="name"' | awk -F "content=" '{print $2}' | tr -d '">')
Channel=$(cat $DATA | grep '<link itemprop="name"' | awk -F "=" '{print $3}' | tr -d '">')
Desc=$(cat $DATA | grep '<meta itemprop="description"' | awk -F "content=" '{print $2}' | tr -d '">')
export Published_RAW=$(cat $DATA | grep '<meta itemprop="datePublished"' | awk -F "content=" '{print $2}' | tr -d '">')
Published=$(date -d "2000/1/1 $(date +%s.%N) seconds - $(date -d "$Published_RAW" +%s.%N) seconds" +"%-j days %H:%M:%S ago")
Length=$(echo $Length_RAW | sed -r 's/PT//' | sed -r 's/([0-9]+)H/\1:/g' | sed -r 's/([0-9]+)M/\1:/g' | sed -r 's/([0-9]+)S/\1/g')
echo "{'id':'$ID','runtime':'$Length','title':'$Title','channel':'$Channel','description':'$Desc','published':'$Published'}" | tr "'" '"'
rm $DATA