Skip to content

Commit

Permalink
changed old models with new
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonzorn committed Jul 16, 2024
1 parent ef7e015 commit 79b2ad7
Show file tree
Hide file tree
Showing 22 changed files with 91 additions and 99 deletions.
10 changes: 4 additions & 6 deletions nlightreader/controlers/filter_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from qfluentwidgets import CheckBox, RadioButton

from nlightreader.dialogs import FormGenres
from nlightreader.items import Genre, Kind, Order
from nlightreader.models import Genre, Kind, Order


class FilterController:
Expand All @@ -16,17 +16,15 @@ def __init__(self):
self._kinds_container = None
self._genres_container = None

def get_active_order(self):
if not self._order_items:
return Order.get_empty_instance()
def get_active_order(self) -> Order | None:
for item in self._order_items:
if item.isChecked():
return self._order_items[item]

def get_active_kinds(self):
def get_active_kinds(self) -> list[Kind]:
return [self._kind_items[i] for i in self._kind_items if i.isChecked()]

def get_active_genres(self):
def get_active_genres(self) -> list[Genre]:
return self._genres_container.selected_genres

def add_orders(self, items: list[Order]):
Expand Down
7 changes: 1 addition & 6 deletions nlightreader/parsers/catalog.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
from nlightreader.consts.urls import DEFAULT_HEADERS
from nlightreader.consts.items.parser_items import ParserItems
from nlightreader.items import (
Chapter,
Character,
Genre,
Image,
Kind,
Order,
RequestForm,
User,
UserRate,
)
from nlightreader.models import Manga
from nlightreader.models import Chapter, Character, Genre, Kind, Manga, Order


class AbstractCatalog:
Expand Down
5 changes: 2 additions & 3 deletions nlightreader/parsers/combined/lib/lib_anilib.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from nlightreader.consts.enums import Nl
from nlightreader.consts.items import AniLibItems
from nlightreader.consts.urls import URL_ANILIB
from nlightreader.items import Chapter
from nlightreader.models import Manga
from nlightreader.models import Chapter, Manga
from nlightreader.parsers.catalogs_base import AbstractAnimeCatalog
from nlightreader.parsers.combined.lib.lib_base import LibBase
from nlightreader.utils.utils import get_html
Expand All @@ -29,7 +28,7 @@ def get_chapters(self, manga: Manga) -> list[Chapter]:
episode = Chapter(
i["id"],
self.CATALOG_ID,
"",
None,
"",
f"Episode {i['number']}",
Nl.Language.ru,
Expand Down
4 changes: 2 additions & 2 deletions nlightreader/parsers/combined/lib/lib_base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from nlightreader.consts.enums import Nl
from nlightreader.consts.urls import URL_LIB_API
from nlightreader.items import Chapter, RequestForm
from nlightreader.models import Manga
from nlightreader.items import RequestForm
from nlightreader.models import Chapter, Manga
from nlightreader.parsers.catalog import AbstractCatalog
from nlightreader.utils.utils import get_html

Expand Down
8 changes: 4 additions & 4 deletions nlightreader/parsers/combined/lib/lib_mangalib.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from nlightreader.consts.items import MangaLibItems
from nlightreader.consts.urls import URL_MANGALIB
from nlightreader.items import Chapter, Image
from nlightreader.models import Manga
from nlightreader.items import Image
from nlightreader.models import Chapter, Manga
from nlightreader.parsers.catalogs_base import AbstractMangaCatalog
from nlightreader.parsers.combined.lib.lib_base import LibBase
from nlightreader.utils.utils import get_html
Expand All @@ -22,8 +22,8 @@ def __init__(self):
def get_images(self, manga: Manga, chapter: Chapter) -> list[Image]:
url = f"{self.url_api}/{self.content_name}/{manga.content_id}/chapter"
params = {
"number": chapter.ch,
"volume": chapter.vol,
"number": chapter.chapter_number,
"volume": chapter.volume_number,
}
response = get_html(url, params=params, content_type="json")
images = []
Expand Down
9 changes: 5 additions & 4 deletions nlightreader/parsers/combined/lib/lib_ranobelib.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from nlightreader.consts.enums import Nl
from nlightreader.consts.items import RanobeLibItems
from nlightreader.consts.urls import URL_RANOBELIB
from nlightreader.items import Chapter, Image
from nlightreader.models import Manga
from nlightreader.items import Image
from nlightreader.models import Chapter, Manga
from nlightreader.parsers.catalogs_base import AbstractRanobeCatalog
from nlightreader.parsers.combined.lib.lib_base import LibBase
from nlightreader.utils.utils import get_html
Expand All @@ -29,8 +29,9 @@ def get_manga(self, manga: Manga) -> Manga:

def get_images(self, manga: Manga, chapter: Chapter) -> list[Image]:
url = (
f"{self.url_api}/{self.content_name}/{manga.content_id}/"
f"chapter?number={chapter.ch}&volume={chapter.vol}"
f"{self.url_api}/{self.content_name}/{manga.content_id}/chapter"
f"?number={chapter.chapter_number}"
f"&volume={chapter.volume_number}"
)
return [Image("", 1, url)]

Expand Down
8 changes: 2 additions & 6 deletions nlightreader/parsers/combined/shikimori/shikimori_anime.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
URL_SHIKIMORI_API,
)
from nlightreader.items import (
Chapter,
Character,
Genre,
Order,
RequestForm,
)
from nlightreader.models import Manga
from nlightreader.models import Chapter, Character, Genre, Manga, Order
from nlightreader.parsers.catalogs_base import AbstractAnimeCatalog
from nlightreader.parsers.service.kodik import Kodik
from nlightreader.utils.utils import get_html
Expand Down Expand Up @@ -82,7 +78,7 @@ def get_chapters(self, manga: Manga) -> list[Chapter]:
chapter = Chapter(
f"{translator.content_id}{episode_num}",
self.CATALOG_ID,
"",
None,
"",
f"Episode {episode_num}",
Nl.Language.ru,
Expand Down
80 changes: 43 additions & 37 deletions nlightreader/parsers/combined/shikimori/shikimori_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
URL_SHIKIMORI,
URL_SHIKIMORI_API,
)
from nlightreader.items import Character, Genre, Order
from nlightreader.models import Manga
from nlightreader.models import Character, Genre, Manga, Order
from nlightreader.parsers.catalog import AbstractCatalog
from nlightreader.utils.utils import get_html

Expand Down Expand Up @@ -53,8 +52,12 @@ def get_manga(self, manga: Manga) -> Manga:
def get_character(self, character: Character) -> Character:
url = f"{self.url_api}/characters/{character.content_id}"
response = get_html(url, headers=self.headers, content_type="json")
if response:
character.description = response.get("description")
if not response:
return character

description = response.get("description")
if description:
character.description = description
return character

def get_preview(self, manga: Manga):
Expand All @@ -73,18 +76,19 @@ def get_character_preview(self, character: Character):
def get_genres(self):
url = f"{self.url_api}/genres"
response = get_html(url, headers=self.headers, content_type="json")
if response:
return [
Genre(
str(i["id"]),
self.CATALOG_ID,
i["name"],
i["russian"],
)
for i in response
if i["entry_type"] == "Manga"
]
return []
if not response:
return []

return [
Genre(
str(i["id"]),
self.CATALOG_ID,
i["name"],
i["russian"],
)
for i in response
if i["entry_type"] == "Manga"
]

def get_orders(self) -> list[Order]:
return [
Expand All @@ -103,33 +107,35 @@ def get_relations(self, manga: Manga) -> list[Manga]:
response = get_html(url, headers=self.headers, content_type="json")
if response:
for i in response:
if i.get("manga"):
i = i.get("manga")
mangas.append(self.setup_manga(i))
if manga_data := i.get("manga"):
mangas.append(
self.setup_manga(manga_data),
)
return mangas

def get_characters(self, manga: Manga) -> list[Character]:
characters = []
url = f"{self.url_api}/mangas/{manga.content_id}/roles"
response = get_html(url, headers=self.headers, content_type="json")
if response:
for i in response:
if i.get("roles"):
role = i.get("roles")[0]
if role in ["Supporting", "Main"]:
data = i.get("character")
if data:
characters.append(
Character(
str(data.get("id")),
self.CATALOG_ID,
data.get("name"),
data.get("russian"),
"",
role,
),
)
characters.sort(key=lambda x: x.role)
if not response:
return characters

for i in response:
if roles_data := i.get("roles"):
role = roles_data[0]
if role in ["Supporting", "Main"]:
if data := i.get("character"):
characters.append(
Character(
str(data.get("id")),
self.CATALOG_ID,
data.get("name"),
data.get("russian"),
"",
role,
),
)
characters.sort(key=lambda x: x.role)
return characters

def get_manga_url(self, manga: Manga) -> str:
Expand Down
3 changes: 2 additions & 1 deletion nlightreader/parsers/combined/shikimori/shikimori_manga.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from nlightreader.consts.items import ShikimoriItems
from nlightreader.items import Kind, RequestForm
from nlightreader.items import RequestForm
from nlightreader.models import Kind
from nlightreader.parsers.catalogs_base import AbstractMangaCatalog
from nlightreader.parsers.combined.shikimori.shikimori_base import (
ShikimoriBase,
Expand Down
4 changes: 2 additions & 2 deletions nlightreader/parsers/hentai_manga/allhentai_hmanga.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from nlightreader.consts.urls import URL_ALLHENTAI, URL_ALLHENTAI_API
from nlightreader.consts.enums import Nl
from nlightreader.items import Chapter, Image
from nlightreader.models import Manga
from nlightreader.items import Image
from nlightreader.models import Chapter, Manga
from nlightreader.parsers.catalogs_base import AbstractHentaiMangaCatalog
from nlightreader.utils.utils import get_html, make_request

Expand Down
4 changes: 2 additions & 2 deletions nlightreader/parsers/hentai_manga/nhentai_hmanga.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from bs4 import BeautifulSoup

from nlightreader.consts.urls import URL_NHENTAI, URL_NHENTAI_API
from nlightreader.items import Chapter, Image
from nlightreader.models import Manga
from nlightreader.items import Image
from nlightreader.models import Chapter, Manga
from nlightreader.parsers.catalogs_base import AbstractHentaiMangaCatalog
from nlightreader.utils.utils import get_html

Expand Down
4 changes: 2 additions & 2 deletions nlightreader/parsers/manga/desu_manga.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from nlightreader.consts.urls import DESU_HEADERS, URL_DESU, URL_DESU_API
from nlightreader.consts.enums import Nl
from nlightreader.consts.items import DesuItems
from nlightreader.items import Chapter, Genre, Image, RequestForm
from nlightreader.models import Manga
from nlightreader.items import Image, RequestForm
from nlightreader.models import Chapter, Manga
from nlightreader.parsers.catalogs_base import AbstractMangaCatalog
from nlightreader.utils.utils import get_data, get_html

Expand Down
5 changes: 1 addition & 4 deletions nlightreader/parsers/manga/mangadex_manga.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
)
from nlightreader.consts.enums import Nl
from nlightreader.items import (
Chapter,
Genre,
Image,
Kind,
RequestForm,
User,
)
from nlightreader.models import Manga
from nlightreader.models import Chapter, Genre, Kind, Manga
from nlightreader.parsers.catalog import LibParser
from nlightreader.parsers.catalogs_base import AbstractMangaCatalog
from nlightreader.utils.decorators import singleton
Expand Down
4 changes: 2 additions & 2 deletions nlightreader/parsers/manga/remanga_manga.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from nlightreader.consts.urls import URL_REMANGA, URL_REMANGA_API
from nlightreader.consts.enums import Nl
from nlightreader.consts.items import RemangaItems
from nlightreader.items import Chapter, Image, RequestForm
from nlightreader.models import Manga
from nlightreader.items import Image, RequestForm
from nlightreader.models import Chapter, Manga
from nlightreader.parsers.catalogs_base import AbstractMangaCatalog
from nlightreader.utils.utils import get_data, get_html

Expand Down
8 changes: 4 additions & 4 deletions nlightreader/parsers/ranobe/ranobehub_ranobe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from nlightreader.consts.urls import URL_RANOBEHUB, URL_RANOBEHUB_API
from nlightreader.consts.enums import Nl
from nlightreader.consts.items import RanobehubItems
from nlightreader.items import Chapter, Image, RequestForm
from nlightreader.models import Manga
from nlightreader.items import Image, RequestForm
from nlightreader.models import Chapter, Manga
from nlightreader.parsers.catalogs_base import AbstractRanobeCatalog
from nlightreader.utils.utils import get_data, get_html

Expand Down Expand Up @@ -90,8 +90,8 @@ def get_chapters(self, manga: Manga) -> list[Chapter]:

def get_images(self, manga: Manga, chapter: Chapter) -> list[Image]:
url = (
f"{self.url}/ranobe/"
f"{manga.content_id}/{chapter.vol}/{chapter.ch}"
f"{self.url}/ranobe/{manga.content_id}/"
f"{chapter.volume_number}/{chapter.chapter_number}"
)
return [Image("", 1, url)]

Expand Down
6 changes: 3 additions & 3 deletions nlightreader/parsers/ranobe/rulate_ranobe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from nlightreader.consts.urls import URL_EROLATE, URL_RULATE
from nlightreader.consts.enums import Nl
from nlightreader.consts.items import RulateItems
from nlightreader.items import Chapter, Image, RequestForm
from nlightreader.models import Manga
from nlightreader.items import Image, RequestForm
from nlightreader.models import Chapter, Manga
from nlightreader.parsers.catalogs_base import AbstractRanobeCatalog
from nlightreader.utils.utils import get_html

Expand Down Expand Up @@ -105,7 +105,7 @@ def get_chapters(self, manga: Manga):
chapter = Chapter(
chapter_id,
self.CATALOG_ID,
"",
None,
"",
name,
Nl.Language.ru,
Expand Down
4 changes: 2 additions & 2 deletions nlightreader/utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from nlightreader.consts.app import APP_NAME
from nlightreader.consts.enums import Nl
from nlightreader.items import Chapter, HistoryNote
from nlightreader.models import Manga
from nlightreader.items import HistoryNote
from nlightreader.models import Chapter, Manga
from nlightreader.utils.decorators import singleton


Expand Down
4 changes: 2 additions & 2 deletions nlightreader/utils/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

from nlightreader.consts.app import APP_NAME
from nlightreader.consts.enums import Nl
from nlightreader.items import Chapter, Character, Image
from nlightreader.models import Manga
from nlightreader.items import Image
from nlightreader.models import Chapter, Character, Manga
from nlightreader.parsers.catalog import AbstractCatalog


Expand Down
Loading

0 comments on commit 79b2ad7

Please sign in to comment.