update ani-cli to allow passing in search query

This commit is contained in:
ksyasuda 2022-02-04 17:58:08 -08:00
parent ebc8587e6f
commit 7c71e05317

29
ani-cli
View File

@ -405,9 +405,11 @@ find_media() {
##################### #####################
get_search_query() { get_search_query() {
if [ $# -gt 0 ]; then
query="${*// /-}"
elif [ "$IS_ROFI" -eq 1 ]; then
stmt="SELECT DISTINCT id || '. ' || anime_name FROM search_history ORDER BY search_date DESC;" stmt="SELECT DISTINCT id || '. ' || anime_name FROM search_history ORDER BY search_date DESC;"
msg="Choose from list of searched anime below, or enter a unique name of an anime to search for" msg="Choose from list of searched anime below, or enter a unique name of an anime to search for"
if [ "$IS_ROFI" -eq 1 ]; then
query=$(rofi -dpi "$DPI" -dmenu -l 15 -p "Search Anime:" \ query=$(rofi -dpi "$DPI" -dmenu -l 15 -p "Search Anime:" \
-mesg "$(generate_span "$msg")" \ -mesg "$(generate_span "$msg")" \
-config "$ROFI_CFG" < <(run_stmt "$stmt")) -config "$ROFI_CFG" < <(run_stmt "$stmt"))
@ -667,16 +669,17 @@ open_episode() {
stream() { stream() {
lg "Running stream()" lg "Running stream()"
if [ "$#" -eq 0 ]; then
get_search_query get_search_query
searched=0 else
# check if anime has been searched before get_search_query "$*"
fi
anime_id="${query// /}" anime_id="${query// /}"
[ -z "$anime_id" ] && die "No anime selected or queried" [ -z "$anime_id" ] && die "No anime selected or queried"
searched=0
lg "Checking if anime: $anime_id has been searched before..." lg "Checking if anime: $anime_id has been searched before..."
check_db "search" "$anime_id" if check_db "search" "$anime_id"; then
searched="$?" lg "$anime_id has been searched before"
lg "Searched before: $searched"
if [ "$searched" -eq 0 ]; then
search_results=$(search_anime $query) # want word splitting to account for both input cases search_results=$(search_anime $query) # want word splitting to account for both input cases
[ -z "$search_results" ] && die "No search results found" [ -z "$search_results" ] && die "No search results found"
lg "SEARCH RESULTS: $search_results" lg "SEARCH RESULTS: $search_results"
@ -684,12 +687,10 @@ stream() {
die "No anime selection found" die "No anime selection found"
fi fi
else else
# if the query is a previous search # skip search_anime function and assign $query if previously searched
# skip search_anime function and assign $query
anime_id="${query// /}"
selection_id="$anime_id" selection_id="$anime_id"
insert_history "search" "$anime_id" & insert_history "search" "$anime_id" &
read -r last_ep_number <<< "$(search_eps "$selection_id")" read -r last_ep_number < <(search_eps "$anime_id")
fi fi
episode_selection episode_selection
} }
@ -796,7 +797,6 @@ parse_args() {
;; ;;
esac esac
done done
shift $((OPTIND - 1))
} }
######## ########
@ -806,7 +806,7 @@ main() {
case $scrape in case $scrape in
query) query)
BASE_URL="$(curl -s -L -o /dev/null -w "%{url_effective}\n" https://gogoanime.cm)" BASE_URL="$(curl -s -L -o /dev/null -w "%{url_effective}\n" https://gogoanime.cm)"
stream stream "$@"
;; ;;
history) history)
BASE_URL="$(curl -s -L -o /dev/null -w "%{url_effective}\n" https://gogoanime.cm)" BASE_URL="$(curl -s -L -o /dev/null -w "%{url_effective}\n" https://gogoanime.cm)"
@ -979,4 +979,5 @@ main() {
dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi" "git" "aria2c" dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi" "git" "aria2c"
parse_args "$@" parse_args "$@"
main shift $((OPTIND - 1))
main "$@"