bashtube/webroot/search.shs

53 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
source "${cfg[namespace]}/code/common.sh"
declare -A meow
if [[ ${cfg[template]} == 'default' ]]; then
meta[title]="youtube but not really"
source templates/head.sh
fi
#https://www.youtube.com/results?search_query=oooo
if [[ "${get_data[search_query]}" ]]; then
query="${get_data[search_query]}"
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]="${runtime[$i]}"
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
source "${cfg[namespace]}/templates/header.shs"
render meow "${cfg[namespace]}/templates/themes/${cfg[template]}/search.t"