* search: move to the new templating engine

merge-requests/6/head
Dominique Liberda 2022-11-29 02:45:15 -05:00
parent da609de918
commit 7e4e26f0f2
2 changed files with 27 additions and 10 deletions

View File

@ -1 +1,8 @@
{{.results}}
{{start _results}}
<a href='/watch?v={{.id}}'>
<img src='https://i.ytimg.com/vi/{{.id}}/mqdefault.jpg'><br>{{.title}}</a>
| {{.runtime}} seconds | {{.views}} views<br>
Uploaded by <a href='/channel/{{.channel_id}}'>{{.channel}}</a><br>
{{end _results}}

View File

@ -1,6 +1,6 @@
#!/bin/bash
declare -A strings
declare -A meow
if [[ ${cfg[template]} == 'default' ]]; then
meta[title]="youtube but not really"
@ -14,28 +14,38 @@ if [[ "${get_data[search_query]}" ]]; then
fi
if [[ "${get_data[search_query]}" ]]; then
data=$(haruhi-dl --ie-key YoutubeSearch "ytsearch30:${get_data[search_query]}" --flat-playlist -J | jq '.entries[]')
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" | xargs printf "%'d\n"))
views=($(jq -r '.view_count' <<< "$data" | xargs printf "%d\n"))
channel=($(jq -r '.channel' <<< "$data"))
channel_id=($(jq -r '.channel_id' <<< "$data"))
unset IFS
for (( i=0; i<${#id[@]}; i++ )); do
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>"
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
#if [[ ! "$(which haruhi-dl)" || $? != "0" ]]; then
# strings[results]="Could not fetch search results"
#fi
source "${cfg[namespace]}/templates/header.shs"
render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/search.t"
render meow "${cfg[namespace]}/templates/themes/${cfg[template]}/search.t"