bashtube/webroot/subscribe.shs
2021-02-28 17:43:40 +01:00

31 lines
952 B
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
render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/subscribe.t"