Skip to content

Commit

Permalink
allow hide parts progress
Browse files Browse the repository at this point in the history
allow to hide parts progress for files with too many parts and show overall progress on top
  • Loading branch information
MarekVigas authored and setnicka committed Oct 23, 2022
1 parent 080c71e commit 3c02bb0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 3 additions & 1 deletion uldlib/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def run():
help="URL from Uloz.to (tip: enter in 'quotes' because the URL contains ! sign)")
parser.add_argument('--parts', metavar='N', type=int, default=20,
help='Number of parts that will be downloaded in parallel')
parser.add_argument('--parts-progress', default=False, action='store_true',
help='Show progress of parts while being downloaded')
parser.add_argument('--output', metavar='DIRECTORY',
type=str, default="./", help='Target directory')
parser.add_argument('--auto-captcha', default=False, action="store_true",
Expand All @@ -32,7 +34,7 @@ def run():
args = parser.parse_args()

# TODO: implement other frontends and allow to choose from them
frontend = ConsoleFrontend()
frontend = ConsoleFrontend(args)

tfull_available = importlib.util.find_spec('tensorflow.lite')
tflite_available = importlib.util.find_spec('tflite_runtime')
Expand Down
19 changes: 11 additions & 8 deletions uldlib/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,19 @@ def run(self, parts: List[DownloadPart], stop_event: threading.Event, terminate_

class ConsoleFrontend(Frontend):
cli_initialized: bool
show_parts_progress: bool

last_log: Tuple[str, LogLevel]

last_captcha_log: Tuple[str, LogLevel]
last_captcha_stats: Dict[str, int]

def __init__(self):
def __init__(self, args):
self.cli_initialized = False
self.last_log = ("", LogLevel.INFO)
self.last_captcha_log = ("", LogLevel.INFO)
self.last_captcha_stats = None
self.show_parts_progress = args.parts_progress

def captcha_log(self, msg: str, level: LogLevel = LogLevel.INFO):
self.last_captcha_log = (msg, level)
Expand Down Expand Up @@ -153,13 +155,7 @@ def _loop(self, info: DownloadInfo, parts: List[DownloadPart], stop_event: threa
lines.append(self._color(line, level))
s += size

# Print parts
for (line, part) in zip(lines, parts):
self._print(
colors.blue(f"[Part {part.id}]") + f"\t{line}",
y=(part.id + CLI_STATUS_STARTLINE))

y = info.parts + CLI_STATUS_STARTLINE
y = CLI_STATUS_STARTLINE

# Print CAPTCHA/TOR status
(msg, level) = self.last_captcha_log
Expand Down Expand Up @@ -211,6 +207,13 @@ def _loop(self, info: DownloadInfo, parts: List[DownloadPart], stop_event: threa
)
y += 1

# Print parts
if self.show_parts_progress:
for (line, part) in zip(lines, parts):
self._print(
colors.blue(f"[Part {part.id}]") + f"\t{line}",
y=(y + part.id))

time.sleep(0.5)

if self.cli_initialized:
Expand Down

0 comments on commit 3c02bb0

Please sign in to comment.