Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove accidental awk and add ci-check for it #1309

Merged
merged 9 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ani-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ jobs:
- uses: actions/checkout@v3
- name: test exec bit
run: test -x "./ani-cli"

check-no-awk:
name: No Awk Allowed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: verify that noone added awk
run: '! grep awk "./ani-cli"'
48 changes: 13 additions & 35 deletions ani-cli
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

version_number="4.8.3"
version_number="4.8.4"

# UI

Expand Down Expand Up @@ -200,26 +200,14 @@ search_anime() {

time_until_next_ep() {
animeschedule="https://animeschedule.net"
schedule_title="$(printf "%s" "$1" | awk '{print tolower($0)}')"
schedule_query="$(printf "%s" "$schedule_title" | sed 's|+|-|g')"
fetched="$(curl -s "$animeschedule/anime/$schedule_query")"

if printf "%s" "$fetched" | grep -q "Not Found"; then
anime_list="$(curl -s "$animeschedule/shows?q=$schedule_title" | awk -F '"' '{print $2}' | grep "$schedule_query" | uniq | grep -v "/anime/")"
for anime in $anime_list; do
fetched="$(curl -s "$animeschedule/anime/$anime")"
main_title="$(printf "%s" "$fetched" | grep 'anime-header-main-title' | grep -v '{' | awk -F '>' '{print $2}' | awk -F '<' '{print $1}')"
english_title="$(printf "%s" "$fetched" | grep 'anime-header-english-title' | grep -v '{' | awk -F '>' '{print $2}' | awk -F '<' '{print $1}')"
ttne="$(printf "%s" "$fetched" | grep 'countdown-time countdown-time-raw' | uniq | awk -F '"' '{print $4}')"
[ -n "$ttne" ] && printf "%s / %s\n%s\n---\n" "$main_title" "$english_title" " - Next episode in: $ttne" | more
[ -z "$ttne" ] && printf "%s / %s\n%s\n---\n" "$main_title" "$english_title" " - Finished" | more
done
else
ttne="$(printf "%s" "$fetched" | grep 'countdown-time countdown-time-raw' | uniq | awk -F '"' '{print $4}')"
[ -n "$ttne" ] && echo "Next episode in: " "$ttne"
[ -z "$ttne" ] && echo "Finished"
fi

curl -s -G "$animeschedule/api/v3/anime" --data-urlencode "q=$1" | sed 's|"id"|\n|g' | sed -nE 's|.*,"route":"([^"]*)","premier.*|\1|p' | while read -r anime; do
data=$(curl -s "$animeschedule/anime/$anime" | sed '1,/"anime-header-list-buttons-wrapper"/d' | sed -nE 's|.*countdown-time-raw" datetime="([^"]*)">.*|Next Raw Release: \1|p;s|.*countdown-time" datetime="([^"]*)">.*|Next Sub Release: \1|p;s|.*english-title">([^<]*)<.*|English Title: \1|p;s|.*main-title".*>([^<]*)<.*|Japanese Title: \1|p')
status="Ongoing"
color="33"
printf "%s\n" "$data"
! (printf "%s\n" "$data" | grep -q "Next Raw Release:") && status="Finished" && color="32"
printf "Status: \033[1;%sm%s\033[0m\n---\n" "$color" "$status"
done
CoolnsX marked this conversation as resolved.
Show resolved Hide resolved
exit 0
}

Expand All @@ -234,10 +222,9 @@ episodes_list() {
# PLAYING

process_hist_entry() {
[ -n "$ttne" ] && ttne="$(printf " - next episode in: %s" "$ttne")"
ep_list=$(episodes_list "$id")
ep_no=$(printf "%s" "$ep_list" | sed -n "/^${ep_no}$/{n;p;}") 2>/dev/null
[ -n "$ep_no" ] && printf "%s\t%s - episode %s%s\n" "$id" "$title" "$ep_no" "$ttne"
[ -n "$ep_no" ] && printf "%s\t%s - episode %s\n" "$id" "$title" "$ep_no"
}

update_history() {
Expand Down Expand Up @@ -450,18 +437,6 @@ case "$search" in
ep_no=$(printf "%s" "$ep_list" | sed -n "/^${ep_no}$/{n;p;}") 2>/dev/null
allanime_title="$(printf "%s" "$title" | cut -d'(' -f1 | tr -d '[:punct:]')"
;;
nextep)
if [ "$use_external_menu" = "0" ]; then
while [ -z "$query" ]; do
printf "\33[2K\r\033[1;36mSearch anime: \033[0m" && read -r query
done
else
[ -z "$query" ] && query=$(printf "" | external_menu "" "Search anime: ")
[ -z "$query" ] && exit 1
fi
query=$(printf "%s" "$query" | sed 's| |+|g')
time_until_next_ep "$query"
;;
*)
if [ "$use_external_menu" = "0" ]; then
while [ -z "$query" ]; do
Expand All @@ -471,6 +446,9 @@ case "$search" in
[ -z "$query" ] && query=$(printf "" | external_menu "" "Search anime: ")
[ -z "$query" ] && exit 1
fi
# for checking new releases by specifying anime name
[ "$search" = "nextep" ] && time_until_next_ep "$query"

query=$(printf "%s" "$query" | sed "s| |+|g")
anime_list=$(search_anime "$query")
[ -z "$anime_list" ] && die "No results found!"
Expand Down
Loading