2023-02-20 14:03:40 +01:00
|
|
|
from typing import Dict, List, Union
|
|
|
|
|
2023-02-20 14:38:09 +01:00
|
|
|
from mangadlp.types import ChapterData,ComicInfo
|
2023-02-18 16:29:44 +01:00
|
|
|
|
2022-05-17 13:32:50 +02:00
|
|
|
# api template for manga-dlp
|
|
|
|
|
|
|
|
|
|
|
|
class YourAPI:
|
2022-08-14 16:34:15 +02:00
|
|
|
"""Your API Class.
|
2023-02-18 12:29:25 +01:00
|
|
|
|
|
|
|
Get infos for a manga from example.org.
|
2022-08-14 16:34:15 +02:00
|
|
|
|
|
|
|
Args:
|
|
|
|
url_uuid (str): URL or UUID of the manga
|
|
|
|
language (str): Manga language with country codes. "en" --> english
|
|
|
|
forcevol (bool): Force naming of volumes. Useful for mangas where chapters reset each volume
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
api_name (str): Name of the API
|
|
|
|
manga_uuid (str): UUID of the manga, without the url part
|
|
|
|
manga_title (str): The title of the manga, sanitized for all filesystems
|
|
|
|
chapter_list (list): A list of all available chapters for the language
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2022-05-17 13:32:50 +02:00
|
|
|
# api information - example
|
|
|
|
api_base_url = "https://api.mangadex.org"
|
|
|
|
img_base_url = "https://uploads.mangadex.org"
|
|
|
|
|
2023-02-18 16:29:44 +01:00
|
|
|
def __init__(self, url_uuid: str, language: str, forcevol: bool):
|
2023-02-18 12:29:25 +01:00
|
|
|
"""get infos to initiate class."""
|
2022-08-13 18:52:32 +02:00
|
|
|
self.api_name = "Your API Name"
|
|
|
|
|
2022-05-17 13:32:50 +02:00
|
|
|
self.url_uuid = url_uuid
|
|
|
|
self.language = language
|
|
|
|
self.forcevol = forcevol
|
|
|
|
|
|
|
|
# attributes needed by app.py
|
|
|
|
self.manga_uuid = "abc"
|
|
|
|
self.manga_title = "abc"
|
2023-02-13 23:17:52 +01:00
|
|
|
self.chapter_list = ["1", "2", "2.1", "5", "10"]
|
2023-02-20 14:03:40 +01:00
|
|
|
self.manga_chapter_data: Dict[str, ChapterData] = { # example data
|
2023-02-13 23:17:52 +01:00
|
|
|
"1": {
|
|
|
|
"uuid": "abc",
|
|
|
|
"volume": "1",
|
|
|
|
"chapter": "1",
|
|
|
|
"name": "test",
|
2023-02-20 14:03:40 +01:00
|
|
|
"pages" 2,
|
2023-02-13 23:17:52 +01:00
|
|
|
},
|
|
|
|
"2": {
|
|
|
|
"uuid": "abc",
|
|
|
|
"volume": "1",
|
|
|
|
"chapter": "2",
|
|
|
|
"name": "test",
|
2023-02-20 14:03:40 +01:00
|
|
|
"pages": 45,
|
2023-02-13 23:17:52 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
# or with --forcevol
|
2023-02-20 14:38:09 +01:00
|
|
|
self.manga_chapter_data: Dict[str, ChapterData] = {
|
2023-02-13 23:17:52 +01:00
|
|
|
"1:1": {
|
|
|
|
"uuid": "abc",
|
|
|
|
"volume": "1",
|
|
|
|
"chapter": "1",
|
|
|
|
"name": "test",
|
|
|
|
},
|
|
|
|
"1:2": {
|
|
|
|
"uuid": "abc",
|
|
|
|
"volume": "1",
|
|
|
|
"chapter": "2",
|
|
|
|
"name": "test",
|
|
|
|
},
|
|
|
|
}
|
2022-05-17 13:32:50 +02:00
|
|
|
|
2023-02-18 16:29:44 +01:00
|
|
|
def get_chapter_images(self, chapter: str, wait_time: float) -> List[str]:
|
2023-02-18 12:29:25 +01:00
|
|
|
"""Get chapter images as a list (full links).
|
2023-02-13 23:17:52 +01:00
|
|
|
|
|
|
|
Args:
|
|
|
|
chapter: The chapter number (chapter data index)
|
|
|
|
download_wait: Wait time between image downloads
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The list of urls of the page images
|
|
|
|
"""
|
2022-05-17 13:32:50 +02:00
|
|
|
# example
|
|
|
|
return [
|
|
|
|
"https://abc.def/image/123.png",
|
|
|
|
"https://abc.def/image/1234.png",
|
|
|
|
"https://abc.def/image/12345.png",
|
|
|
|
]
|
2023-02-13 19:15:27 +01:00
|
|
|
|
2023-02-20 14:03:40 +01:00
|
|
|
def create_metadata(self, chapter: str) -> ComicInfo:
|
2023-02-18 12:29:25 +01:00
|
|
|
"""Get metadata with correct keys for ComicInfo.xml.
|
|
|
|
|
|
|
|
Provide as much metadata as possible. empty/false values will be ignored.
|
2023-02-13 23:17:52 +01:00
|
|
|
|
|
|
|
Args:
|
|
|
|
chapter: The chapter number (chapter data index)
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The metadata as a dict
|
|
|
|
"""
|
2023-02-15 14:21:45 +01:00
|
|
|
# metadata types. have to be valid
|
|
|
|
# {key: (type, default value, valid values)}
|
2023-02-19 18:50:56 +01:00
|
|
|
{
|
2023-02-15 14:21:45 +01:00
|
|
|
"Title": (str, None, []),
|
|
|
|
"Series": (str, None, []),
|
|
|
|
"Number": (str, None, []),
|
|
|
|
"Count": (int, None, []),
|
|
|
|
"Volume": (int, None, []),
|
|
|
|
"AlternateSeries": (str, None, []),
|
|
|
|
"AlternateNumber": (str, None, []),
|
|
|
|
"AlternateCount": (int, None, []),
|
|
|
|
"Summary": (str, None, []),
|
|
|
|
"Notes": (
|
|
|
|
str,
|
|
|
|
"Downloaded with https://github.com/olofvndrhr/manga-dlp",
|
|
|
|
[],
|
|
|
|
),
|
|
|
|
"Year": (int, None, []),
|
|
|
|
"Month": (int, None, []),
|
|
|
|
"Day": (int, None, []),
|
|
|
|
"Writer": (str, None, []),
|
|
|
|
"Colorist": (str, None, []),
|
|
|
|
"Publisher": (str, None, []),
|
|
|
|
"Genre": (str, None, []),
|
|
|
|
"Web": (str, None, []),
|
|
|
|
"PageCount": (int, None, []),
|
|
|
|
"LanguageISO": (str, None, []),
|
|
|
|
"Format": (str, None, []),
|
|
|
|
"BlackAndWhite": (str, None, ["Yes", "No", "Unknown"]),
|
|
|
|
"Manga": (str, "Yes", ["Yes", "No", "Unknown", "YesAndRightToLeft"]),
|
|
|
|
"ScanInformation": (str, None, []),
|
|
|
|
"SeriesGroup": (str, None, []),
|
|
|
|
"AgeRating": (
|
|
|
|
str,
|
|
|
|
None,
|
|
|
|
[
|
|
|
|
"Unknown",
|
|
|
|
"Adults Only 18+",
|
|
|
|
"Early Childhood",
|
|
|
|
"Everyone",
|
|
|
|
"Everyone 10+",
|
|
|
|
"G",
|
|
|
|
"Kids to Adults",
|
|
|
|
"M",
|
|
|
|
"MA15+",
|
|
|
|
"Mature 17+",
|
|
|
|
"PG",
|
|
|
|
"R18+",
|
|
|
|
"Rating Pending",
|
|
|
|
"Teen",
|
|
|
|
"X18+",
|
|
|
|
],
|
|
|
|
),
|
|
|
|
"CommunityRating": (int, None, [1, 2, 3, 4, 5]),
|
2023-02-14 13:31:55 +01:00
|
|
|
}
|
|
|
|
|
2023-02-13 19:15:27 +01:00
|
|
|
# example
|
|
|
|
return {
|
2023-02-20 14:38:09 +01:00
|
|
|
"Volume": 1,
|
2023-02-13 19:15:27 +01:00
|
|
|
"LanguageISO": "en",
|
|
|
|
"Title": "test",
|
|
|
|
}
|