bashtube/webroot/search.shs
4 raccoons in a trenchcoat. / luna vivian 8f15262d01 search page overhaul
it now looks as good as the feed, the homepage
and the favourites! :3
additionally, the search page now also mentions
your search term, in case you suddenly decide
to leave that tab alone for some reason and come
back to it later, only to no longer know what you
searched for lol
2023-04-20 01:04:03 +02:00

55 lines
1.5 KiB
Bash
Executable file

#!/bin/bash
source "${cfg[namespace]}/code/common.sh"
declare -A meow
if [[ ${cfg[template]} != 'retro' ]]; then
meta[title]="youtube but not really"
#source templates/head.sh
source "${cfg[namespace]}/templates/header.shs"
fi
#https://www.youtube.com/results?search_query=oooo
if [[ "${get_data[search_query]}" ]]; then
query="${get_data[search_query]}"
meow[query]=$(sed -s 's/+/ /g' <<< "${get_data[search_query]}")
meow[?query]=true
query_nice=$(sed -s 's/+/ /g' <<< "${get_data[search_query]}")
fi
if [[ "${get_data[search_query]}" ]]; then
data=$(yt-dlp "ytsearch30:${get_data[search_query]}" --flat-playlist -J | jq '.entries[]')
IFS=$'\n'
id=($(jq -r '.id' <<< "$data"))
title=($(jq -r '.title' <<< "$data"))
runtime=($(jq -r '.duration' <<< "$data"))
views=($(jq -r '.view_count' <<< "$data" | format_numbers))
channel=($(jq -r '.channel' <<< "$data"))
channel_id=($(jq -r '.channel_id' <<< "$data"))
unset IFS
declare -A strings
nested_declare nyaa
for (( i=0; i<${#id[@]}; i++ )); do
strings[id]="${id[$i]}"
strings[title]="${title[$i]}"
strings[runtime]="$(date -d "@${runtime[$i]}" "+%H:%M:%S")"
strings[views]="${views[$i]}"
strings[channel_id]="${channel_id[$i]}"
strings[channel]="${channel[$i]}"
nested_add nyaa strings
done
meow[_results]=nyaa
else
strings[results]="search for something will 'ya?"
fi
#if [[ ! "$(which haruhi-dl)" || $? != "0" ]]; then
# strings[results]="Could not fetch search results"
#fi
render meow "${cfg[namespace]}/templates/themes/${cfg[template]}/search.html"