Skip to content

Commit

Permalink
MangaPlus: Disable other release schedule only if no new chapters in …
Browse files Browse the repository at this point in the history
…60 days
  • Loading branch information
s0hv committed Dec 9, 2023
1 parent aa6e1d2 commit 67d1931
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/scrapers/mangaplus/mangaplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,16 +400,13 @@ def add_chapters(self, series: TitleDetailViewWrapper, service_id: int, manga_id
disabled = True
completed = True

ReleaseSchedule = mangaplus_pb2.TitleLabels.ReleaseSchedule
if series.release_schedule:
ReleaseSchedule = mangaplus_pb2.TitleLabels.ReleaseSchedule
if series.release_schedule in (ReleaseSchedule.COMPLETED, ReleaseSchedule.DISABLED, ReleaseSchedule.OTHER):
if series.release_schedule in (ReleaseSchedule.COMPLETED, ReleaseSchedule.DISABLED):
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 All @@ -419,6 +416,16 @@ def add_chapters(self, series: TitleDetailViewWrapper, service_id: int, manga_id
if c.chapter_number > newest_chapter.chapter_number:
newest_chapter = c

if (not next_update and
newest_chapter and
series.release_schedule == ReleaseSchedule.OTHER and
utcnow() - newest_chapter.release_date > timedelta(days=60)
):
next_update = None
disabled = True

logger.info(f'No new chapters for {self.NAME} title {series.title.name} / {series.title.title_id} in 60 days. Disabling it.')

with self.conn.transaction():
with self.conn.cursor() as cursor:
inserted = self.dbutil.add_chapters(new_chapters, fetch=True)
Expand Down
3 changes: 2 additions & 1 deletion src/tests/scrapers/mangaplus/test_mangaplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ def test_scrapes_correctly_for_other_schedule_chapters(self):
)

self.assertDbChaptersEqual(inserted[0], correct)
self.assertMangaServiceDisabled(ms.service_id, ms.title_id)
# TODO this test will fail in time due to timedelta checks. When that happens change to assertMangaServiceDisabled
self.assertMangaServiceEnabled(ms.service_id, ms.title_id)

@responses.activate
def test_scrapes_correctly_for_oneshot(self):
Expand Down

0 comments on commit 67d1931

Please sign in to comment.