4040extension_output = config_manager .get ("M3U8_CONVERSION" , "extension" )
4141
4242
43- def download_video (index_season_selected : int , index_episode_selected : int , scape_info_serie : GetSerieInfo ) -> Tuple [str ,bool ]:
43+ def download_video (index_season_selected : int , index_episode_selected : int , scrape_serie : GetSerieInfo ) -> Tuple [str ,bool ]:
4444 """
4545 Downloads a specific episode from a specified season.
4646
4747 Parameters:
4848 - index_season_selected (int): Season number
4949 - index_episode_selected (int): Episode index
50- - scape_info_serie (GetSerieInfo): Scraper object with series information
50+ - scrape_serie (GetSerieInfo): Scraper object with series information
5151
5252 Returns:
5353 - str: Path to downloaded file
@@ -56,13 +56,13 @@ def download_video(index_season_selected: int, index_episode_selected: int, scap
5656 start_message ()
5757
5858 # Get episode information
59- obj_episode = scape_info_serie .selectEpisode (index_season_selected , index_episode_selected - 1 )
60- index_season_selected = dynamic_format_number (str (index_season_selected ))
61- console .print (f"\n [bold yellow]Download:[/bold yellow] [red]{ site_constant .SITE_NAME } [/red] → [cyan]{ scape_info_serie .tv_name } [/cyan] \\ [bold magenta]{ obj_episode .get ('name' )} [/bold magenta] ([cyan]S{ index_season_selected } E{ index_episode_selected } [/cyan]) \n " )
59+ obj_episode = scrape_serie .selectEpisode (index_season_selected , index_episode_selected - 1 )
60+ index_season_selected_formatted = dynamic_format_number (str (index_season_selected ))
61+ console .print (f"\n [bold yellow]Download:[/bold yellow] [red]{ site_constant .SITE_NAME } [/red] → [cyan]{ scrape_serie .tv_name } [/cyan] \\ [bold magenta]{ obj_episode .get ('name' )} [/bold magenta] ([cyan]S{ index_season_selected_formatted } E{ index_episode_selected } [/cyan]) \n " )
6262
6363 # Define filename and path for the downloaded video
64- mp4_name = f"{ map_episode_title (scape_info_serie .tv_name , index_season_selected , index_episode_selected , obj_episode .get ('name' ))} .{ extension_output } "
65- mp4_path = os .path .join (site_constant .SERIES_FOLDER , scape_info_serie .tv_name , f"S{ index_season_selected } " )
64+ mp4_name = f"{ map_episode_title (scrape_serie .tv_name , index_season_selected_formatted , index_episode_selected , obj_episode .get ('name' ))} .{ extension_output } "
65+ mp4_path = os .path .join (site_constant .SERIES_FOLDER , scrape_serie .tv_name , f"S{ index_season_selected_formatted } " )
6666
6767 # Setup video source
6868 video_source = VideoSource (obj_episode .get ('url' ))
@@ -85,40 +85,38 @@ def download_video(index_season_selected: int, index_episode_selected: int, scap
8585 return hls_process ['path' ], hls_process ['stopped' ]
8686
8787
88- def download_episode (scape_info_serie : GetSerieInfo , index_season_selected : int , download_all : bool = False , episode_selection : str = None ) -> None :
88+ def download_episode (index_season_selected : int , scrape_serie : GetSerieInfo , download_all : bool = False , episode_selection : str = None ) -> None :
8989 """
9090 Handle downloading episodes for a specific season.
9191
9292 Parameters:
93- - scape_info_serie (GetSerieInfo): Scraper object with series information
9493 - index_season_selected (int): Season number
94+ - scrape_serie (GetSerieInfo): Scraper object with series information
9595 - download_all (bool): Whether to download all episodes
9696 - episode_selection (str, optional): Pre-defined episode selection that bypasses manual input
9797 """
98- # Get episodes for the selected season
99- episodes = scape_info_serie . get_episode_number (index_season_selected )
98+ # Get episodes for the selected season using the new method
99+ episodes = scrape_serie . getEpisodeSeasons (index_season_selected )
100100 episodes_count = len (episodes )
101101
102102 if episodes_count == 0 :
103103 console .print (f"[red]No episodes found for season { index_season_selected } " )
104104 return
105105
106106 if download_all :
107-
108107 # Download all episodes in the season
109108 for i_episode in range (1 , episodes_count + 1 ):
110- path , stopped = download_video (index_season_selected , i_episode , scape_info_serie )
109+ path , stopped = download_video (index_season_selected , i_episode , scrape_serie )
111110
112111 if stopped :
113112 break
114113
115114 console .print (f"\n [red]End downloaded [yellow]season: [red]{ index_season_selected } ." )
116115
117116 else :
118-
119117 # Display episodes list and manage user selection
120118 if episode_selection is None :
121- last_command = display_episodes_list (scape_info_serie . list_episodes )
119+ last_command = display_episodes_list (episodes )
122120 else :
123121 last_command = episode_selection
124122 console .print (f"\n [cyan]Using provided episode selection: [yellow]{ episode_selection } " )
@@ -129,7 +127,7 @@ def download_episode(scape_info_serie: GetSerieInfo, index_season_selected: int,
129127
130128 # Download selected episodes
131129 for i_episode in list_episode_select :
132- path , stopped = download_video (index_season_selected , i_episode , scape_info_serie )
130+ path , stopped = download_video (index_season_selected , i_episode , scrape_serie )
133131
134132 if stopped :
135133 break
@@ -148,7 +146,9 @@ def download_series(dict_serie: MediaItem, season_selection: str = None, episode
148146
149147 # Create class
150148 scrape_serie = GetSerieInfo (dict_serie )
151- seasons_count = scrape_serie .get_seasons_number ()
149+
150+ # Get number of seasons
151+ seasons_count = scrape_serie .getNumberSeason ()
152152
153153 # If season_selection is provided, use it instead of asking for input
154154 if season_selection is None :
@@ -163,7 +163,19 @@ def download_series(dict_serie: MediaItem, season_selection: str = None, episode
163163
164164 # Loop through the selected seasons and download episodes
165165 for i_season in list_season_select :
166- if len (list_season_select ) > 1 or index_season_selected == "*" :
167- download_episode (scrape_serie , i_season , download_all = True )
168- else :
169- download_episode (scrape_serie , i_season , download_all = False , episode_selection = episode_selection )
166+ try :
167+ season = scrape_serie .seasons_manager .get_season_by_number (i_season )
168+ if not season :
169+ console .print (f"[red]Season { i_season } not found! Available seasons: { [s .number for s in scrape_serie .seasons_manager .seasons ]} " )
170+ continue
171+
172+ season_number = season .number
173+
174+ if len (list_season_select ) > 1 or index_season_selected == "*" :
175+ download_episode (season_number , scrape_serie , download_all = True )
176+ else :
177+ download_episode (season_number , scrape_serie , download_all = False , episode_selection = episode_selection )
178+
179+ except Exception as e :
180+ console .print (f"[red]Error processing season { i_season } : { str (e )} " )
181+ continue
0 commit comments