bashtube/webroot/yt/channel.shs

23 lines
863 B
Bash

#!/bin/bash
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>//')
meta[title]=$title
source templates/head.sh
if [[ ${get_data[id]} ]]; then
data=$(youtube-dl -j --flat-playlist https://www.youtube.com/channel/${get_data[id]})
elif [[ ${get_data[name]} ]]; then
data=$(youtube-dl -j --flat-playlist https://www.youtube.com/user/${get_data[name]})
else
echo "Please specify either `id` or `name`"
return
fi
IFS=$'\n'
video_title=($(jq -r '.title' <<< $data))
video_id=($(jq -r '.id' <<< $data))
echo "<h1>$title</h1><a href='subscribe.shs?id=${get_data[id]}'>Subscribe!</a><br>"
for (( i=0; i<${#video_id[@]}; i++ )); do
echo "<a href='watch.shs?v=${video_id[$i]}'><img src='http://i.ytimg.com/vi/${video_id[$i]}/mqdefault.jpg'><br>${video_title[$i]}</a><br>"
done