Skip to content

Commit

Permalink
Merge pull request #83 from mansuf/bugs/#82
Browse files Browse the repository at this point in the history
Fix "cover" command is failing
  • Loading branch information
mansuf authored Jul 9, 2023
2 parents bca6328 + 6d4e93b commit f9a6bcd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
15 changes: 15 additions & 0 deletions mangadex_downloader/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
from ..mdlist import MangaDexList
from ..group import Group
from ..cover import CoverArt, cover_qualities
from ..language import get_language

def preview_chapter(chapter: Chapter):
try:
Expand Down Expand Up @@ -630,9 +631,15 @@ def __init__(self, parser, args, input_text):
if quality not in cover_qualities:
parser.error(f"{quality} is not valid quality covers")

from ..config import config
vcl = config.volume_cover_language
cover_locale = vcl if vcl else config.language
cover_locale = get_language(cover_locale)

manga = Manga(_id=manga_id)
iterator = CoverArtURLIterator(manga_id, quality)
text = f"List of covers art from manga '{manga.title}' in {quality} quality"
text += f" ({cover_locale.name} language)"

super().__init__(
parser,
Expand All @@ -641,6 +648,8 @@ def __init__(self, parser, args, input_text):
text,
)

self.cover_locale = cover_locale
self.manga = manga
self.manga_id = manga_id
self.quality = quality
self.limit = 10
Expand All @@ -661,6 +670,12 @@ def prompt(self, input_pos=None):

return result

def on_empty_error(self):
self.args_parser.error(
f"Manga {self.manga.title!r} doesn't " \
f"have {self.cover_locale.name!r} covers"
)

registered_commands = {
"search": SearchMangaCommand,
"fetch_library_manga": MangaLibraryCommand,
Expand Down
8 changes: 7 additions & 1 deletion mangadex_downloader/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ def __init__(self, cover_id=None, data=None):
pass

def __str__(self) -> str:
return f"Cover volume {self.volume}"
from .config import config

msg = f"Cover volume {self.volume}"
if config.language == "all" or config.volume_cover_language == "all":
msg += f" in {self.locale.name} language"

return msg

@property
def volume(self):
Expand Down
4 changes: 3 additions & 1 deletion mangadex_downloader/iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,11 @@ def fill_data(self):
"manga[]": self.manga_id,
"offset": self.offset,
"limit": self.limit,
"locales[]": cover_locale
}

if cover_locale != "all":
params.update({"locales[]": cover_locale})

url = f"{base_url}/cover"
r = Net.mangadex.get(url, params=params)
items = r.json()["data"]
Expand Down

0 comments on commit f9a6bcd

Please sign in to comment.