better output
This commit is contained in:
parent
03bbb224ad
commit
c3f9e4aa84
56
src/Main.py
56
src/Main.py
@ -2,6 +2,7 @@ import sys
|
||||
import os
|
||||
import logging
|
||||
from src.Loaders import AniWorldLoader
|
||||
import progressbar
|
||||
import SerieList
|
||||
import SerieScanner
|
||||
from src.Loaders.Loaders import Loaders
|
||||
@ -37,6 +38,8 @@ class SeriesApp:
|
||||
def __init__(self, directory_to_search: str):
|
||||
|
||||
print("Please wait while initializing...")
|
||||
self.barTotal = None
|
||||
self.bar = None
|
||||
self.directory_to_search = directory_to_search
|
||||
self.Loaders = Loaders()
|
||||
loader = self.Loaders.GetLoader(key="aniworld.to")
|
||||
@ -87,11 +90,6 @@ class SeriesApp:
|
||||
print("No valid series selected. Going back to the result display.")
|
||||
return None
|
||||
|
||||
def print_progress_bar(self, current, total, length=20):
|
||||
"""Generate progress bar string"""
|
||||
filled_length = int(length * current // total)
|
||||
bar = "@" * filled_length + "-" * (length - filled_length)
|
||||
return f"[{bar}] {current} / {total}"
|
||||
|
||||
def retry(self, func, max_retries=3, delay=2, *args, **kwargs):
|
||||
for attempt in range(1, max_retries + 1):
|
||||
@ -111,28 +109,39 @@ class SeriesApp:
|
||||
"""Simulate the downloading process with a progress bar."""
|
||||
total_downloaded = 0
|
||||
total_episodes = sum(sum(len(ep) for ep in serie.episodeDict.values()) for serie in series)
|
||||
self.barTotal = progressbar.ProgressBar(
|
||||
max_value=total_episodes,
|
||||
widgets=[
|
||||
progressbar.FormatLabel(f'Processing:'),
|
||||
' ', progressbar.Percentage(),
|
||||
' ', progressbar.Bar(),
|
||||
' ', progressbar.ETA()
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
for serie in series:
|
||||
serie_episodes = sum(len(ep) for ep in serie.episodeDict.values())
|
||||
downloaded = 0
|
||||
|
||||
print(f"\nStarting download for {serie.folder}...\n")
|
||||
|
||||
self.bar = progressbar.ProgressBar(
|
||||
max_value=serie_episodes,
|
||||
widgets=[
|
||||
progressbar.FormatLabel(f'Processing {serie.name}:'),
|
||||
' ', progressbar.Percentage(),
|
||||
' ', progressbar.Bar(),
|
||||
' ', progressbar.ETA()
|
||||
]
|
||||
)
|
||||
for season, episodes in serie.episodeDict.items():
|
||||
for episode in episodes:
|
||||
loader = self.Loaders.GetLoader(key="aniworld.to")
|
||||
if loader.IsLanguage(season, episode, serie.key):
|
||||
print(f"\ndownload {serie.folder} {season} {episode}\n")
|
||||
self.retry(loader.Download, 3, 1, self.directory_to_search, serie.folder, season, episode, serie.key)
|
||||
|
||||
downloaded += 1
|
||||
total_downloaded += 1
|
||||
progress = self.print_progress_bar(downloaded, serie_episodes)
|
||||
total_progress = self.print_progress_bar(total_downloaded, total_episodes)
|
||||
|
||||
sys.stdout.write(f"\r{serie.name}: {progress} (Total: {total_progress})")
|
||||
sys.stdout.flush()
|
||||
print("\nDownload complete!\n")
|
||||
self.bar.update(downloaded)
|
||||
self.bar.update(total_downloaded)
|
||||
|
||||
|
||||
def search_mode(self):
|
||||
@ -165,6 +174,9 @@ class SeriesApp:
|
||||
except ValueError:
|
||||
print("Invalid input. Try again.")
|
||||
|
||||
def updateFromReinit(self, folder, counter):
|
||||
if self.bar != None:
|
||||
self.bar.update(counter)
|
||||
|
||||
def run(self):
|
||||
"""Main function to run the app."""
|
||||
@ -177,8 +189,16 @@ class SeriesApp:
|
||||
|
||||
print("\nRescanning series...\n")
|
||||
|
||||
self.bar = progressbar.ProgressBar(
|
||||
max_value=progressbar.UnknownLength,
|
||||
widgets=[
|
||||
progressbar.Counter(), ' items processed ',
|
||||
progressbar.AnimatedMarker()
|
||||
]
|
||||
)
|
||||
|
||||
self.SerieScanner.Reinit()
|
||||
self.SerieScanner.Scan()
|
||||
self.SerieScanner.Scan(self.updateFromReinit)
|
||||
|
||||
self.List = SerieList.SerieList(self.directory_to_search)
|
||||
self.__InitList__()
|
||||
@ -186,10 +206,6 @@ class SeriesApp:
|
||||
selected_series = self.get_user_selection()
|
||||
if selected_series:
|
||||
self.download_series(selected_series)
|
||||
print("\nProgress: [@@@@@@@@@@@@@@@@@@@@] Complete")
|
||||
break
|
||||
else:
|
||||
print("Invalid action. Please enter 'search' or 'local'.")
|
||||
|
||||
# Run the app
|
||||
if __name__ == "__main__":
|
||||
|
||||
@ -21,12 +21,19 @@ class SerieScanner:
|
||||
|
||||
def is_null_or_whitespace(self, s):
|
||||
return s is None or s.strip() == ""
|
||||
def Scan(self):
|
||||
|
||||
def GetTotalToScan(self):
|
||||
result = self.__find_mp4_files()
|
||||
return sum(1 for _ in result)
|
||||
|
||||
def Scan(self, callback):
|
||||
logging.info("Starting process to load missing episodes")
|
||||
result = self.__find_mp4_files()
|
||||
|
||||
counter = 0
|
||||
for folder, mp4_files in result:
|
||||
try:
|
||||
counter += 1
|
||||
callback(folder, counter)
|
||||
serie = self.__ReadDataFromFile(folder)
|
||||
if (serie != None and not self.is_null_or_whitespace(serie.key)):
|
||||
missings, site = self.__GetMissingEpisodesAndSeason(serie.key, mp4_files)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user