From 61db9aeea68b433447b075e96a36c759ea52b36d Mon Sep 17 00:00:00 2001 From: Pixelizer09 <153782533+Pixelizer09@users.noreply.github.com> Date: Thu, 21 Nov 2024 10:57:02 +0800 Subject: [PATCH 1/9] Update data.py --- fastanime/Utility/data.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fastanime/Utility/data.py b/fastanime/Utility/data.py index 1f4b94f..6b0b2d4 100644 --- a/fastanime/Utility/data.py +++ b/fastanime/Utility/data.py @@ -12,7 +12,10 @@ anime_normalizer_raw = { "Re:Zero kara Hajimeru Isekai Seikatsu Season 3": "Re:Zero kara Hajimeru Isekai Seikatsu 3rd Season", }, "hianime": {"My Star": "Oshi no Ko"}, - "animepahe": {"Azumanga Daiou The Animation": "Azumanga Daioh"}, + "animepahe": { + "Azumanga Daiou The Animation": "Azumanga Daioh", + "Mairimashita! Iruma-kun 2": "Mairimashita! Iruma-kun 2nd Season" + }, "nyaa": {}, "yugen": {}, } From 33c06eab0ae9b769d8a2fbca23542cfe5a3cb537 Mon Sep 17 00:00:00 2001 From: Benex <81157281+Benex254@users.noreply.github.com> Date: Thu, 21 Nov 2024 18:07:13 +0300 Subject: [PATCH 2/9] Update README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e643b29..dd78a05 100644 --- a/README.md +++ b/README.md @@ -28,14 +28,20 @@ My Rice - + + **Anilist results menu:** ![image](https://github.com/user-attachments/assets/240023a7-7e4e-47dd-80ff-017d65081ee1) +**Episodes menu preview:** ![image](https://github.com/user-attachments/assets/580f86ef-326f-4ab3-9bd8-c1cb312fbfa6) **Without preview images enabled:** ![image](https://github.com/user-attachments/assets/e1248a85-438f-4758-ae34-b0e0b224addd) +**Desktop notifications + episodes menu without image preview:** +![image](https://github.com/user-attachments/assets/111cf33e-0724-473a-a30d-65b0c20b5bd6) + +
From fe8cda094c9c1c6580087ecfd497d4287063a331 Mon Sep 17 00:00:00 2001 From: Benex <81157281+Benex254@users.noreply.github.com> Date: Thu, 21 Nov 2024 18:55:55 +0300 Subject: [PATCH 3/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dd78a05..fc35dfb 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ ![image](https://github.com/user-attachments/assets/e1248a85-438f-4758-ae34-b0e0b224addd) **Desktop notifications + episodes menu without image preview:** -![image](https://github.com/user-attachments/assets/111cf33e-0724-473a-a30d-65b0c20b5bd6) +![image](https://github.com/user-attachments/assets/b7802ef1-ca0d-45f5-a13a-e39c96a5d499)
From b10d9dc39aaff3beef0cc56dd518433ba48d3125 Mon Sep 17 00:00:00 2001 From: Pixelizer09 <153782533+Pixelizer09@users.noreply.github.com> Date: Fri, 22 Nov 2024 11:27:29 +0800 Subject: [PATCH 4/9] Update data.py --- fastanime/Utility/data.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fastanime/Utility/data.py b/fastanime/Utility/data.py index 6b0b2d4..ccef0ab 100644 --- a/fastanime/Utility/data.py +++ b/fastanime/Utility/data.py @@ -14,7 +14,8 @@ anime_normalizer_raw = { "hianime": {"My Star": "Oshi no Ko"}, "animepahe": { "Azumanga Daiou The Animation": "Azumanga Daioh", - "Mairimashita! Iruma-kun 2": "Mairimashita! Iruma-kun 2nd Season" + "Mairimashita! Iruma-kun 2nd Season": "Mairimashita! Iruma-kun 2", + "Mairimashita! Iruma-kun 3rd Season": "Mairimashita! Iruma-kun 3" }, "nyaa": {}, "yugen": {}, From 812d0110a78b45ee058b55e9b7a9b66e835679a8 Mon Sep 17 00:00:00 2001 From: Benex <81157281+Benex254@users.noreply.github.com> Date: Fri, 22 Nov 2024 08:41:04 +0300 Subject: [PATCH 5/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fc35dfb..f39c0b0 100644 --- a/README.md +++ b/README.md @@ -336,7 +336,7 @@ fastanime --manga search -t #### The anilist command :fire: :fire: :fire: -Stream, browse, and discover anime efficiently from the terminal using the [AniList API](https://github.com/AniList/ApiV2-GraphQL-Docs). +Uses the [AniList API](https://github.com/AniList/ApiV2-GraphQL-Docs) to create a terminal anilist client which is then intergrated with the scraping capabilities of the project. ##### Running without any subcommand From 7b6cc48b904176acb94dc0ea4e1a4912d4f25a3a Mon Sep 17 00:00:00 2001 From: Benex <81157281+Benexl@users.noreply.github.com> Date: Fri, 22 Nov 2024 09:56:26 +0300 Subject: [PATCH 6/9] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f39c0b0..5cac883 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ If you have any difficulty consult for help on the [discord channel](https://dis ![Static Badge](https://img.shields.io/badge/NixOs-black?style=flat&logo=nixos) ```bash -nix profile install github:Benex254/fastanime +nix profile install github:Benexl/fastanime ``` ### Installation using your favourite package manager @@ -195,7 +195,7 @@ Requirements: To build from the source, follow these steps: -1. Clone the repository: `git clone https://github.com/FastAnime/FastAnime.git --depth 1` +1. Clone the repository: `git clone https://github.com/Benexl/FastAnime.git --depth 1` 2. Navigate into the folder: `cd FastAnime` 3. Then build and Install the app: From 1c367c8aa1054b2f725b091af9252eb16604a044 Mon Sep 17 00:00:00 2001 From: benex Date: Fri, 22 Nov 2024 22:28:12 +0300 Subject: [PATCH 7/9] feat(anilist-interface): add resume flag to auto continue from the most recent anime --- fastanime/cli/commands/anilist/__init__.py | 37 +++++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/fastanime/cli/commands/anilist/__init__.py b/fastanime/cli/commands/anilist/__init__.py index 6ce7fc5..dbb2be9 100644 --- a/fastanime/cli/commands/anilist/__init__.py +++ b/fastanime/cli/commands/anilist/__init__.py @@ -80,15 +80,13 @@ commands = { fastanime --log-file anilist notifier """, ) +@click.option("--resume", is_flag=True, help="Resume from the last session") @click.pass_context -def anilist(ctx: click.Context): +def anilist(ctx: click.Context, resume: bool): from typing import TYPE_CHECKING from ....anilist import AniList from ....AnimeProvider import AnimeProvider - from ...interfaces.anilist_interfaces import ( - fastanime_main_menu as anilist_interface, - ) if TYPE_CHECKING: from ...config import Config @@ -98,4 +96,33 @@ def anilist(ctx: click.Context): AniList.update_login_info(user, user["token"]) if ctx.invoked_subcommand is None: fastanime_runtime_state = FastAnimeRuntimeState() - anilist_interface(ctx.obj, fastanime_runtime_state) + if resume: + from ...interfaces.anilist_interfaces import ( + anime_provider_search_results_menu, + ) + + if not config.user_data["recent_anime"]: + click.echo("No recent anime found", err=True, color=True) + return + fastanime_runtime_state.anilist_results_data = { + "data": {"Page": {"media": config.user_data["recent_anime"]}} + } + + fastanime_runtime_state.selected_anime_anilist = config.user_data[ + "recent_anime" + ][0] + fastanime_runtime_state.selected_anime_id_anilist = config.user_data[ + "recent_anime" + ][0]["id"] + fastanime_runtime_state.selected_anime_title_anilist = ( + config.user_data["recent_anime"][0]["title"]["romaji"] + or config.user_data["recent_anime"][0]["title"]["english"] + ) + anime_provider_search_results_menu(config, fastanime_runtime_state) + + else: + from ...interfaces.anilist_interfaces import ( + fastanime_main_menu as anilist_interface, + ) + + anilist_interface(ctx.obj, fastanime_runtime_state) From 27b4422ef3e2e7d95f63ef3c202d932382b000d1 Mon Sep 17 00:00:00 2001 From: benex Date: Fri, 22 Nov 2024 23:21:32 +0300 Subject: [PATCH 8/9] feat(requests_cacher): make more reliable by ordering the results by created_at --- fastanime/libs/common/requests_cacher.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/fastanime/libs/common/requests_cacher.py b/fastanime/libs/common/requests_cacher.py index b20e9fa..d7ec5ac 100644 --- a/fastanime/libs/common/requests_cacher.py +++ b/fastanime/libs/common/requests_cacher.py @@ -80,7 +80,8 @@ class CachedRequestsSession(requests.Session): response_headers TEXT, data BLOB, redirection_policy INT, - cache_expiry INTEGER + cache_expiry INTEGER, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP )""" ) @@ -117,6 +118,8 @@ class CachedRequestsSession(requests.Session): url = ? AND redirection_policy = ? AND cache_expiry > ? + ORDER BY created_at DESC + LIMIT 1 """, (url, redirection_policy, int(time.time())), ) @@ -162,8 +165,15 @@ class CachedRequestsSession(requests.Session): logger.debug("Caching the current request") cursor.execute( f""" - INSERT INTO {self.table_name} - VALUES (?, ?, ?, ?, ?, ?, ?) + INSERT INTO {self.table_name} ( + url, + status_code, + request_headers, + response_headers, + data, + redirection_policy, + cache_expiry + ) VALUES (?, ?, ?, ?, ?, ?, ?) """, ( url, From 7cd97c78b18400e8808b86fc87bf0bcc5b8f96e6 Mon Sep 17 00:00:00 2001 From: benex Date: Fri, 22 Nov 2024 23:21:58 +0300 Subject: [PATCH 9/9] feat(config): make the max_cache_lifetime configurable --- fastanime/cli/config.py | 14 ++++++++++++++ fastanime/libs/anime_provider/base_provider.py | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/fastanime/cli/config.py b/fastanime/cli/config.py index ef56893..32bdd68 100644 --- a/fastanime/cli/config.py +++ b/fastanime/cli/config.py @@ -51,6 +51,7 @@ class Config(object): "image_previews": "True" if S_PLATFORM != "win32" else "False", "normalize_titles": "True", "notification_duration": "2", + "max_cache_lifetime": "03:00:00", "player": "mpv", "preferred_history": "local", "preferred_language": "english", @@ -128,6 +129,14 @@ class Config(object): self.notification_duration = self.configparser.getint( "general", "notification_duration" ) + max_cache_lifetime = list( + map(int, self.configparser.get("general", "max_cache_lifetime").split(":")) + ) + self.max_cache_lifetime = ( + max_cache_lifetime[0] * 86400 + + max_cache_lifetime[1] * 3600 + + max_cache_lifetime[2] * 60 + ) self.player = self.configparser.get("stream", "player") self.preferred_history = self.configparser.get("stream", "preferred_history") self.preferred_language = self.configparser.get("general", "preferred_language") @@ -396,6 +405,11 @@ force_forward_tracking = {self.force_forward_tracking} # from the cached_requests_db cache_requests = {self.cache_requests} +# the max lifetime for a cached request +# defaults to 3days = 03:00:00 +# this is the time after which a cached request will be deleted (technically : ) +max_cache_lifetime = {self.max_cache_lifetime} + # whether to use a persistent store (basically a sqlitedb) for storing some data the provider requires # to enable a seamless experience [true/false] # this option exists primarily because i think it may help in the optimization diff --git a/fastanime/libs/anime_provider/base_provider.py b/fastanime/libs/anime_provider/base_provider.py index 8de9941..ad8c956 100644 --- a/fastanime/libs/anime_provider/base_provider.py +++ b/fastanime/libs/anime_provider/base_provider.py @@ -19,7 +19,10 @@ class AnimeProvider: from ..common.requests_cacher import CachedRequestsSession self.session = CachedRequestsSession( - os.path.join(APP_CACHE_DIR, "cached_requests.db") + os.path.join(APP_CACHE_DIR, "cached_requests.db"), + max_lifetime=int( + os.environ.get("FASTANIME_MAX_CACHE_LIFETIME", 259200) + ), ) else: self.session = requests.session()