bashtube/webroot/yt/feed.shs

24 lines
897 B
Bash

#!/bin/bash
source templates/head.sh
if session_verify ${cookies[sh_session]}; then
for i in $(cat storage/subscribed); do
IFS=':'
y=($i)
IFS=$'\n'
data=$(curl -s "https://www.youtube.com/feeds/videos.xml?channel_id=${y[1]}");
video_id+=($(echo "$data" | grep "<link" | grep -Eoh "watch\?v\=[A-Za-z0-9_\-]+" | sed -s 's/watch?v=//'))
video_title+=($(echo "$data" | grep "<media:title>" | sed -E 's/[</ ]+media:title>//g'))
video_date+=($(echo "$data" | grep "<published>" | tail -n 15 | sed -E 's/[ </]+published>//g' | xargs -L1 date "+%s" -d))
done
queue=$(for (( i=0; i<${#video_id[@]}; i++ )); do echo "$i ${video_date[i]}"; done | sort -k2r | awk '{print $1}')
for i in $queue; do
echo "<a href='watch.shs?v=${video_id[$i]}'><img src='http://i.ytimg.com/vi/${video_id[$i]}/mqdefault.jpg'><br>${video_title[$i]}</a>${video_date[$i]}<br>"
done
else
echo "gtfo"
fi