From 9512c3530abd7494c9fb63d4daec9f7413ce3f91 Mon Sep 17 00:00:00 2001 From: benex Date: Sun, 24 Nov 2024 14:43:43 +0300 Subject: [PATCH 1/3] feat: check for updates after every 12hrs --- fastanime/cli/__init__.py | 78 +++++++++++++++++++++------------------ fastanime/cli/config.py | 7 +++- 2 files changed, 49 insertions(+), 36 deletions(-) diff --git a/fastanime/cli/__init__.py b/fastanime/cli/__init__.py index f51829a..32f480f 100644 --- a/fastanime/cli/__init__.py +++ b/fastanime/cli/__init__.py @@ -226,44 +226,52 @@ def run_cli( from .config import Config ctx.obj = Config() - # TODO: only check once per week or day - # so as to not hit api limit - # for now i have disabled it - if ctx.obj.check_for_updates and ctx.invoked_subcommand != "completions" and False: - from .app_updater import check_for_updates - import sys + if ctx.obj.check_for_updates and ctx.invoked_subcommand != "completions": + import time - print("Checking for updates...", file=sys.stderr) - print("So you can enjoy the latest features and bug fixes", file=sys.stderr) - print( - "You can disable this by setting check_for_updates to False in the config", - file=sys.stderr, - ) - is_latest, github_release_data = check_for_updates() - if not is_latest: - from rich.console import Console - from rich.markdown import Markdown - from .app_updater import update_app - from rich.prompt import Confirm + last_update = ctx.obj.user_data["meta"]["last_updated"] + now = time.time() + # checks after every 12 hours + if (now - last_update) > 43200: + ctx.obj.user_data["meta"]["last_updated"] = now + ctx.obj._update_user_data() - def _print_release(release_data): - console = Console() - body = Markdown(release_data["body"]) - tag = github_release_data["tag_name"] - tag_title = release_data["name"] - github_page_url = release_data["html_url"] - console.print(f"Release Page: {github_page_url}") - console.print(f"Tag: {tag}") - console.print(f"Title: {tag_title}") - console.print(body) + from .app_updater import check_for_updates + import sys - if Confirm.ask( - "A new version of fastanime is available, would you like to update?" - ): - _, release_json = update_app() - print("Successfully updated") - _print_release(release_json) - exit(0) + print("Checking for updates...", file=sys.stderr) + print("So you can enjoy the latest features and bug fixes", file=sys.stderr) + print( + "You can disable this by setting check_for_updates to False in the config", + file=sys.stderr, + ) + is_latest, github_release_data = check_for_updates() + if not is_latest: + from rich.console import Console + from rich.markdown import Markdown + from .app_updater import update_app + from rich.prompt import Confirm + + def _print_release(release_data): + console = Console() + body = Markdown(release_data["body"]) + tag = github_release_data["tag_name"] + tag_title = release_data["name"] + github_page_url = release_data["html_url"] + console.print(f"Release Page: {github_page_url}") + console.print(f"Tag: {tag}") + console.print(f"Title: {tag_title}") + console.print(body) + + if Confirm.ask( + "A new version of fastanime is available, would you like to update?" + ): + _, release_json = update_app() + print("Successfully updated") + _print_release(release_json) + exit(0) + else: + print("You are using the latest version of fastanime", file=sys.stderr) ctx.obj.manga = manga if log: diff --git a/fastanime/cli/config.py b/fastanime/cli/config.py index b9e19d5..3ad3be1 100644 --- a/fastanime/cli/config.py +++ b/fastanime/cli/config.py @@ -29,7 +29,12 @@ class Config(object): "https://anilist.co/api/v2/oauth/authorize?client_id=20148&response_type=token" ) anime_provider: "AnimeProvider" - user_data = {"recent_anime": [], "animelist": [], "user": {}} + user_data = { + "recent_anime": [], + "animelist": [], + "user": {}, + "meta": {"last_updated": 0}, + } default_config = { "auto_next": "False", "auto_select": "True", From a0f28ddf6d723d4f20c2d2c0c1b341ad90632ae8 Mon Sep 17 00:00:00 2001 From: benex Date: Sun, 24 Nov 2024 14:55:38 +0300 Subject: [PATCH 2/3] feat(cli): don't check for update if running notifier --- fastanime/cli/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fastanime/cli/__init__.py b/fastanime/cli/__init__.py index 32f480f..fc92b76 100644 --- a/fastanime/cli/__init__.py +++ b/fastanime/cli/__init__.py @@ -222,11 +222,16 @@ def run_cli( fresh_requests, ): import os + import sys from .config import Config ctx.obj = Config() - if ctx.obj.check_for_updates and ctx.invoked_subcommand != "completions": + if ( + ctx.obj.check_for_updates + and ctx.invoked_subcommand != "completions" + and "notifier" not in sys.argv + ): import time last_update = ctx.obj.user_data["meta"]["last_updated"] @@ -237,7 +242,6 @@ def run_cli( ctx.obj._update_user_data() from .app_updater import check_for_updates - import sys print("Checking for updates...", file=sys.stderr) print("So you can enjoy the latest features and bug fixes", file=sys.stderr) From 320e3799d3e7c448e91c6debb553e4a87aa0158a Mon Sep 17 00:00:00 2001 From: benex Date: Sun, 24 Nov 2024 15:05:33 +0300 Subject: [PATCH 3/3] chore: update username --- README.md | 12 +++++------- fastanime/__init__.py | 2 +- fastanime/cli/config.py | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a184aa9..d68472b 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,8 @@ My Rice - **Anilist results menu:** - ![image](https://github.com/user-attachments/assets/240023a7-7e4e-47dd-80ff-017d65081ee1) +**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) @@ -41,7 +41,6 @@ **Desktop notifications + episodes menu without image preview:** ![image](https://github.com/user-attachments/assets/b7802ef1-ca0d-45f5-a13a-e39c96a5d499) -
@@ -729,7 +728,6 @@ fastanime serve fastanime serve --host --port ``` - ### MPV specific commands The project now allows on the fly media controls directly from mpv. This means you can go to the next or previous episode without the window ever closing thus offering a seamless experience. @@ -855,7 +853,7 @@ player = mpv We welcome your issues and feature requests. However, due to time constraints, I currently do not plan to add another provider. But if you are willing to add one yourself pr's are welcome. -If you find an anime title that does not correspond with a provider or is just weird just [edit the data file](https://github.com/FastAnime/FastAnime/blob/master/fastanime/Utility/data.py) and open a pr, i will ignore issues 😝. +If you find an anime title that does not correspond with a provider or is just weird just [edit the data file](https://github.com/Benexl/FastAnime/blob/master/fastanime/Utility/data.py) and open a pr, i will ignore issues 😝. ## Receiving Support @@ -872,7 +870,7 @@ For inquiries, join our [Discord Server](https://discord.gg/HBEmAwvbHV). More pr's less issues 🙃 Those who contribute at least five times will be able to make changes to the repo without my review. -Show your support by starring the GitHub repository or [buying me a coffee](https://ko-fi.com/benex254). +Show your support by starring the GitHub repository or [buying me a coffee](https://ko-fi.com/benexl). ## Disclaimer @@ -880,4 +878,4 @@ Show your support by starring the GitHub repository or [buying me a coffee](http > > This project currently scrapes allanime, hianime, nyaa, yugen and animepahe. > The developer(s) of this application does not have any affiliation with the content providers available, and this application hosts zero content. -> [DISCLAIMER](https://github.com/Benex254/FastAnime/blob/master/DISCLAIMER.md) +> [DISCLAIMER](https://github.com/Benexl/FastAnime/blob/master/DISCLAIMER.md) diff --git a/fastanime/__init__.py b/fastanime/__init__.py index c8bbc66..80c383b 100644 --- a/fastanime/__init__.py +++ b/fastanime/__init__.py @@ -9,7 +9,7 @@ if sys.version_info < (3, 10): __version__ = "v2.8.3" APP_NAME = "FastAnime" -AUTHOR = "Benex254" +AUTHOR = "Benexl" GIT_REPO = "github.com" REPO = f"{GIT_REPO}/{AUTHOR}/{APP_NAME}" diff --git a/fastanime/cli/config.py b/fastanime/cli/config.py index 3ad3be1..8df9224 100644 --- a/fastanime/cli/config.py +++ b/fastanime/cli/config.py @@ -480,7 +480,7 @@ auto_next = {self.auto_next} # But 99% of the time will be accurate # if this happens just turn off auto_select in the menus or from the commandline # and manually select the correct anime title -# edit this file +# edit this file # and to the dictionary of the provider # the provider title (key) and their corresponding anilist names (value) # and then please open a pr @@ -552,7 +552,7 @@ player = {self.player} # # HOPE YOU ENJOY FASTANIME AND BE SURE TO STAR THE PROJECT ON GITHUB -# https://github.com/Benex254/FastAnime +# https://github.com/Benexl/FastAnime # # Also join the discord server # where the anime tech community lives :)