bashtube/webroot/subscribe.shs

36 lines
1.1 KiB
Bash

#!/bin/bash
declare -A strings
if session_verify ${cookies[sh_session]} && [[ ${get_data[id]} != '' ]]; then
title=$(curl https://www.youtube.com/feeds/videos.xml?channel_id=${get_data[id]} | grep title | head -n 1 | sed -s 's/ <title>//;s/<\/title>//')
if [[ $((grep -PF ":$title$" | grep "$(echo ${cookies[username]} | sed -E "s/\r//")") <<< storage/subscribed) == '' ]]; then
echo "$(session_get_username ${cookies[sh_session]}):${get_data[id]}:$title" >> storage/subscribed
fi
fi
if [[ ${cfg[template]} == 'default' ]]; then
source templates/head.sh
fi
IFS=$'\n'
for i in $(tac storage/subscribed | grep -P "^$(session_get_username ${cookies[sh_session]}):"); do
IFS=':'
array=($i)
if [[ ${array[1]} == '' ]]; then
break
fi
strings[subscribe]+="<div><a href='channel.shs?id=${array[1]}'>${array[@]:2:9999}</a><br></div>";
done
unset IFS
if [[ ! ${strings[subscribe]} ]]; then
strings[subscribe]="You are not logged in or you do not have any subscribed channels"
fi
source "${cfg[namespace]}/templates/header.shs"
render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/subscribe.t"