backup
This commit is contained in:
parent
ce341fe360
commit
4dae1d037f
BIN
__pycache__/Loader.cpython-310.pyc
Normal file
BIN
__pycache__/Loader.cpython-310.pyc
Normal file
Binary file not shown.
65
main.py
65
main.py
@ -33,40 +33,20 @@ class Loader:
|
|||||||
logging.debug(f"Found {len(mp4_files)} .mp4 files in {root_folder_name}")
|
logging.debug(f"Found {len(mp4_files)} .mp4 files in {root_folder_name}")
|
||||||
yield root_folder_name, mp4_files
|
yield root_folder_name, mp4_files
|
||||||
for dir in self.__find_empty_folders():
|
for dir in self.__find_empty_folders():
|
||||||
relative_path = os.path.relpath(dir, self.directory)
|
logging.debug(f"Found no .mp4 files in {dir}")
|
||||||
logging.debug(f"Found no .mp4 files in {relative_path}")
|
yield dir, []
|
||||||
yield relative_path, []
|
|
||||||
for dir in self.__find_folders_without_mp4():
|
|
||||||
relative_path = os.path.relpath(dir, self.directory)
|
|
||||||
logging.debug(f"Found no .mp4 files in {relative_path}")
|
|
||||||
yield relative_path, []
|
|
||||||
|
|
||||||
def __find_empty_folders(self):
|
def __find_empty_folders(self):
|
||||||
"""Finds and returns a list of empty folders in the given directory."""
|
"""Yield folder names that do not contain any mp4 files in a given directory."""
|
||||||
empty_folders = []
|
for folder in os.listdir(self.directory):
|
||||||
|
folder_path = os.path.join(self.directory, folder)
|
||||||
|
|
||||||
for root, dirs, files in os.walk(self.directory):
|
if os.path.isdir(folder_path): # Ensure it's a directory
|
||||||
if not files and not dirs: # If the folder contains no files or subdirectories
|
has_mp4 = any(file.endswith(".mp4") for file in os.listdir(folder_path))
|
||||||
empty_folders.append(root)
|
|
||||||
|
|
||||||
return empty_folders
|
if not has_mp4:
|
||||||
def __find_folders_without_mp4(self):
|
yield folder # Yield the folder name if no mp4 files found
|
||||||
"""
|
|
||||||
Finds folders that are either empty or contain no .mp4 files.
|
|
||||||
|
|
||||||
:param root_dir: The directory to search within.
|
|
||||||
:return: List of folders that are empty or have no .mp4 files.
|
|
||||||
"""
|
|
||||||
result_folders = []
|
|
||||||
|
|
||||||
for foldername, subfolders, filenames in os.walk(self.directory):
|
|
||||||
# Check if the folder is empty or has no MP4 files
|
|
||||||
folder_name = os.path.relpath(foldername, self.directory)
|
|
||||||
if not any(file.lower().endswith('.mp4') for file in filenames):
|
|
||||||
if (folder_name != "."):
|
|
||||||
result_folders.append(foldername)
|
|
||||||
|
|
||||||
return result_folders
|
|
||||||
def __remove_year(self, input_string: str):
|
def __remove_year(self, input_string: str):
|
||||||
cleaned_string = re.sub(r'\(\d{4}\)', '', input_string).strip()
|
cleaned_string = re.sub(r'\(\d{4}\)', '', input_string).strip()
|
||||||
logging.debug(f"Removed year from '{input_string}' -> '{cleaned_string}'")
|
logging.debug(f"Removed year from '{input_string}' -> '{cleaned_string}'")
|
||||||
@ -95,11 +75,36 @@ class Loader:
|
|||||||
season = match.group(1)
|
season = match.group(1)
|
||||||
episode = match.group(2)
|
episode = match.group(2)
|
||||||
logging.debug(f"Extracted season {season}, episode {episode} from '{filename}'")
|
logging.debug(f"Extracted season {season}, episode {episode} from '{filename}'")
|
||||||
return season, episode
|
return int(season), int(episode)
|
||||||
else:
|
else:
|
||||||
logging.error(f"Failed to find season/episode pattern in '{filename}'")
|
logging.error(f"Failed to find season/episode pattern in '{filename}'")
|
||||||
raise MatchNotFoundError("Season and episode pattern not found in the filename.")
|
raise MatchNotFoundError("Season and episode pattern not found in the filename.")
|
||||||
|
|
||||||
|
def __GetEpisodesAndSeasons(self, mp4_files: []):
|
||||||
|
episodes_dict = {}
|
||||||
|
|
||||||
|
for file in mp4_files:
|
||||||
|
season, episode = self.__GetEpisodeAndSeason(file)
|
||||||
|
|
||||||
|
if season in episodes_dict:
|
||||||
|
episodes_dict[season].append(episode)
|
||||||
|
else:
|
||||||
|
episodes_dict[season] = [episode]
|
||||||
|
|
||||||
|
return episodes_dict
|
||||||
|
|
||||||
|
def __GetMissingEpisodesAndSeason(self, key: str, mp4_files: []):
|
||||||
|
expected_dict = get_season_episode_count(key) # key season , value count of episodes
|
||||||
|
filedict = self.__GetEpisodesAndSeasons(mp4_files)
|
||||||
|
|
||||||
|
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]
|
||||||
|
|
||||||
|
if missing_episodes:
|
||||||
|
yield season, missing_episodes
|
||||||
|
|
||||||
|
|
||||||
def LoadMissing(self):
|
def LoadMissing(self):
|
||||||
logging.info("Starting process to load missing episodes")
|
logging.info("Starting process to load missing episodes")
|
||||||
result = self.__find_mp4_files()
|
result = self.__find_mp4_files()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user