bashtube/webroot/search.shs

55 lines
1.5 KiB
Plaintext
Raw Normal View History

2021-01-28 22:56:24 +01:00
#!/bin/bash
source "${cfg[namespace]}/code/common.sh"
2021-01-28 22:56:24 +01:00
declare -A meow
2021-01-28 22:56:24 +01:00
if [[ ${cfg[template]} != 'retro' ]]; then
2021-02-28 17:43:40 +01:00
meta[title]="youtube but not really"
#source templates/head.sh
source "${cfg[namespace]}/templates/header.shs"
2021-02-28 17:43:40 +01:00
fi
2021-01-28 22:56:24 +01:00
2021-06-03 21:48:10 +02:00
#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
2021-06-03 21:48:10 +02:00
query_nice=$(sed -s 's/+/ /g' <<< "${get_data[search_query]}")
2021-02-18 00:21:25 +01:00
fi
2021-06-03 21:48:10 +02:00
if [[ "${get_data[search_query]}" ]]; then
data=$(yt-dlp "ytsearch30:${get_data[search_query]}" --flat-playlist -J | jq '.entries[]')
2021-01-28 22:56:24 +01:00
IFS=$'\n'
2021-01-28 22:56:24 +01:00
id=($(jq -r '.id' <<< "$data"))
title=($(jq -r '.title' <<< "$data"))
runtime=($(jq -r '.duration' <<< "$data"))
views=($(jq -r '.view_count' <<< "$data" | format_numbers))
2021-01-28 22:56:24 +01:00
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
2021-01-28 22:56:24 +01:00
done
meow[_results]=nyaa
2021-01-28 22:56:24 +01:00
else
strings[results]="search for something will 'ya?"
fi
#if [[ ! "$(which haruhi-dl)" || $? != "0" ]]; then
# strings[results]="Could not fetch search results"
#fi
2021-02-28 17:43:40 +01:00
render meow "${cfg[namespace]}/templates/themes/${cfg[template]}/search.html"