Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rawkuma] Add rawkuma extractor #4571

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gallery_dl/extractor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"pornpics",
"postmill",
"pururin",
"rawkuma",
"reactor",
"readcomiconline",
"reddit",
Expand Down
97 changes: 97 additions & 0 deletions gallery_dl/extractor/rawkuma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# -*- coding: utf-8 -*-

"""Extractors for https://rawkuma.com/"""

from .common import MangaExtractor, ChapterExtractor
from .. import text, util
import re

BASE_PATTERN = r"(?:https?://)?rawkuma\.com"


class RawkumaBase():
"""Base class for rawkuma extractors"""
category = "rawkuma"
root = "https://rawkuma.com"

def get_title(self, page):
title = text.extr(page, 'property="og:title" content="', '"')
title = text.unescape(title).strip()
m = re.search(
r"(.+) (?:Manga|Chapter \d+) (?:Raw - Rawkuma)", title)
if m:
title = m.group(1)
return title


class RawkumaChapterExtractor(RawkumaBase, ChapterExtractor):
"""Extractor for manga chapters from rawkuma.com"""
archive_fmt = "{chapter_id}_{page}"
pattern = BASE_PATTERN + r"/([\w\d-]+)-chapter-(\d+)"
example = "https://rawkuma.com/ID-chapter-1"

def __init__(self, match):
url = match.group(0)
self.gid, self.chapter = match.groups()
ChapterExtractor.__init__(self, match, url)

def metadata(self, page):
title = self.get_title(page)
chapter, sep, minor = self.chapter.partition(".")
return {
"manga": title,
"manga_id": self.gid,
"chapter": text.parse_int(chapter),
"chapter_minor": sep + minor,
"chapter_id": "%s-chapter-%s" % (self.gid, self.chapter),
}

def images(self, page):
results = []
pos = 0
json, pos = text.extract(page, "<script>ts_reader.run(",
");</script>", pos)
json_data = util.json_loads(json)
source = json_data.get("sources", [{}])[0]
images = source.get("images", [])

for url in images:
results.append((url, None))

return results


class RawkumaMangaExtractor(RawkumaBase, MangaExtractor):
"""Extractor for manga from rawkuma.com"""
chapterclass = RawkumaChapterExtractor
pattern = BASE_PATTERN + r"/manga/([\w\d-]+)"
example = "https://rawkuma.com/manga/ID"

def __init__(self, match):
url, self.gid = match.group(0), match.group(1)
MangaExtractor.__init__(self, match, url)

def chapters(self, page):
results = []
pos = 0
title = self.get_title(page)

while True:
chapter_id, pos = \
text.extract(page, '<div class="eph-num">\n'
'<a href="https://rawkuma.com/',
'/"', pos)
if not chapter_id:
return results
url = text.urljoin(self.root, chapter_id)
# chapter, pos = text.extract(page,
# '<span class="chapternum">Chapter ', '<', pos)
data = {
"manga_id": self.gid,
"chapter_id": chapter_id,
"title": title,
}
chapter_match = re.search(r"\d+$", chapter_id)
if chapter_match:
data["chapter"] = chapter_match.group(0)
results.append((url, data))
Loading