Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Update window dimensions and add new anime downloader and a lot of th…
Browse files Browse the repository at this point in the history
…ings
  • Loading branch information
ReiLoko4 committed Apr 7, 2024
1 parent ce07ae3 commit 0759ef2
Show file tree
Hide file tree
Showing 14 changed files with 369 additions and 69 deletions.
7 changes: 5 additions & 2 deletions MangaYouKnow/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
def main(page: ft.Page) -> ft.FletApp:
page.title = f'MangaYouKnow {__version__}'
page.theme_mode = database.get_config()['theme-mode']
page.window_min_width = 770
page.window_min_height = 600
page.window_width = 1200
page.window_height = 800
page.window_min_width = 1200
page.window_min_height = 800
page.window_center()
page.vertical_alignment = ft.CrossAxisAlignment.CENTER
database.init_database()
page.data = {}
Expand Down
1 change: 1 addition & 0 deletions MangaYouKnow/backend/anime_downloaders/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .anime_fire import AnimeFireDl
from .animes_house import AnimesHouseDl
from .animes_online import AnimesOnlineDl
from .animes_online_nz import AnimesOnlineNZDl
from .animes_vision import AnimesVisionDl
from .better_anime import BetterAnimeDl
from .goyabu import GoyabuDl
Expand Down
86 changes: 86 additions & 0 deletions MangaYouKnow/backend/anime_downloaders/animes_online_nz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from backend.interfaces import AnimeDl
from backend.models import Chapter, Episode, Manga
from bs4 import BeautifulSoup
from requests import Session


class AnimesOnlineNZDl(AnimeDl):
def __init__(self):
self.base_url = 'https://animesonline.nz'
self.session = Session()
self.session.headers.update({
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Accept-Language': 'pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3',
'Alt-Used': 'animesonline.nz',
'Connection': 'keep-alive',
'Referer': 'https://animesonline.nz/',
'Upgrade-Insecure-Requests': '1',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-User': '?1',
})

def search(self, query: str) -> list[Manga] | bool:
response = self.session.get(
self.base_url,
params={'s': query},
)
if response.status_code == 200:
soup = BeautifulSoup(response.content, 'html.parser')
div_results = soup.find_all('div', {'class': 'result-item'})
animes = []
for div in div_results:
a = div.find_all('a')[1]
img = div.find('img')
animes.append(
Manga(
id=a['href'].split('/')[-2],
name=a.text,
folder_name=a['href'].split('/')[-2],
cover=img['src'],
)
)
return animes[:10]
return False

def get_episodes(self, anime_id: str) -> list[Chapter] | bool:
response = self.session.get(f'{self.base_url}/animes/{anime_id}')
if response.status_code == 200:
soup = BeautifulSoup(response.content, 'html.parser')
ul = soup.find('ul', {'class': 'episodios'})
episodes = []
for li in ul.find_all('li'):
a = li.find('a')
split_url = a['href'].split('/')
episodes.append(
Chapter(
id=split_url[-2],
number=a.text,
title=a['title']
)
)
return episodes[::-1]
return False

def get_episode_url(self, episode_id: str) -> Episode | list[Episode] | str:
response = self.session.get(f'{self.base_url}/episodio/{episode_id}')
if response.status_code == 200:
soup = BeautifulSoup(response.content, 'html.parser')
iframes = soup.find_all('iframe')
labels = soup.find_all('span', {'class': 'title'})
if len(iframes) == 1:
return Episode(
url=iframes[0]['src'],
label=labels[0].text
)
if len(iframes) > 1:
return [
Episode(
url='https://animesonline.nz/noa/?id=ZnA0MGNjMDA0bWI3',
label=label.text
)
for iframe, label in zip(iframes, labels)
]
return f'{self.base_url}/episodio/{episode_id}'
59 changes: 59 additions & 0 deletions MangaYouKnow/backend/anime_downloaders/erai_raws.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from backend.interfaces import AnimeDl
from backend.models import Chapter, Episode, Manga
from bs4 import BeautifulSoup
from requests import Session


class EraiRawsDl(AnimeDl):
def __init__(self):
self.base_url = 'https://www.erai-raws.info/'
self.session = Session()
self.session.headers.update({
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Accept-Language': 'pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-User': '?1',
})
self.session.cookies.update({
'__ddg1_': 'Z8mWxMS2GPqmh1Cj6S1O',
'wordpress_logged_in_25c65adc7d24c2f6075a3cbdddcf4db0': 'ReiLoko%7C1719190782%7CJtnw9BojJM48YUY8JLDADaO07sqNCKZeX3kMc0fJivv%7C52f29e45c74b4995d451dfc3943f68412a81bc6cfdae2efe15b22bd025078933',
'PHPSESSID': '5qmt44puosja5kbo4u4kio9c69',
'wfwaf-authcookie-f95bdc8896162871dd9440f078446f26': '115269%7Cother%7Cread%7C84287b359506d1d8c0b76d0b9b5ce1629b277b9c81ce919a21cc131ad408762f',
'wpdiscuz_nonce_25c65adc7d24c2f6075a3cbdddcf4db0': '8d15adcdb9',
})

def search(self, query: str) -> list[Manga] | bool:
response = self.session.get(
self.base_url,
params={
's': query
}
)
if response.status_code == 200:
soup = BeautifulSoup(response.content, 'html.parser')
main = soup.find('main')
animes = []
for a in main.find_all(a):
split_url = a['href'].split('/')
animes.append(
Manga(
id=split_url[-2:],
name=a.text,
folder_name=split_url[-2],
cover='https://mapacultural.funcap.se.gov.br/_next/static/images/no-capa-814c308aa1d2c7aa3ca6da4f90a4a581.jpg'
)
)
return animes[:10]
return False

def get_episodes(self, anime_id: str) -> list[Chapter] | bool:
pass

def get_episode_url(self, episode_id: str) -> list[Episode] | bool:
pass

2 changes: 2 additions & 0 deletions MangaYouKnow/backend/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def __init__(self):
'desc': desc(Favorite.id),
'asc-mark': asc(MarkFavorite.id),
'desc-mark': desc(MarkFavorite.id),
'more-score': desc(Favorite.score),
'less-score': asc(Favorite.score),
'asc-alf': asc(Favorite.name),
'desc-alf': desc(Favorite.name)
}
Expand Down
9 changes: 9 additions & 0 deletions MangaYouKnow/backend/managers/download_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from cachetools import TTLCache
from requests import Session
from requests.adapters import HTTPAdapter
from retrying import retry
from urllib3 import PoolManager
from urllib3.util.retry import Retry
from yt_dlp import YoutubeDL
Expand Down Expand Up @@ -50,6 +51,7 @@ def __init__(self) -> None:
'av': AnimesVisionDl(),
'af': AnimeFireDl(),
'ao': AnimesOnlineDl(),
'aon': AnimesOnlineNZDl(),
'ah': AnimesHouseDl(),
'oa': OtakuAnimessDl(),
'go': GoyabuDl(),
Expand All @@ -65,13 +67,15 @@ def __match_source__(self, source: str, fav_type: str = 'manga') -> MangaDl | An
return self.manga_downloaders[source]
return self.anime_downloaders[source]

@retry(stop_max_attempt_number=3, wait_fixed=1000)
@conditional_cache_lru(maxsize=1024)
def search(self, source: str, query: str, fav_type: str = 'manga') -> list[Manga] | bool:
dl = self.__match_source__(source, fav_type)
if dl:
return dl.search(query)
return False

@retry(stop_max_attempt_number=3, wait_fixed=1000)
@conditional_cache_ttl(TTLCache(maxsize=1024, ttl=580))
def get_chapters(self, source: str, manga_id: str, source_language: str = None) -> list[Chapter] | bool:
source: MangaDl = self.__match_source__(source)
Expand All @@ -83,6 +87,7 @@ def get_chapters(self, source: str, manga_id: str, source_language: str = None)
print(e)
return False

@retry(stop_max_attempt_number=3, wait_fixed=1000)
@conditional_cache_ttl(TTLCache(maxsize=1024, ttl=580))
def get_episodes(self, source: str, anime_id: str) -> list[Chapter] | bool:
source: AnimeDl = self.__match_source__(source, 'anime')
Expand All @@ -93,6 +98,7 @@ def get_episodes(self, source: str, anime_id: str) -> list[Chapter] | bool:
print(e)
return False

@retry(stop_max_attempt_number=3, wait_fixed=1000)
@conditional_cache_lru(maxsize=1024)
def get_chapter_image_urls(self, source: str, chapter_id: str) -> list[str] | bool:
dl: MangaDl = self.__match_source__(source)
Expand All @@ -103,6 +109,7 @@ def get_chapter_image_urls(self, source: str, chapter_id: str) -> list[str] | bo
print(e)
return False

@retry(stop_max_attempt_number=3, wait_fixed=1000)
@conditional_cache_lru(maxsize=1024)
def get_episode_url(self, source: str, episode_id: str) -> Episode | list[Episode] | bool:
dl: AnimeDl = self.__match_source__(source, 'anime')
Expand All @@ -113,6 +120,7 @@ def get_episode_url(self, source: str, episode_id: str) -> Episode | list[Episod
print(e)
return False

@retry(stop_max_attempt_number=3, wait_fixed=1000)
@conditional_cache_lru(maxsize=1024)
def get_image_content(self, url: str) -> bytes | None:
response = self.session.get(url)
Expand Down Expand Up @@ -227,6 +235,7 @@ def download_page(url: str, path: Path):
return False

def download_all_chapters(self, manga: Favorite, source: str, chapters: list[Chapter], num: int = 5) -> bool:
self.notificator.show(manga.name, f'Baixando {len(chapters)} capítulos...')
threads = ThreadManager()
if not chapters:
return False
Expand Down
12 changes: 6 additions & 6 deletions MangaYouKnow/screen/components/manga_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

database = DataBase()
def MangaEdit(
manga_info: Favorite, row_mangas: ft.Row,
load_mangas_by_mark: callable, load_mangas: callable,
search: ft.TextField, page: ft.Page
manga_info: Favorite,
load_mangas: callable,
page: ft.Page
) -> ft.AlertDialog:
change_name = ft.TextField(label='Nome', value=manga_info.name)
change_cover = ft.TextField(label='Capa', value=manga_info.cover)
marks = database.get_marks()
def change_mark(mark_id: int, value: bool):
if value:
database.add_mark_favorite(manga_info.id, mark_id)
load_mangas_by_mark()
load_mangas()
return
database.delete_mark_favorite(manga_info.id, mark_id)
load_mangas_by_mark()
load_mangas()
marks_column = ft.Column([
ft.ListTile(
title=ft.Text(
Expand All @@ -37,7 +37,7 @@ def save(column, content):
if content == getattr(manga_info, column):
return
if database.set_favorite(manga_info.id, column, content):
row_mangas.controls = load_mangas(search.value if search.value != '' else None)
load_mangas()
page.update()
edition = ft.AlertDialog(
title=ft.Text('Editar Mangá'),
Expand Down
Loading

0 comments on commit 0759ef2

Please sign in to comment.