bashtube/webroot/feed.shs
Dominika Liberda dc016e361e + better header
2021-03-01 23:53:15 +01:00

33 lines
1.3 KiB
Bash

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