bashtube/webroot/search.shs

41 lines
1.2 KiB
Plaintext
Raw Normal View History

2021-01-28 22:56:24 +01:00
#!/bin/bash
2021-02-28 17:43:40 +01:00
declare -A strings
2021-01-28 22:56:24 +01:00
2021-02-28 17:43:40 +01:00
if [[ ${cfg[template]} == 'default' ]]; then
meta[title]="youtube but not really"
source templates/head.sh
fi
2021-01-28 22:56:24 +01:00
2021-02-18 00:21:25 +01:00
if [[ "${get_data[q]}" ]]; then
query="${get_data[q]}"
query_nice=$(sed -s 's/+/ /g' <<< "${get_data[q]}")
fi
if [[ "${get_data[q]}" ]]; then
data=$(haruhi-dl --ie-key YoutubeSearch "ytsearch30:${get_data[q]}" --flat-playlist -J | jq '.entries[]')
2021-01-28 22:56:24 +01:00
IFS=$'\n'
id=($(jq -r '.id' <<< "$data"))
title=($(jq -r '.title' <<< "$data"))
runtime=($(jq -r '.duration' <<< "$data"))
views=($(jq -r '.view_count' <<< "$data"))
channel=($(jq -r '.channel' <<< "$data"))
channel_id=($(jq -r '.channel_id' <<< "$data"))
unset IFS
for (( i=0; i<${#id[@]}; i++ )); do
2021-02-28 17:43:40 +01:00
strings[results]+="<a href='/watch?v=${id[$i]}'><img src='https://i.ytimg.com/vi/${id[$i]}/mqdefault.jpg'><br>${title[$i]}</a> | ${runtime[$i]} seconds | ${views[$i]} views<br>Uploaded by <a href='/channel/${channel_id[$i]}'>${channel[$i]}</a><br>"
2021-01-28 22:56:24 +01:00
done
else
strings[results]="search for something will 'ya?"
fi
if [[ ! "$(which haruhi-dl)" || $? != "0" ]]; then
strings[results]="Could not fetch search results"
2021-01-28 22:56:24 +01:00
fi
2021-02-28 17:43:40 +01:00
2021-03-01 23:53:15 +01:00
source "${cfg[namespace]}/templates/header.shs"
2021-02-28 17:43:40 +01:00
render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/search.t"