AlexandreSenpai / Enma

Enma is a Python library designed to fetch and download manga and doujinshi data from many sources including Manganato and NHentai.
MIT License
80 stars 16 forks source link

Fixed bugs in repositories/manganato.py #67

Closed NokutokaMomiji closed 3 months ago

NokutokaMomiji commented 3 months ago

Issues with the Manganato repository source

Issues

  1. In the get method, the format string "%b %d,%Y - %I:%M %p" expects the hour to be in the 12-hour format. However, Manganato displays time in the 24-hour format, which triggers a ValueError exception.

from enma import Enma, DefaultAvailableSources

enma = Enma[DefaultAvailableSources]()
enma.source_manager.set_source("manganato")

test = enma.get(identifier="manga-um997395")

r"""
  File "D:\Archivos de Usuario\Escritorio\Stuff\Projects\external\Enma\enma\infra\adapters\repositories\manganato.py", line 152, in get
    created_at=datetime.strptime(updated_at, "%b %d,%Y - %I:%M %p") if updated_at else None,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Archivos de Programas\Python 3.11.2\Lib\_strptime.py", line 568, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Archivos de Programas\Python 3.11.2\Lib\_strptime.py", line 349, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data 'Mar 08,2024 - 14:47 PM' does not match format '%b %d,%Y - %I:%M %p'
"""
  1. The __create_title method assumes that the manga title will contain at least two alternatives. However, certain posts in Manganato have a singular alternative. Trying to unpack the values triggers a ValueError exception.
from enma import Enma, DefaultAvailableSources

enma = Enma[DefaultAvailableSources]()
enma.source_manager.set_source("manganato")

test = enma.get(identifier="manga-dj980492")

r"""
  File "D:\Archivos de Usuario\Escritorio\Stuff\Projects\external\Enma\enma\infra\adapters\repositories\manganato.py", line 124, in get
    title = self.__create_title(main_title=elem_title,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Archivos de Usuario\Escritorio\Stuff\Projects\external\Enma\enma\infra\adapters\repositories\manganato.py", line 48, in __create_title
    jp, cn, *_ = alternative.split(';') if alternative.find(';') != -1 else alternative.split(',')
    ^^^^^^^^^^
ValueError: not enough values to unpack (expected at least 2, got 1)
"""

Proposed solutions

  1. Change the format string from "%b %d,%Y - %I:%M %p" to "%b %d,%Y - %H:%M %p" to accept 24-hour formatted data.

  2. Add a check to see whether there are no multiple available alternative strings, and act accordingly.

has_many_alternatives = alternative.find(';') != -1 or alternative.find(',') != -1

if not has_many_alternatives:
    jp = alternative
    return Title(english=main_title.strip(),
                 japanese=jp.strip(),
                 other=main_title.strip())
AlexandreSenpai commented 3 months ago

Approved. Thank you very much for your contrib (●'◡'●)