update .gitignore
fix chapters counting the most recently uploaded as the latest renaming in manga_api.py, expecially in chapters first working saving for manager.py (with no loading as of now)
This commit is contained in:
parent
e06049a858
commit
494fe4c850
|
|
@ -160,3 +160,7 @@ cython_debug/
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Save file
|
||||||
|
manager.json
|
||||||
|
|
|
||||||
|
|
@ -79,9 +79,9 @@ def get_chapter_files(manga: Manga):
|
||||||
def chapter_embed(manga: Manga, chapter: Chapter):
|
def chapter_embed(manga: Manga, chapter: Chapter):
|
||||||
e = discord.Embed(
|
e = discord.Embed(
|
||||||
title=f'New "{manga.get_title()}" Chapter Released!',
|
title=f'New "{manga.get_title()}" Chapter Released!',
|
||||||
description=f"Chapter {chapter.get_chapter_num()} of {manga.get_title()} Released."
|
description=f"Chapter {chapter.get_number()} of {manga.get_title()} Released."
|
||||||
f"\nGo read it now!",
|
f"\nGo read it now!",
|
||||||
url=chapter.get_chapter_url()
|
url=chapter.get_url()
|
||||||
)
|
)
|
||||||
e.set_thumbnail(url=f"attachment://{manga.id}.{manga.get_cover_art_extension()}")
|
e.set_thumbnail(url=f"attachment://{manga.id}.{manga.get_cover_art_extension()}")
|
||||||
return e
|
return e
|
||||||
|
|
|
||||||
|
|
@ -39,10 +39,10 @@ class Manager:
|
||||||
def check_for_new_chapter(self, manga: manga_api.Manga) -> manga_api.Chapter | None:
|
def check_for_new_chapter(self, manga: manga_api.Manga) -> manga_api.Chapter | None:
|
||||||
latest_chap = manga.get_latest_chap()
|
latest_chap = manga.get_latest_chap()
|
||||||
if latest_chap not in self.chapters.keys():
|
if latest_chap not in self.chapters.keys():
|
||||||
self.chapters[manga.id] = latest_chap
|
self.chapters[manga.id] = latest_chap.id
|
||||||
return latest_chap
|
return latest_chap
|
||||||
if float(latest_chap.get_chapter_num()) > self.chapters[manga.id]:
|
if latest_chap.is_more_recent_than(manga_api.Chapter(self.chapters[manga.id])):
|
||||||
self.chapters[manga.id] = latest_chap
|
self.chapters[manga.id] = latest_chap.id
|
||||||
return latest_chap
|
return latest_chap
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
|
||||||
51
manga_api.py
51
manga_api.py
|
|
@ -21,15 +21,25 @@ class Chapter:
|
||||||
)
|
)
|
||||||
self.data = r.json()["data"]
|
self.data = r.json()["data"]
|
||||||
|
|
||||||
def get_chapter_num(self) -> str:
|
def is_more_recent_than(self, chapter):
|
||||||
|
if chapter.get_volume() != self.get_volume():
|
||||||
|
return float(self.get_volume()) > float(chapter.get_volume())
|
||||||
|
return float(self.get_number()) > float(chapter.get_number())
|
||||||
|
|
||||||
|
def get_volume(self) -> str:
|
||||||
|
return self.data["attributes"]["volume"]
|
||||||
|
|
||||||
|
def get_number(self) -> str:
|
||||||
return self.data["attributes"]["chapter"]
|
return self.data["attributes"]["chapter"]
|
||||||
|
|
||||||
def get_chapter_url(self) -> str:
|
def get_url(self) -> str:
|
||||||
return self.data["attributes"]["readableAt"]
|
return f"https://mangadex.org/chapter/{self.id}"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str({
|
return str({
|
||||||
"chapter_num": self.get_chapter_num(),
|
"chapter_vol": self.get_volume(),
|
||||||
|
"chapter_num": self.get_number(),
|
||||||
|
"chapter_url": self.get_url()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -57,7 +67,31 @@ class Manga:
|
||||||
return "No Title"
|
return "No Title"
|
||||||
|
|
||||||
def get_latest_chap(self) -> Chapter:
|
def get_latest_chap(self) -> Chapter:
|
||||||
return Chapter(self.data["attributes"]["latestUploadedChapter"])
|
params = {
|
||||||
|
"manga": self.id,
|
||||||
|
"translatedLanguage": ["en"],
|
||||||
|
"order": {
|
||||||
|
"chapter": "desc"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r = requests.get(
|
||||||
|
f"{self.base_url}/chapter?manga={self.id}&originalLanguage%5B%5D=en&contentRating%5B%5D=safe"
|
||||||
|
f"&contentRating%5B%5D=suggestive&contentRating%5B%5D=erotica&includeFutureUpdates=1&order%5Bchapter%5D"
|
||||||
|
f"=desc",
|
||||||
|
|
||||||
|
)
|
||||||
|
print(r.request.__dict__)
|
||||||
|
print(r.json())
|
||||||
|
if r.json()["total"] == 0:
|
||||||
|
r = requests.get(
|
||||||
|
f"{self.base_url}/chapter?manga={self.id}&translatedLanguage%5B%5D=en&contentRating%5B%5D=safe"
|
||||||
|
f"&contentRating%5B%5D=suggestive&contentRating%5B%5D=erotica&includeFutureUpdates=1&order%5Bchapter"
|
||||||
|
f"%5D=desc",
|
||||||
|
)
|
||||||
|
|
||||||
|
latest_chap = r.json()["data"][0]
|
||||||
|
|
||||||
|
return Chapter(latest_chap["id"])
|
||||||
|
|
||||||
def get_cover_art_url(self):
|
def get_cover_art_url(self):
|
||||||
cover_art_id = ""
|
cover_art_id = ""
|
||||||
|
|
@ -65,8 +99,6 @@ class Manga:
|
||||||
if relation["type"] == "cover_art":
|
if relation["type"] == "cover_art":
|
||||||
cover_art_id = relation["id"]
|
cover_art_id = relation["id"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
r = requests.get(f"{self.base_url}/cover/{cover_art_id}")
|
r = requests.get(f"{self.base_url}/cover/{cover_art_id}")
|
||||||
cover_fileName = r.json()["data"]["attributes"]["fileName"]
|
cover_fileName = r.json()["data"]["attributes"]["fileName"]
|
||||||
cover_extension = cover_fileName.split(".")[1]
|
cover_extension = cover_fileName.split(".")[1]
|
||||||
|
|
@ -78,8 +110,6 @@ class Manga:
|
||||||
if relation["type"] == "cover_art":
|
if relation["type"] == "cover_art":
|
||||||
cover_art_id = relation["id"]
|
cover_art_id = relation["id"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
r = requests.get(f"{self.base_url}/cover/{cover_art_id}")
|
r = requests.get(f"{self.base_url}/cover/{cover_art_id}")
|
||||||
cover_fileName = r.json()["data"]["attributes"]["fileName"]
|
cover_fileName = r.json()["data"]["attributes"]["fileName"]
|
||||||
cover_extension = cover_fileName.split(".")[1]
|
cover_extension = cover_fileName.split(".")[1]
|
||||||
|
|
@ -121,7 +151,6 @@ class MangaHandler:
|
||||||
return manga_list
|
return manga_list
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
mh = MangaHandler()
|
mh = MangaHandler()
|
||||||
print(mh.search("Umineko no Naku Koro ni Episode 4: Alliance of the Golden Witch")[0].data)
|
print(mh.search("Umineko no Naku Koro ni Episode 4: Alliance of the Golden Witch")[0].get_latest_chap())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue