Update workflows/publish_pypi.yml
[manga-dl.git] / manga_py / providers / mangapanda_onl.py
blob4b4f943640575455f399c4febe5db6a643e078c7
1 from manga_py.provider import Provider
2 from .helpers.std import Std
5 class MangaPandaCom(Provider, Std):
6 _cdn = 'https://img.mghubcdn.com/file/imghub'
7 _api_url = 'https://api.mghubcdn.com/graphql'
9 def get_chapter_index(self) -> str:
10 return self.chapter_for_json()
12 def get_content(self):
13 return self._get_content('{}/manga/{}')
15 def get_manga_name(self) -> str:
16 return self._get_name(r'\.\w{2,7}/manga/([^/]+)')
18 def get_chapters(self):
19 # curl 'https://api.mghubcdn.com/graphql' -H 'Content-Type: application/json' --data-raw '{"query": "{latestPopular(x:mr02){id}manga(x:mr02,slug:\"mahou-tsukai-no-yome\"){id,rank,title,slug,status,image,latestChapter,author,artist,genres,description,alternativeTitle,mainSlug,isYaoi,isPorn,isSoftPorn,unauthFile,noCoverAd,isLicensed,createdDate,updatedDate,chapters{id,number,title,slug,date}}}"}'
21 keys = [
22 'id', 'rank', 'title', 'slug', 'status', 'chapters'
25 data = self._api(
26 r'{manga(x:mr02,slug:"%(name)s"){%(keys)s{id,number,title,slug,date}}}'
27 % {'name': self.manga_name, 'keys': ','.join(keys)}
30 chapters = data.get('data', {}).get('manga', {}).get('chapters', []) # type: list
32 return chapters[::-1]
34 def get_files(self):
35 data = self._api(
36 r'{chapter(x:mr02,slug:"%(name)s",number:%(number)f){id,title,mangaID,number,slug,date,pages}}'
37 % {'name': self.manga_name, 'number': self.chapter['number']}
40 images = data.get('data', {}).get('chapter', {}).get('pages', [])
42 if type(images) == str:
43 images = self.json.loads(images) # type: list
45 return list(map(lambda x: '{}/{}'.format(self._cdn, images[x]), images))
47 def get_cover(self):
48 return self._cover_from_content('.manga-thumb')
50 def chapter_for_json(self) -> str:
51 number = str(self.chapter['number']).replace('.', '-')
52 slug = self.chapter['slug']
54 return '{}_{}'.format(number, slug)
56 def _api(self, query: str) -> dict:
57 response = self.http().requests(self._api_url, method='post', data={
58 "query": query,
59 }, headers={
60 'Accept': 'application/json',
63 return response.json()
66 main = MangaPandaCom