Skip to content

Commit

Permalink
fix kodik (step 1/?), fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nichind committed Nov 30, 2024
1 parent 2eaf4e4 commit f7b514c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 10 deletions.
2 changes: 2 additions & 0 deletions moe_parsers/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ class Anime(object):
def __init__(self, *args, **kwargs):
self.orig_title: str = None
self.title: str = None
self.all_titles: List[str] = None
self.anime_id: int | str = None
self.id_type: str = None
self.url: str = None
Expand All @@ -243,6 +244,7 @@ def __init__(self, *args, **kwargs):
self.data: dict = None
self.language: str = None
self.status: str = self.Status.UNKNOWN
self.description: str = None
self.args = args
for kwarg in kwargs:
setattr(self, kwarg, kwargs[kwarg])
Expand Down
12 changes: 9 additions & 3 deletions moe_parsers/providers/aniboom.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ async def get_episodes(self) -> List[AniboomEpisode]:
if self.episodes:
return self.episodes
self.episodes: List[AniboomEpisode] = await self.parser.get_episodes(self.url)
self.total_episodes = int(self.episodes[-1].get("episode_num", 0)) or len(self.episodes)
self.total_episodes = int(self.episodes[-1].get("episode_num", 0)) or len(
self.episodes
)
return self.episodes

async def get_translations(self) -> dict:
Expand Down Expand Up @@ -98,7 +100,11 @@ async def get_videos(self) -> List[dict]:
Returns:
List[dict]: List of videos for each episode
"""
for episode in self.episodes if (self.episodes and isinstance(self.episodes[0], AniboomEpisode)) else await self.get_episodes():
for episode in (
self.episodes
if (self.episodes and isinstance(self.episodes[0], AniboomEpisode))
else await self.get_episodes()
):
try:
await episode.get_videos()
except Exception:
Expand Down Expand Up @@ -332,7 +338,7 @@ async def get_info(self, link: str) -> dict:
anime_data = {}
response = await self.get(link)
soup = await self.soup(response)

anime_data["link"] = link
anime_data["animego_id"] = link[link.rfind("-") + 1 :]
anime_data["title"] = (
Expand Down
34 changes: 33 additions & 1 deletion moe_parsers/providers/kodik.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List, Literal
from json import loads
from base64 import b64decode
from ..classes import Anime, Parser, ParserParams, Exceptions, M3U8Playlist
from ..classes import Anime, Parser, ParserParams, Exceptions, M3U8Playlist, Media


class KodikVideo:
Expand All @@ -28,6 +28,14 @@ async def get_m3u8(self) -> str:
return await self.parser.get_m3u8(self.cloud_url)


class KodikIframe(Media):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.parser: KodikParser = (
kwargs["parser"] if "parser" in kwargs else KodikParser()
)


class KodikEpisode(Anime.Episode):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -75,12 +83,32 @@ async def convert2anime(self, **kwargs) -> KodikAnime:
anime = KodikAnime(
orig_title=kwargs["title_orig"],
title=kwargs["title"],
all_titles=[]
+ [kwargs.get("other_title", [])]
+ kwargs.get("other_titles_en", [])
+ kwargs.get("other_titles_jp", []),
anime_id=kwargs["shikimori_id"],
url="https:" + kwargs["link"],
parser=self,
id_type="shikimori",
language=self.language,
data=kwargs,
status=Anime.Status.COMPLETED
if kwargs.get("all_status", "") == "released"
else (
Anime.Status.ONGOING
if kwargs.get("all_status", "") == "ongoing"
else (Anime.Status.UNKNOWN)
),
year=kwargs.get("year", None),
description=kwargs.get("description", None),
type=Anime.Type.TV
if kwargs.get("anime_kind", "") == "tv"
else (
Anime.Type.MOVIE
if kwargs.get("anime_kind", "") == "movie"
else (Anime.Type.UNKNOWN)
),
)
return anime

Expand Down Expand Up @@ -142,6 +170,10 @@ async def search(
"imdb_id": result.get("imdb_id"),
"worldart_link": result.get("worldart_link"),
"link": result.get("link"),
"all_status": result.get("all_status"),
"description": result.get("description"),
"other_titles_en": result.get("other_titles_en"),
"other_titles_jp": result.get("other_titles_jp"),
}
)
added_titles.add(result["title"])
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pytest==7.2.2
pytest-cov==4.0.0
pytest-asyncio
ruff==v0.0.260
coverage-badge~=1.1.0
aiohttp
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/test_aniboom.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ async def test_aniboom_get_info():
"https://animego.org/anime/atri-moi-dorogie-momenty-2595"
)
assert data["animego_id"] == "2595"
assert data["status"] == 'Вышел'
assert len(data['translations']) >= 1
assert data["status"] == "Вышел"
assert len(data["translations"]) >= 1


@pytest.mark.asyncio
Expand All @@ -29,8 +29,8 @@ async def test_aniboom_get_episodes():
)
assert len(episodes) == 13
assert isinstance(episodes[0], AniboomEpisode)


@pytest.mark.asyncio
async def test_aniboom_get_episode_videos():
parser = AniboomParser()
Expand All @@ -51,7 +51,7 @@ async def test_aniboom_get_translations():
@pytest.mark.asyncio
async def test_aniboom_get_playlist():
parser = AniboomParser()
playlist = await parser.get_mpd_content("2318", 1, '1')
playlist = await parser.get_mpd_content("2318", 1, "1")
assert len(playlist.content) >= 256


Expand All @@ -61,5 +61,5 @@ async def test_aniboom_get_shikimori_id():
await AniboomAnime().get_shikimori_id(
"https://animego.org/anime/plastikovye-vospominaniya-2318"
)
== " "
== "27775"
)
2 changes: 2 additions & 0 deletions tests/unit/test_animego.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async def test_animego_get_translations():
translations = await parser.get_translations("2595")
assert len(translations) >= 1


@pytest.mark.asyncio
async def test_animego_get_episode_videos():
parser = AnimegoParser()
Expand All @@ -45,6 +46,7 @@ async def test_animego_get_episode_videos():
assert len(await episode.get_videos()) > 0
break


@pytest.mark.asyncio
async def test_animego_get_videos():
parser = AnimegoParser()
Expand Down

0 comments on commit f7b514c

Please sign in to comment.