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

fix: avoids reencoding the + while running time_until_next_ep #1445

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

HirschBerge
Copy link
Contributor

@HirschBerge HirschBerge commented Oct 18, 2024

Pull Request Template

Type of change

  • Bug fix
  • Feature
  • Documentation update

Description

Hey, it's me again. ha. I hope this one is simpler and a bit more well tested.

I noticed that checking for the next episode countdown only works when you use -N or --nextep-countdown by itself and did not provide a search directly in the cli command.
I narrowed down the reasoning to two things:
This snippet automatically replaces spaces with +

ani-cli/ani-cli

Line 435 in f2e8112

*) query="$(printf "%s" "$query $1" | sed "s|^ ||;s| |+|g")" ;;

and the curl in the function re-encodes the + to become %2B when I look the verbose curl output.

ani-cli/ani-cli

Line 221 in f2e8112

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

The only reason that it works at all when using the built-in query picker is because the function is called one line before that query gets its spaces converted to +'s. I suspect this was known about when the feature was added due to the function call placement, but the author didn't realize it didn't work for queries from the cli

ani-cli/ani-cli

Lines 479 to 481 in f2e8112

[ "$search" = "nextep" ] && time_until_next_ep "$query"
query=$(printf "%s" "$query" | sed "s| |+|g")

I do not know a lot about curl, so Idk if there's an easier way to avoid re-encoding the + during the call, I tried just removing the flag, but that broke harder, so I just decided to use sed to return the spaces.

Note, I didn't test any anime that have a literal + in the title, I don't know if that exists even, so there's that.

Checklist

  • any anime playing
  • bumped version

I don't really want to go through and click all of these, i only changed the -N function so it'll all work

  • next, prev and replay work
  • --nextep-countdownworks
  • -c history and continue work
  • -d downloads work
  • -s syncplay works
  • -q quality works
  • -v vlc works
  • -e select episode works
  • -S select index works
  • -r range selection works
  • --skip ani-skip works
  • --skip-title ani-skip title argument works
  • --no-detach no detach works
  • --dub and regular (sub) mode both work
  • all providers return links (not necessarily on a single anime, use debug mode to confirm)

  • -h help info is up to date
  • Readme is up to date
  • Man page is up to date

Additional Testcases

  • The safe bet: One Piece
  • Episode 0: Saenai Heroine no Sodatekata ♭
  • Unicode: Saenai Heroine no Sodatekata ♭
  • Non-whole episodes: Tensei shitara slime datta ken (ep. 24.5, ep. 24.9)

the literal `+` representing spaces are encodes as %2B and they mangle
the curl api call
@HirschBerge HirschBerge changed the title fix:avoids reencoding the + while running time_until_next_ep fix: avoids reencoding the + while running time_until_next_ep Oct 18, 2024
@port19x
Copy link
Collaborator

port19x commented Nov 4, 2024

Just seeing this now. It's on my radar, but it might take a couple more days until I take some time to fully review the issue and make sure there is no related problems

@CoolnsX
Copy link
Collaborator

CoolnsX commented Nov 11, 2024

I think passing the query directly in url instead of --data-urlencode should work

@CoolnsX
Copy link
Collaborator

CoolnsX commented Nov 11, 2024

or just replace --data-urlencode to --data-raw in that particular curl will also work

@CoolnsX
Copy link
Collaborator

CoolnsX commented Nov 11, 2024

and you can remove that avoids_reencoding="$(printf "%s" "$1" | sed 's/+/ /g')" reassignment and it will be only 1 line change

just do --

  • either
     curl -s -G "$animeschedule/api/v3/anime" --data-raw "q=$1"
  • or
     curl -s -G "$animeschedule/api/v3/anime?q=$1"

both works

@HirschBerge
Copy link
Contributor Author

Nice! Good suggestion, though waking up to like 8 notifications did make me concerned, lol

@CoolnsX
Copy link
Collaborator

CoolnsX commented Nov 11, 2024

LGTM..

@CoolnsX
Copy link
Collaborator

CoolnsX commented Nov 11, 2024

Will test once I reach home

@HirschBerge
Copy link
Contributor Author

Is working on my end FWIW

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants