mirror of
https://git.lecygnenoir.info/LecygneNoir/prismedia.git
synced 2025-10-03 01:19:15 +02:00
Make it possible to choose between multiples tipes of progress bar
This commit is contained in:
parent
09c2d84357
commit
93f1205ab8
2 changed files with 32 additions and 9 deletions
|
@ -305,7 +305,7 @@ def upload_video(oauth, secret, options):
|
||||||
logger_stdout = logging.getLogger('stdoutlogs')
|
logger_stdout = logging.getLogger('stdoutlogs')
|
||||||
|
|
||||||
encoder = MultipartEncoder(fields)
|
encoder = MultipartEncoder(fields)
|
||||||
progress_callback = create_callback(encoder)
|
progress_callback = create_callback(encoder, options.get('--progress'))
|
||||||
multipart_data = MultipartEncoderMonitor(encoder, progress_callback)
|
multipart_data = MultipartEncoderMonitor(encoder, progress_callback)
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
|
@ -338,20 +338,32 @@ def upload_video(oauth, secret, options):
|
||||||
'%s') % response)
|
'%s') % response)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
upload_finished = False
|
|
||||||
def create_callback(encoder):
|
|
||||||
encoder_len = encoder.len
|
|
||||||
upload_size_MB = encoder_len * (1 / (1024 * 1024))
|
|
||||||
|
|
||||||
bar = ProgressBar(expected_size=100, label=f"Peertube upload progress ({upload_size_MB:.2f}MB) ", filled_char='=')
|
upload_finished = False
|
||||||
|
def create_callback(encoder, progress_type):
|
||||||
|
upload_size_MB = encoder.len * (1 / (1024 * 1024))
|
||||||
|
|
||||||
|
if progress_type is None or "percentage" in progress_type.lower():
|
||||||
|
progress_lambda = lambda x: int((x / encoder.len) * 100) # Default to percentage
|
||||||
|
elif "bigfile" in progress_type.lower():
|
||||||
|
progress_lambda = lambda x: x * (1 / (1024 * 1024)) # MB
|
||||||
|
elif "accurate" in progress_type.lower():
|
||||||
|
progress_lambda = lambda x: x * (1 / (1024)) # kB
|
||||||
|
else:
|
||||||
|
# Should not happen outside of development when adding partly a progress type
|
||||||
|
logger.critical("Peertube: Unknown progress type `" + progress_type + "`")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
bar = ProgressBar(expected_size=progress_lambda(encoder.len), label=f"Peertube upload progress ({upload_size_MB:.2f}MB) ", filled_char='=')
|
||||||
|
|
||||||
def callback(monitor):
|
def callback(monitor):
|
||||||
# We want the condition to capture the varible from the parent scope, not a local variable that is created after
|
# We want the condition to capture the varible from the parent scope, not a local variable that is created after
|
||||||
global upload_finished
|
global upload_finished
|
||||||
percentage = int((monitor.bytes_read / encoder_len) * 100)
|
progress = progress_lambda(monitor.bytes_read)
|
||||||
bar.show(percentage)
|
|
||||||
|
|
||||||
if monitor.bytes_read == encoder_len:
|
bar.show(progress)
|
||||||
|
|
||||||
|
if monitor.bytes_read == encoder.len:
|
||||||
if not upload_finished:
|
if not upload_finished:
|
||||||
# We get two time in the callback with both bytes equals, skip the first
|
# We get two time in the callback with both bytes equals, skip the first
|
||||||
upload_finished = True
|
upload_finished = True
|
||||||
|
|
|
@ -49,6 +49,7 @@ Options:
|
||||||
If the playlist is not found, spawn an error except if --playlistCreate is set.
|
If the playlist is not found, spawn an error except if --playlistCreate is set.
|
||||||
--playlistCreate Create the playlist if not exists. (default do not create)
|
--playlistCreate Create the playlist if not exists. (default do not create)
|
||||||
Only relevant if --playlist is set.
|
Only relevant if --playlist is set.
|
||||||
|
--progress=STRING Set the progress bar view, one of percentage, bigFile, accurate.
|
||||||
-h --help Show this help.
|
-h --help Show this help.
|
||||||
--version Show version.
|
--version Show version.
|
||||||
|
|
||||||
|
@ -150,6 +151,7 @@ VALID_LANGUAGES = ('arabic', 'english', 'french',
|
||||||
'german', 'hindi', 'italian',
|
'german', 'hindi', 'italian',
|
||||||
'japanese', 'korean', 'mandarin',
|
'japanese', 'korean', 'mandarin',
|
||||||
'portuguese', 'punjabi', 'russian', 'spanish')
|
'portuguese', 'punjabi', 'russian', 'spanish')
|
||||||
|
VALID_PROGRESS = ('percentage', 'bigfile', 'accurate')
|
||||||
|
|
||||||
|
|
||||||
def validateVideo(path):
|
def validateVideo(path):
|
||||||
|
@ -235,6 +237,14 @@ def validateLogLevel(loglevel):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def validateProgress(progress):
|
||||||
|
for prgs in progress.split(','):
|
||||||
|
if prgs.lower().replace(" ", "") not in VALID_PROGRESS:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def _optionnalOrStrict(key, scope, error):
|
def _optionnalOrStrict(key, scope, error):
|
||||||
option = key.replace('-', '')
|
option = key.replace('-', '')
|
||||||
option = option[0].upper() + option[1:]
|
option = option[0].upper() + option[1:]
|
||||||
|
@ -385,6 +395,7 @@ def main():
|
||||||
Optional('--channelCreate'): bool,
|
Optional('--channelCreate'): bool,
|
||||||
Optional('--playlist'): Or(None, str),
|
Optional('--playlist'): Or(None, str),
|
||||||
Optional('--playlistCreate'): bool,
|
Optional('--playlistCreate'): bool,
|
||||||
|
Optional('--progress'): Or(None, And(str, validateProgress, error="Sorry, progress visualisation not supported")),
|
||||||
'--help': bool,
|
'--help': bool,
|
||||||
'--version': bool,
|
'--version': bool,
|
||||||
# This allow to return all other options for further use: https://github.com/keleshev/schema#extra-keys
|
# This allow to return all other options for further use: https://github.com/keleshev/schema#extra-keys
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue