refactor: Apply PEP8 naming conventions - convert PascalCase methods to snake_case
This comprehensive refactoring applies PEP8 naming conventions across the codebase: ## Core Changes: ### src/cli/Main.py - Renamed __InitList__() to __init_list__() - Renamed print_Download_Progress() to print_download_progress() - Fixed variable naming: task3 -> download_progress_task - Fixed parameter spacing: words :str -> words: str - Updated all method calls to use snake_case - Added comprehensive docstrings ### src/core/SerieScanner.py - Renamed Scan() to scan() - Renamed GetTotalToScan() to get_total_to_scan() - Renamed Reinit() to reinit() - Renamed private methods to snake_case: - __ReadDataFromFile() -> __read_data_from_file() - __GetMissingEpisodesAndSeason() -> __get_missing_episodes_and_season() - __GetEpisodeAndSeason() -> __get_episode_and_season() - __GetEpisodesAndSeasons() -> __get_episodes_and_seasons() - Added comprehensive docstrings to all methods - Fixed long line issues ### src/core/providers/base_provider.py - Refactored abstract base class with proper naming: - Search() -> search() - IsLanguage() -> is_language() - Download() -> download() - GetSiteKey() -> get_site_key() - GetTitle() -> get_title() - Added proper type hints (Dict, List, etc.) - Added comprehensive docstrings explaining contracts - Fixed newline at end of file ### src/core/providers/aniworld_provider.py - Renamed public methods to snake_case: - Search() -> search() - IsLanguage() -> is_language() - Download() -> download() - GetSiteKey() -> get_site_key() - GetTitle() -> get_title() - ClearCache() -> clear_cache() - RemoveFromCache() -> remove_from_cache() - Renamed private methods to snake_case: - _GetLanguageKey() -> _get_language_key() - _GetKeyHTML() -> _get_key_html() - _GetEpisodeHTML() -> _get_episode_html() - Fixed import organization - Improved code formatting and line lengths - Added docstrings to all methods ### src/core/SeriesApp.py - Updated all calls to use new snake_case method names - Updated loader calls: loader.Search() -> loader.search() - Updated loader calls: loader.Download() -> loader.download() - Updated scanner calls: SerieScanner.GetTotalToScan() -> SerieScanner.get_total_to_scan() - Updated scanner calls: SerieScanner.Reinit() -> SerieScanner.reinit() - Updated scanner calls: SerieScanner.Scan() -> SerieScanner.scan() ### tests/unit/test_series_app.py - Updated mock calls to use new snake_case method names: - get_total_to_scan() instead of GetTotalToScan() - reinit() instead of Reinit() - scan() instead of Scan() ## Verification: - All unit tests pass ✅ - All integration tests pass ✅ - All tests pass ✅ - No breaking changes to functionality ## Standards Applied: - PEP 8: Function/method names use lowercase with underscores (snake_case) - PEP 257: Added comprehensive docstrings - Type hints: Proper type annotations where applicable - Code formatting: Fixed line lengths and spacing
This commit is contained in:
@@ -62,20 +62,31 @@ class SerieScanner:
|
||||
"""Get the callback manager instance."""
|
||||
return self._callback_manager
|
||||
|
||||
def Reinit(self):
|
||||
def reinit(self):
|
||||
"""Reinitialize the folder dictionary."""
|
||||
self.folderDict: dict[str, Serie] = {}
|
||||
|
||||
def is_null_or_whitespace(self, s):
|
||||
"""Check if a string is None or whitespace."""
|
||||
"""Check if a string is None or whitespace.
|
||||
|
||||
Args:
|
||||
s: String value to check
|
||||
|
||||
Returns:
|
||||
True if string is None or contains only whitespace
|
||||
"""
|
||||
return s is None or s.strip() == ""
|
||||
|
||||
def GetTotalToScan(self):
|
||||
"""Get the total number of folders to scan."""
|
||||
def get_total_to_scan(self):
|
||||
"""Get the total number of folders to scan.
|
||||
|
||||
Returns:
|
||||
Total count of folders with MP4 files
|
||||
"""
|
||||
result = self.__find_mp4_files()
|
||||
return sum(1 for _ in result)
|
||||
|
||||
def Scan(self, callback: Optional[Callable[[str, int], None]] = None):
|
||||
def scan(self, callback: Optional[Callable[[str, int], None]] = None):
|
||||
"""
|
||||
Scan directories for anime series and missing episodes.
|
||||
|
||||
@@ -105,7 +116,7 @@ class SerieScanner:
|
||||
|
||||
try:
|
||||
# Get total items to process
|
||||
total_to_scan = self.GetTotalToScan()
|
||||
total_to_scan = self.get_total_to_scan()
|
||||
logger.info("Total folders to scan: %d", total_to_scan)
|
||||
|
||||
result = self.__find_mp4_files()
|
||||
@@ -139,13 +150,15 @@ class SerieScanner:
|
||||
if callback:
|
||||
callback(folder, counter)
|
||||
|
||||
serie = self.__ReadDataFromFile(folder)
|
||||
serie = self.__read_data_from_file(folder)
|
||||
if (
|
||||
serie is not None
|
||||
and not self.is_null_or_whitespace(serie.key)
|
||||
):
|
||||
missings, site = self.__GetMissingEpisodesAndSeason(
|
||||
serie.key, mp4_files
|
||||
missings, site = (
|
||||
self.__get_missing_episodes_and_season(
|
||||
serie.key, mp4_files
|
||||
)
|
||||
)
|
||||
serie.episodeDict = missings
|
||||
serie.folder = folder
|
||||
@@ -274,8 +287,15 @@ class SerieScanner:
|
||||
)
|
||||
return cleaned_string
|
||||
|
||||
def __ReadDataFromFile(self, folder_name: str):
|
||||
"""Read serie data from file or key file."""
|
||||
def __read_data_from_file(self, folder_name: str):
|
||||
"""Read serie data from file or key file.
|
||||
|
||||
Args:
|
||||
folder_name: Name of the folder containing serie data
|
||||
|
||||
Returns:
|
||||
Serie object if found, None otherwise
|
||||
"""
|
||||
folder_path = os.path.join(self.directory, folder_name)
|
||||
key = None
|
||||
key_file = os.path.join(folder_path, 'key')
|
||||
@@ -302,8 +322,18 @@ class SerieScanner:
|
||||
|
||||
return None
|
||||
|
||||
def __GetEpisodeAndSeason(self, filename: str):
|
||||
"""Extract season and episode numbers from filename."""
|
||||
def __get_episode_and_season(self, filename: str):
|
||||
"""Extract season and episode numbers from filename.
|
||||
|
||||
Args:
|
||||
filename: Filename to parse
|
||||
|
||||
Returns:
|
||||
Tuple of (season, episode) as integers
|
||||
|
||||
Raises:
|
||||
MatchNotFoundError: If pattern not found
|
||||
"""
|
||||
pattern = r'S(\d+)E(\d+)'
|
||||
match = re.search(pattern, filename)
|
||||
if match:
|
||||
@@ -325,12 +355,19 @@ class SerieScanner:
|
||||
"Season and episode pattern not found in the filename."
|
||||
)
|
||||
|
||||
def __GetEpisodesAndSeasons(self, mp4_files: list):
|
||||
"""Get episodes grouped by season from mp4 files."""
|
||||
def __get_episodes_and_seasons(self, mp4_files: list):
|
||||
"""Get episodes grouped by season from mp4 files.
|
||||
|
||||
Args:
|
||||
mp4_files: List of MP4 filenames
|
||||
|
||||
Returns:
|
||||
Dictionary mapping season to list of episode numbers
|
||||
"""
|
||||
episodes_dict = {}
|
||||
|
||||
for file in mp4_files:
|
||||
season, episode = self.__GetEpisodeAndSeason(file)
|
||||
season, episode = self.__get_episode_and_season(file)
|
||||
|
||||
if season in episodes_dict:
|
||||
episodes_dict[season].append(episode)
|
||||
@@ -338,23 +375,29 @@ class SerieScanner:
|
||||
episodes_dict[season] = [episode]
|
||||
return episodes_dict
|
||||
|
||||
def __GetMissingEpisodesAndSeason(self, key: str, mp4_files: list):
|
||||
"""Get missing episodes for a serie."""
|
||||
def __get_missing_episodes_and_season(self, key: str, mp4_files: list):
|
||||
"""Get missing episodes for a serie.
|
||||
|
||||
Args:
|
||||
key: Series key
|
||||
mp4_files: List of MP4 filenames
|
||||
|
||||
Returns:
|
||||
Tuple of (episodes_dict, site_name)
|
||||
"""
|
||||
# key season , value count of episodes
|
||||
expected_dict = self.loader.get_season_episode_count(key)
|
||||
filedict = self.__GetEpisodesAndSeasons(mp4_files)
|
||||
filedict = self.__get_episodes_and_seasons(mp4_files)
|
||||
episodes_dict = {}
|
||||
for season, expected_count in expected_dict.items():
|
||||
existing_episodes = filedict.get(season, [])
|
||||
missing_episodes = [
|
||||
ep for ep in range(1, expected_count + 1)
|
||||
if ep not in existing_episodes
|
||||
and self.loader.IsLanguage(season, ep, key)
|
||||
and self.loader.is_language(season, ep, key)
|
||||
]
|
||||
|
||||
if missing_episodes:
|
||||
episodes_dict[season] = missing_episodes
|
||||
|
||||
return episodes_dict, "aniworld.to"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user