Skip to content

Commit

Permalink
Fix bronze award regex and disabled other timing manga
Browse files Browse the repository at this point in the history
  • Loading branch information
s0hv committed Dec 6, 2023
1 parent c85e166 commit 26b9e10
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/scrapers/mangaplus/mangaplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from src.db.models.authors import AuthorPartial
from src.db.models.manga import MangaService
from src.enums import Status
from src.scrapers.base_scraper import BaseChapter, BaseScraperWhole, \
BaseScraper, ScrapeServiceRetVal
from src.scrapers.base_scraper import (BaseChapter, BaseScraperWhole,
BaseScraper, ScrapeServiceRetVal)
from src.utils.utilities import random_timedelta, utcnow, utcfromtimestamp
from .protobuf import mangaplus_pb2

Expand Down Expand Up @@ -245,7 +245,7 @@ class MangaPlus(BaseScraperWhole):
CHAPTER_REGEX = re.compile(r'#(\d+)')
SPECIAL_CHAPTER_REGEX = re.compile(r'\s*(#?ex)s*', re.I)
ONESHOT_REGEX = re.compile(r'\s*(one[- ]?shot)s*', re.I)
AWARD_REGEX = re.compile(r'\s*bronze award\s*', re.I)
AWARD_REGEX = re.compile(r'\s*bronze award(\s|:)*', re.I)
CHAPTER_URL_FORMAT = 'https://mangaplus.shueisha.co.jp/viewer/{}'
MANGA_URL_FORMAT = 'https://mangaplus.shueisha.co.jp/titles/{}'
GROUP = 'Shueisha'
Expand Down Expand Up @@ -402,11 +402,14 @@ def add_chapters(self, series: TitleDetailViewWrapper, service_id: int, manga_id

if series.release_schedule:
ReleaseSchedule = mangaplus_pb2.TitleLabels.ReleaseSchedule
if series.release_schedule == ReleaseSchedule.COMPLETED or series.release_schedule == ReleaseSchedule.DISABLED:
if series.release_schedule in (ReleaseSchedule.COMPLETED, ReleaseSchedule.DISABLED, ReleaseSchedule.OTHER):
next_update = None
disabled = True
completed = False

if series.release_schedule == ReleaseSchedule.OTHER:
logger.warning(f'Release schedule is OTHER for {self.NAME} title {series.title.name} / {series.title.title_id}. Disabling it.')

newest_chapter = None
for c in chapters:
if not newest_chapter:
Expand Down
27 changes: 27 additions & 0 deletions src/tests/scrapers/mangaplus/test_mangaplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class TestMangaPlusParser(BaseTestClasses.DatabaseTestCase):
request_data_award: bytes
request_data_hiatus: bytes
request_data_all: bytes
request_data_otherschedule: bytes

@staticmethod
def read_title_detail_data(status: str) -> bytes:
Expand All @@ -64,6 +65,7 @@ def setUpClass(cls) -> None:
cls.request_data_notfound = cls.read_title_detail_data('notfound')
cls.request_data_award = cls.read_title_detail_data('award')
cls.request_data_hiatus = cls.read_title_detail_data('hiatus')
cls.request_data_otherschedule = cls.read_title_detail_data('otherschedule')
cls.request_data_all = cls.read_all_titles_data()

def setUp(self) -> None:
Expand Down Expand Up @@ -190,6 +192,31 @@ def test_scrapes_correctly_for_complete_chapters(self):

self.assertMangaServiceDisabled(ms.service_id, ms.title_id)

@responses.activate
def test_scrapes_correctly_for_other_schedule_chapters(self):
ms, chapter_ids = self.setup_with_data(self.request_data_otherschedule)

self.assertIsNotNone(chapter_ids)
chapter_ids = cast(set[int], chapter_ids)
self.assertEqual(len(chapter_ids), 1)
self.assertEqual(len(responses.calls), 1)

inserted = self.dbutil.get_chapters(ms.manga_id, ms.service_id, limit=len(chapter_ids))

correct = Chapter(
manga_id=ms.manga_id,
service_id=ms.service_id,
title="Bronze Award: METRA-K",
chapter_number=0,
chapter_decimal=None,
release_date=utcfromtimestamp(1699887600),
chapter_identifier='1019511',
group_id=self.group_id
)

self.assertDbChaptersEqual(inserted[0], correct)
self.assertMangaServiceDisabled(ms.service_id, ms.title_id)

@responses.activate
def test_scrapes_correctly_for_oneshot(self):
ms, chapter_ids = self.setup_with_data(self.request_data_oneshot)
Expand Down
Binary file not shown.

0 comments on commit 26b9e10

Please sign in to comment.