bashtube/webroot/feed.shs

41 lines
1.6 KiB
Bash

#!/bin/bash
if [[ ${cfg[template]} != 'retro' ]]; then
#source templates/head.sh
source "${cfg[namespace]}/templates/header.shs"
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" <<< "$data" | grep -Eoh "watch\?v\=[A-Za-z0-9_\-]+" | sed -s 's/watch?v=//'))
video_title+=($(grep "<media:title>" <<< "$data" | sed -E 's/[</ ]+media:title>//g'))
video_date+=($(grep "<published>" <<< "$data" | tail -n 15 | sed -E 's/[ </]+published>//g;s/T/\\ /;s/\+.*//' | xargs -L1 date "+%s" -d))
video_uploader+=($(grep -Poh "name>.*?</" <<< "$data" | sed -E 's/name>//;s/<\///' | head -n 1))
done <<< "$(cat storage/subscribed | grep -P "^$(session_get_username ${cookies[sh_session]}):")"
[[ ${#video_id[@]} -gt 0 ]] && strings[?feed]=true
queue=$(for (( i=0; i<${#video_id[@]}; i++ )); do echo "$i ${video_date[i]}"; done | sort -k2r | awk '{print $1}')
nested_declare feed
declare -A feed_
while read i; do
feed_[id]="${video_id[$i]}"
feed_[title]="${video_title[$i]}"
feed_[date]="$(date -d "@${video_date[$i]}" "+%H:%M, %d %h %Y")"
feed_[uploader]="${video_uploader[$i]}"
#strings[feed]+="<div class='video-image-container'><a href='watch?v='><div class='video-image' style='background-image: url(http://i.ytimg.com/vi/${video_id[$i]}/mqdefault.jpg)'></div></a></div>"
nested_add feed feed_
done <<< "$queue"
strings[_feed]="feed"
fi
render strings "${cfg[namespace]}/templates/themes/${cfg[template]}/feed.html"