bashtube/webroot/channel.shs

44 lines
1.7 KiB
Bash

#!/bin/bash
declare -A strings
if [[ "${params[id]}" ]]; then
data=$(haruhi-dl --ie-key YoutubeChannel -J --flat-playlist "https://www.youtube.com/channel/${params[id]}")
elif [[ "${params[user]}" ]]; then
data=$(haruhi-dl --ie-key YoutubeChannel -J --flat-playlist "https://www.youtube.com/user/${params[user]}")
elif [[ "${params[c]}" ]]; then
data=$(haruhi-dl --ie-key YoutubeChannel -J --flat-playlist "https://www.youtube.com/c/${params[c]}")
elif [[ "${get_data[id]}" ]]; then
data=$(haruhi-dl --ie-key YoutubeChannel -J --flat-playlist "https://www.youtube.com/channel/${get_data[id]}")
elif [[ "${get_data[name]}" ]]; then
data=$(haruhi-dl --ie-key YoutubeChannel -J --flat-playlist "https://www.youtube.com/user/${get_data[name]}")
else
echo "Please specify either id or name"
return
fi
title=$(jq -r '.title' <<< $data)
if [[ ${cfg[template]} == 'default' ]]; then
meta[title]="$title"
source templates/head.sh
fi
IFS=$'\n'
video_title=($(jq -r '.entries[].title' <<< $data))
video_id=($(jq -r '.entries[].id' <<< $data))
#strings[subscribe]="<h1>$title</h1><a href='subscribe.shs?id=$(html_encode "${get_data[id]}")'>Subscribe!</a><br>"
strings[subscribe]='<h1>'"$(html_encode "$title")'s channel"'</h1>'
echo uwu > /dev/stderr
for (( i=0; i<${#video_id[@]}; i++ )); do
strings[videos]+="<a href='/watch?v=${video_id[$i]}'><img src='http://i.ytimg.com/vi/${video_id[$i]}/mqdefault.jpg'><br>${video_title[$i]}</a><br>"
done
if [[ ! ${strings[videos]} ]]; then
strings[videos]="Failed to fetch videos or channel does not have videos"
fi
source "${cfg[namespace]}/templates/header.shs"
render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/channel.t"