From 11fc5e711bf7f28e0adde02a74ad501fdc35aef2 Mon Sep 17 00:00:00 2001 From: ReiLoko Date: Sun, 18 Feb 2024 19:09:07 -0300 Subject: [PATCH] Update anime downloaders with episode URL changes --- .../backend/anime_downloaders/anime_fire.py | 6 ++--- .../anime_downloaders/animes_online.py | 2 +- .../anime_downloaders/animes_vision.py | 6 +++-- .../backend/anime_downloaders/better_anime.py | 4 +-- .../backend/anime_downloaders/goyabu.py | 2 +- MangaYouKnow/screen/components/manga_open.py | 26 ++++++++++++++++--- MangaYouKnow/screen/pages/index.py | 2 +- 7 files changed, 35 insertions(+), 13 deletions(-) diff --git a/MangaYouKnow/backend/anime_downloaders/anime_fire.py b/MangaYouKnow/backend/anime_downloaders/anime_fire.py index 1748e2c..c30c437 100644 --- a/MangaYouKnow/backend/anime_downloaders/anime_fire.py +++ b/MangaYouKnow/backend/anime_downloaders/anime_fire.py @@ -57,7 +57,7 @@ def get_episodes(self, anime_id: str) -> list[Chapter] | bool: return episodes[::-1] return False - def get_episode_url(self, episode_id: str) -> Episode | bool: + def get_episode_url(self, episode_id: str) -> Episode | str: response = self.session.get(f'{self.base_url}/animes/{episode_id}') if response.status_code == 200: soup = BeautifulSoup(response.content, 'html.parser') @@ -73,5 +73,5 @@ def get_episode_url(self, episode_id: str) -> Episode | bool: ) for episode in video_json.json()['data'] ][::-1] - return False - return False \ No newline at end of file + return f'{self.base_url}/animes/{episode_id}' + return f'{self.base_url}/animes/{episode_id}' \ No newline at end of file diff --git a/MangaYouKnow/backend/anime_downloaders/animes_online.py b/MangaYouKnow/backend/anime_downloaders/animes_online.py index d23070e..9038c12 100644 --- a/MangaYouKnow/backend/anime_downloaders/animes_online.py +++ b/MangaYouKnow/backend/anime_downloaders/animes_online.py @@ -78,4 +78,4 @@ def get_episode_url(self, episode_id: str) -> Episode | list[Episode] | bool: ) for iframe, a in zip(iframes, a) ] - return False + return f'{self.base_url}/episodio/{episode_id}' diff --git a/MangaYouKnow/backend/anime_downloaders/animes_vision.py b/MangaYouKnow/backend/anime_downloaders/animes_vision.py index e39765b..552327c 100644 --- a/MangaYouKnow/backend/anime_downloaders/animes_vision.py +++ b/MangaYouKnow/backend/anime_downloaders/animes_vision.py @@ -100,10 +100,12 @@ def get_episodes(self, anime_id: str) -> list[Chapter] | bool: return episodes[::-1] return False - def get_episode_url(self, episode_id: str) -> Episode | bool: + def get_episode_url(self, episode_id: str) -> Episode | str: response = self.session.get(f'{self.base_url}/animes/{episode_id}') if response.status_code == 200: soup = BeautifulSoup(response.content, 'html.parser') + return f'{self.base_url}/animes/{episode_id}' + div_script = soup.find_all('div', {'wire:initial-data': True})[1] script = json.loads(div_script['wire:initial-data']) urls = [] @@ -125,5 +127,5 @@ def get_episode_url(self, episode_id: str) -> Episode | bool: ) for url, label in zip(urls, labels) ][::-1] - return False + return f'{self.base_url}/animes/{episode_id}' \ No newline at end of file diff --git a/MangaYouKnow/backend/anime_downloaders/better_anime.py b/MangaYouKnow/backend/anime_downloaders/better_anime.py index 00a1075..bb54130 100644 --- a/MangaYouKnow/backend/anime_downloaders/better_anime.py +++ b/MangaYouKnow/backend/anime_downloaders/better_anime.py @@ -85,10 +85,10 @@ def get_url_by_quality(self, quality_info: str) -> str | bool: if quality_match: return quality_match.group(1).replace('\\', '') - def get_episode_url(self, episode_id: str) -> list[Episode] | Episode | bool: + def get_episode_url(self, episode_id: str) -> list[Episode] | Episode | str: response = self.session.get(f'{self.base_url}/anime/{episode_id}') if not response: - return False + return f'{self.base_url}/anime/{episode_id}' url_and_label = [] matches = re.findall(r'qualityString\["([^"]*)"\]\s*=\s*"([^"]*)"', response.text) for match in matches: diff --git a/MangaYouKnow/backend/anime_downloaders/goyabu.py b/MangaYouKnow/backend/anime_downloaders/goyabu.py index a01f6bc..114abb5 100644 --- a/MangaYouKnow/backend/anime_downloaders/goyabu.py +++ b/MangaYouKnow/backend/anime_downloaders/goyabu.py @@ -73,4 +73,4 @@ def get_episode_url(self, episode_id: str) -> Episode | bool: return Episode( url=url ) - return False \ No newline at end of file + return f'{self.base_url}/{episode_id}' \ No newline at end of file diff --git a/MangaYouKnow/screen/components/manga_open.py b/MangaYouKnow/screen/components/manga_open.py index 9adba83..4391b33 100644 --- a/MangaYouKnow/screen/components/manga_open.py +++ b/MangaYouKnow/screen/components/manga_open.py @@ -1,4 +1,7 @@ +import webbrowser + import flet as ft +import pyperclip from backend.database import DataBase from backend.managers import DownloadManager from backend.models import Chapter, Episode @@ -85,12 +88,27 @@ def read(source, manga: Favorite, chapter: Chapter, chapters: list[Chapter], lan dl.download_mpv() status.value = 'Procurando o episódio...' page.update() + print(chapter) episode_urls = dl.get_episode_url(source, chapter.id) print(episode_urls) - if type(episode_urls) == bool: + if type(episode_urls) == str: status.value = 'Erro ao encontrar o episódio!' status.color = ft.colors.RED_500 - row_content.controls = [] + row_content.controls = [ + ft.Column([ + ft.Text('Você pode assistir diretamente no link: '), + ft.TextField(value=episode_urls, read_only=True, width=240, border_radius=20, height=70, border_color=ft.colors.GREY_700, focused_border_color=ft.colors.BLUE_300), + ft.Row([ + ft.FilledButton('Copiar', on_click=lambda e: pyperclip.copy(episode_urls), ), + ft.FilledButton('Abrir no navegador', on_click=lambda e: webbrowser.open(episode_urls),), + ], alignment=ft.MainAxisAlignment.CENTER, width=250), + ft.Text('Assistiu?'), + ft.Row([ + ft.IconButton(icon=ft.icons.CHECK, on_click=lambda e: (togle_readed(source, manga, chapter, language if language else None, True), MangaOpen(manga_info, source_languages, togle_notify, page, is_index, cards_row, mangas_card_notify))), + ft.IconButton(icon=ft.icons.HIGHLIGHT_REMOVE, on_click=lambda e: MangaOpen(manga_info, source_languages, togle_notify, page, is_index, cards_row, mangas_card_notify)), + ], alignment=ft.MainAxisAlignment.CENTER, width=250), + ]) + ] page.update() return def select_option(ep: Episode): @@ -133,8 +151,10 @@ def select_option(ep: Episode): MangaOpen(manga_info, source_languages, togle_notify, page, is_index, cards_row, mangas_card_notify) btns_list: list[ft.IconButton] = [] - def togle_readed(source, manga: Favorite, chapter: Chapter, language: str=None): + def togle_readed(source, manga: Favorite, chapter: Chapter, language: str=None, just_read: bool=False) -> None: if db.is_readed(source, manga.id, manga.source_id, chapter.id, language if language else None): + if just_read: + return db.delete_all_readed_above(manga, source, chapter, chapters_by_source[f'{source}_{language_options.value}'], language if language else None) else: db.add_all_readed_below(manga, source, chapter, chapters_by_source[f'{source}_{language_options.value}'], language if language else None) diff --git a/MangaYouKnow/screen/pages/index.py b/MangaYouKnow/screen/pages/index.py index f96773d..57d7442 100644 --- a/MangaYouKnow/screen/pages/index.py +++ b/MangaYouKnow/screen/pages/index.py @@ -25,7 +25,7 @@ def __init__(self, page: ft.Page): ] anime_options = [ ft.dropdown.Option('ba', text='BetterAnime'), - # ft.dropdown.Option('av', text='AnimesVision'), + ft.dropdown.Option('av', text='AnimesVision'), ft.dropdown.Option('af', text='AnimeFire'), # ft.dropdown.Option('ah', text='AnimesHouse'), ft.dropdown.Option('go', text='Goyabu'),