41 lines
1.2 KiB
Bash
Executable file
41 lines
1.2 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
declare -A strings
|
|
|
|
if [[ ${cfg[template]} == 'default' ]]; then
|
|
meta[title]="youtube but not really"
|
|
source templates/head.sh
|
|
fi
|
|
|
|
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 "ytsearch30:${get_data[q]}" --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"))
|
|
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>"
|
|
done
|
|
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_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/search.t"
|