Skip to content

Commit 4e71e2f

Browse files
committed
[mangafreak] update & fix
- fix manga and title extraction - fix 'chapter_minor' - extend test results
1 parent 58662f9 commit 4e71e2f

File tree

2 files changed

+73
-33
lines changed

2 files changed

+73
-33
lines changed

gallery_dl/extractor/mangafreak.py

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# -*- coding: utf-8 -*-
22

3-
# Copyright 2025 Mike Fährmann
4-
#
53
# This program is free software; you can redistribute it and/or modify
64
# it under the terms of the GNU General Public License version 2 as
75
# published by the Free Software Foundation.
@@ -11,7 +9,7 @@
119
from .common import ChapterExtractor, MangaExtractor
1210
from .. import text
1311

14-
BASE_PATTERN = r"(?:https?://)?(?:ww\d\.)?mangafreak\.me"
12+
BASE_PATTERN = r"(?:https?://)?(?:ww[\dw]\.)?mangafreak\.me"
1513

1614

1715
class MangafreakBase():
@@ -22,33 +20,30 @@ class MangafreakBase():
2220

2321
class MangafreakChapterExtractor(MangafreakBase, ChapterExtractor):
2422
"""Extractor for mangafreak manga chapters"""
25-
pattern = BASE_PATTERN + r"(/Read1_(.+)_(\d+[a-z]?))"
23+
pattern = BASE_PATTERN + r"(/Read1_([^/?#]+)_((\d+)([a-z])?))"
2624
example = "https://ww2.mangafreak.me/Read1_Onepunch_Man_1"
2725

2826
def metadata(self, page):
29-
extr = text.extract_from(page)
30-
manga = text.unescape(extr("<title>", " Chapter "))
31-
title = text.unescape(extr("", " - MangaFreak"))
32-
33-
chapter_str = self.groups[2]
34-
chapter, sep, minor = chapter_str.partition("e")
27+
manga = text.extr(page, "<title>Read ", " Chapter ")
28+
title = text.extr(page, 'selected="selected">', "<").partition(": ")[2]
29+
_, manga_slug, chapter_string, chapter, minor = self.groups
3530

3631
return {
37-
"manga" : manga,
38-
"title" : title,
32+
"manga" : text.unescape(manga),
33+
"manga_slug" : manga_slug,
34+
"title" : text.unescape(title) if title else "",
3935
"chapter" : text.parse_int(chapter),
40-
"chapter_minor": sep + minor,
41-
"chapter_string": chapter_str,
42-
"manga_slug" : self.groups[1],
36+
"chapter_minor": "" if minor is None else minor,
37+
"chapter_string": chapter_string,
4338
"lang" : "en",
4439
"language" : "English",
4540
}
4641

4742
def images(self, page):
43+
base = "https://images.mangafreak.me/mangas/"
4844
return [
49-
("https://images.mangafreak.me/mangas/" + path, None)
50-
for path in text.extract_iter(
51-
page, 'src="https://images.mangafreak.me/mangas/', '"')
45+
(base + path, None)
46+
for path in text.extract_iter(page, 'src="' + base, '"')
5247
]
5348

5449

@@ -59,34 +54,32 @@ class MangafreakMangaExtractor(MangafreakBase, MangaExtractor):
5954
example = "https://ww2.mangafreak.me/Manga/Onepunch_Man"
6055

6156
def chapters(self, page):
62-
extr = text.extract_from(page)
63-
manga = text.unescape(extr("<title>", " Manga"))
64-
65-
chapter_table = text.extr(page, "<table>", "</table>")
66-
if not chapter_table:
67-
return []
57+
table = text.extr(page, "<table>", "</table>")
58+
if not table:
59+
return ()
6860

6961
data = {
70-
"manga" : manga,
62+
"manga" : text.unescape(text.extr(page, "<title>", " Manga")),
7163
"manga_slug": self.groups[1],
7264
"lang" : "en",
7365
"language" : "English",
7466
}
7567

7668
results = []
77-
for row in text.extract_iter(chapter_table, "<tr>", "</tr>"):
69+
chapter_match = text.re(r"(\d+)(\w*)").match
70+
for row in text.extract_iter(table, "<tr>", "</tr>"):
7871
href = text.extr(row, '<a href="', '"')
7972
if not href:
8073
continue
8174
url = self.root + href
82-
chapter_str = url.rpartition("_")[2]
83-
chapter, sep, minor = chapter_str.partition("e")
84-
75+
chapter_string = href.rpartition("_")[2]
76+
chapter, minor = chapter_match(chapter_string).groups()
77+
title = text.extr(row, '">', '<').partition(" - ")[2]
8578
results.append((url, {
86-
"chapter" : text.parse_int(chapter),
87-
"chapter_minor": sep + minor,
88-
"chapter_string": chapter_str,
79+
"chapter" : text.parse_int(chapter),
80+
"chapter_minor" : minor,
81+
"chapter_string": chapter_string,
82+
"title" : text.unescape(title) if title else "",
8983
**data,
9084
}))
91-
9285
return results

test/results/mangafreak.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,37 @@
3232
"chapter_string": "167e",
3333
},
3434

35+
{
36+
"#url" : "https://ww2.mangafreak.me/Read1_Sss_Rank_Dungeon_De_Knife_Ippon_Tewatasare_Tsuihou_Sareta_Shiro_Madoushi_Yggdrasil_No_Noroi_Ni_Yori_Jakuten_De_Aru_Maryoku_Fusoku_Wo_Kokufuku_Shi_Sekai_Saikyou_E_To_Itaru_23c",
37+
"#class" : mangafreak.MangafreakChapterExtractor,
38+
"#pattern" : r"https://images\.mangafreak\.me/mangas/sss_rank_dungeon_de_knife_ippon_tewatasare_tsuihou_sareta_shiro_madoushi_yggdrasil_no_noroi_ni_yori_jakuten_de_aru_maryoku_fusoku_wo_kokufuku_shi_sekai_saikyou_e_to_itaru/sss_rank_dungeon_de_knife_ippon_tewatasare_tsuihou_sareta_shiro_madoushi_yggdrasil_no_noroi_ni_yori_jakuten_de_aru_maryoku_fusoku_wo_kokufuku_shi_sekai_saikyou_e_to_itaru_23c/sss_rank_dungeon_de_knife_ippon_tewatasare_tsuihou_sareta_shiro_madoushi_yggdrasil_no_noroi_ni_yori_jakuten_de_aru_maryoku_fusoku_wo_kokufuku_shi_sekai_saikyou_e_to_itaru_23c_\d+\.jpg",
39+
"#count" : 11,
40+
41+
"chapter" : 23,
42+
"chapter_minor" : "c",
43+
"chapter_string": "23c",
44+
"count" : 11,
45+
"page" : range(1, 11),
46+
"filename" : str,
47+
"extension" : "jpg",
48+
"lang" : "en",
49+
"language" : "English",
50+
"manga" : "Sss Rank Dungeon De Knife Ippon Tewatasare Tsuihou Sareta Shiro Madoushi Yggdrasil No Noroi Ni Yori Jakuten De Aru Maryoku Fusoku Wo Kokufuku Shi Sekai Saikyou E To Itaru",
51+
"manga_slug" : "Sss_Rank_Dungeon_De_Knife_Ippon_Tewatasare_Tsuihou_Sareta_Shiro_Madoushi_Yggdrasil_No_Noroi_Ni_Yori_Jakuten_De_Aru_Maryoku_Fusoku_Wo_Kokufuku_Shi_Sekai_Saikyou_E_To_Itaru",
52+
"title" : "",
53+
},
54+
55+
{
56+
"#url" : "https://ww2.mangafreak.me/Read1_Tensei_Shitara_Slime_Datta_Ken_62",
57+
"#class" : mangafreak.MangafreakChapterExtractor,
58+
"#count" : 19,
59+
60+
"chapter" : 62,
61+
"count" : 19,
62+
"manga" : "Tensei Shitara Slime Datta Ken",
63+
"title" : "To be a Monster or Human",
64+
},
65+
3566
{
3667
"#url" : "https://ww2.mangafreak.me/Manga/Onepunch_Man",
3768
"#class" : mangafreak.MangafreakMangaExtractor,
@@ -45,4 +76,20 @@
4576
"chapter" : int,
4677
},
4778

79+
{
80+
"#url" : "https://ww2.mangafreak.me/Manga/Sss_Rank_Dungeon_De_Knife_Ippon_Tewatasare_Tsuihou_Sareta_Shiro_Madoushi_Yggdrasil_No_Noroi_Ni_Yori_Jakuten_De_Aru_Maryoku_Fusoku_Wo_Kokufuku_Shi_Sekai_Saikyou_E_To_Itaru",
81+
"#class" : mangafreak.MangafreakMangaExtractor,
82+
"#pattern" : mangafreak.MangafreakChapterExtractor.pattern,
83+
"#count" : range(40, 80),
84+
85+
"chapter" : int,
86+
"chapter_minor" : {"", "a", "b", "c"},
87+
"chapter_string": str,
88+
"lang" : "en",
89+
"language" : "English",
90+
"manga" : "SSS Rank Dungeon de Knife Ippon Tewatasare Tsuihou Sareta Shiro Madoushi: Yggdrasil no Noroi ni yori Jakuten de aru Maryoku Fusoku wo Kokufuku-shi Sekai Saikyou e to Itaru",
91+
"manga_slug" : "Sss_Rank_Dungeon_De_Knife_Ippon_Tewatasare_Tsuihou_Sareta_Shiro_Madoushi_Yggdrasil_No_Noroi_Ni_Yori_Jakuten_De_Aru_Maryoku_Fusoku_Wo_Kokufuku_Shi_Sekai_Saikyou_E_To_Itaru",
92+
"title" : str,
93+
},
94+
4895
)

0 commit comments

Comments
 (0)