55from datetime import datetime
66
77from natsort import humansorted , ns
8+ from prompt_toolkit .styles import Style
9+ from questionary import Choice , select
810from requests .exceptions import JSONDecodeError
911from rich .prompt import Confirm , Prompt
1012from simyan .comicvine import Comicvine as Simyan
1416from simyan .sqlite_cache import SQLiteCache
1517
1618from perdoo import get_cache_root
17- from perdoo .console import CONSOLE , create_menu
19+ from perdoo .console import CONSOLE
1820from perdoo .metadata import ComicInfo , MetronInfo
1921from perdoo .metadata .metron_info import InformationSource
2022from perdoo .services ._base import BaseService
2123from perdoo .settings import Comicvine as ComicvineSettings
2224from perdoo .utils import IssueSearch , Search , SeriesSearch
2325
2426LOGGER = logging .getLogger (__name__ )
27+ DEFAULT_CHOICE = Choice (title = "None of the Above" , value = None )
2528
2629
2730class Comicvine (BaseService [Volume , Issue ]):
@@ -42,27 +45,39 @@ def _search_series(self, name: str | None, volume: int | None, year: int | None)
4245 )
4346 if year :
4447 options = [x for x in options if x .start_year == year ]
45- if not options :
48+ if options :
49+ search = name
50+ if volume :
51+ search += f" v{ volume } "
52+ if year :
53+ search += f" ({ year } )"
54+ choices = [
55+ Choice (
56+ title = [
57+ (
58+ "class:dim" ,
59+ f"{ x .id } | { x .publisher .name if x .publisher and x .publisher .name else '' } | " , # noqa: E501
60+ ),
61+ ("class:title" , f"{ x .name } ({ x .start_year } )" ),
62+ ],
63+ description = f"https://comicvine.gamespot.com/volumes/4050-{ x .id } " ,
64+ value = x ,
65+ )
66+ for x in options
67+ ]
68+ choices .append (DEFAULT_CHOICE )
69+ selected = select (
70+ f"Searching for Comicvine Volume '{ search } '" ,
71+ default = DEFAULT_CHOICE ,
72+ choices = choices ,
73+ style = Style ([("dim" , "dim" )]),
74+ ).ask ()
75+ if selected and selected != DEFAULT_CHOICE .title :
76+ return selected .id
77+ else :
4678 LOGGER .warning (
4779 "Unable to find any Volumes with the Name and StartYear: '%s %s'" , name , year
4880 )
49- search = name
50- if volume :
51- search += f" v{ volume } "
52- if year :
53- search += f" ({ year } )"
54- index = create_menu (
55- options = [
56- f"{ x .id } | { x .publisher .name if x .publisher and x .publisher .name else '' } "
57- f" | { x .name } ({ x .start_year } )"
58- for x in options
59- ],
60- title = "Comicvine Volume" ,
61- subtitle = f"Searching for Volume '{ search } '" ,
62- default = "None of the Above" ,
63- )
64- if index != 0 :
65- return options [index - 1 ].id
6681 if year :
6782 LOGGER .info ("Searching again without the StartYear" )
6883 return self ._search_series (name = name , volume = volume , year = None )
@@ -111,14 +126,33 @@ def _search_issue(self, series_id: int, number: str | None) -> int | None:
111126 series_id ,
112127 number ,
113128 )
114- index = create_menu (
115- options = [f"{ x .id } | { x .number } - { x .name or '' } " for x in options ],
116- title = "Comicvine Issue" ,
117- subtitle = f"Searching for Issue #{ number } " if number else "" ,
118- default = "None of the Above" ,
119- )
120- if index != 0 :
121- return options [index - 1 ].id
129+ if options :
130+ choices = [
131+ Choice (
132+ title = [
133+ ("class:dim" , f"{ x .id } | " ),
134+ ("class:title" , f"{ x .number } - { x .name or '' } " ),
135+ ],
136+ description = f"https://comicvine.gamespot.com/issues/4000-{ x .id } " ,
137+ value = x ,
138+ )
139+ for x in options
140+ ]
141+ choices .append (DEFAULT_CHOICE )
142+ selected = select (
143+ f"Searching for Comicvine Issue #{ number } " ,
144+ default = DEFAULT_CHOICE ,
145+ choices = choices ,
146+ style = Style ([("dim" , "dim" )]),
147+ ).ask ()
148+ if selected and selected != DEFAULT_CHOICE .title :
149+ return selected .id
150+ else :
151+ LOGGER .warning (
152+ "Unable to find any Issues with the Volume and IssueNumber: '%s %s'" ,
153+ series_id ,
154+ number ,
155+ )
122156 if number :
123157 LOGGER .info ("Searching again without the IssueNumber" )
124158 return self ._search_issue (series_id = series_id , number = None )
0 commit comments