pystardust / ani-cli

A cli tool to browse and play anime
GNU General Public License v3.0
7.89k stars 542 forks source link

feat: countdown to next episode #1301

Closed llComodino closed 6 months ago

llComodino commented 6 months ago

Pull Request Template

Type of change

Description

Implementation of a function to get the countdown to the next episode Also changed #!/bin/sh to #!/usr/bin/env sh to make it more portable (sorry if I wasn't supposed to)

I had originally opened a PR, but then noticed unwanted behavior for some japanese titles

Now it works with the vast majority of the titles, though some have really different names across websites, therefore the countdown is not found (an example is One Piece, 1P on allanime, one-piece on animeschedule Pretty sure this can be corrected with some thinkering but I haven't been able to

It uses https://animeschedule.net/ to find titles and their release date

The countdown is shown as the last episode in the episode list

Checklist

Additional Testcases

port19x commented 6 months ago

This could be a useful feature, I'll make a more thorough review later

port19x commented 6 months ago

The commit messages :joy: :ok_hand:

llComodino commented 6 months ago

Sadly it's true, I've got a funny commit history for my CS class ...

llComodino commented 6 months ago

In the current state, running ani-cli -c -N prints countdowns for next episodes. I'm currently figuring out how to conditionally print, only for animes with a next ep - Next episode in: %s

For instance, at the moment an history list would look like this: 1 anime_still_in_progress - episode %s - Next episode in: %s 2 anime_finished - episode %s - Next episode in:

I tried to chain [ "$countdown" = "1" ] && [ -z "$(time_until_next_ep "$title")" which seemed most logical, since a finished anime should return nothing

Maybe I'm missing something 😕

Derisis13 commented 6 months ago

Unless you want to keep entertaining the world with your comment messages, I recommend you to only push after testing (or at least running) your code. As long as your changes are local, you can safely use git commit --amend to fix your typos without creating new commits.

Also in case you're unaware, you can turn on an explicite trace by running your program with sh -x ani-cli, this might help you iron out the details.

llComodino commented 6 months ago

Sorry for that, pushing hastily is a bad habit of mine 😅 I think I missed some errors because I was running shellcheck with different flags

llComodino commented 6 months ago

On it

llComodino commented 6 months ago

Actually, since the -N just needs to return the countdown and terminate, I should just write a proper scraper for animeschedule

I haven't done it before because it would have slowed down the execution before prompting for the episodes, but but given that it doesn't need to anymore...

Do I close this PR and make another one when it's done?

llComodino commented 6 months ago

I hope you'll find this version ok.

Now running with the -N gets results for everything you search for

If you insert a query that does not return 1 result you will see every result containing your query (english and japanese titles) and it's status (either finished or the countdown)

port19x commented 6 months ago

I intend to test this later this evening, thanks for the effort

port19x commented 6 months ago

I like how it behaves now, thanks for adapting it

testing & output
``` [port19@archlinux ani-cli]$ ./ani-cli -N Checking dependencies... Search anime: boruto BORUTO: NARUTO THE MOVIE / - Finished --- BORUTO: NARUTO NEXT GENERATIONS / - Finished --- Boruto: Jump Festa 2016 Special / - Finished --- BORUTO: NARUTO THE MOVIE - Naruto ga Hokage ni Natta Hi / Boruto: Naruto the Movie - The Day Naruto Became Hokage - Finished --- [port19@archlinux ani-cli]$ ./ani-cli -N boruto Checking dependencies... BORUTO: NARUTO THE MOVIE / - Finished --- BORUTO: NARUTO NEXT GENERATIONS / - Finished --- Boruto: Jump Festa 2016 Special / - Finished --- BORUTO: NARUTO THE MOVIE - Naruto ga Hokage ni Natta Hi / Boruto: Naruto the Movie - The Day Naruto Became Hokage - Finished --- [port19@archlinux ani-cli]$ ./ani-cli -N flcl Checking dependencies... Finished [port19@archlinux ani-cli]$ ./ani-cli -N flcl progressive Checking dependencies... Finished [port19@archlinux ani-cli]$ ./ani-cli -N one piece Checking dependencies... Next episode in: 4d 2h 47m ```
port19x commented 6 months ago

Looks ready, but I'll sleep on it

llComodino commented 6 months ago

As you please, thanks for letting me contribute to this

port19x commented 6 months ago

Bonus points for implementing this with external menu compatibility as well as no fzf required. Good work

port19x commented 6 months ago

Btw image

port19x commented 6 months ago

Check out #1309 for an awk-free edition