Browse Source

Add progress for peertube plugin

plugins
Zykino 2 years ago
parent
commit
b895a4543e
1 changed files with 40 additions and 39 deletions
  1. +40
    -39
      prismedia/plugins/platforms/peertube.py

+ 40
- 39
prismedia/plugins/platforms/peertube.py View File

@ -20,6 +20,7 @@ from clint.textui.progress import Bar as ProgressBar
from yapsy.PluginManager import PluginManagerSingleton
logger = logging.getLogger('Prismedia')
upload_finished = False
class Peertube(pi.IPlatformPlugin):
@ -327,11 +328,11 @@ class Peertube(pi.IPlatformPlugin):
exit(1)
encoder = MultipartEncoder(fields)
# if options.get('--quiet'):
multipart_data = encoder
# else:
# progress_callback = create_callback(encoder, options.get('--progress'))
# multipart_data = MultipartEncoderMonitor(encoder, progress_callback)
if options.get('--quiet'):
multipart_data = encoder
else:
progress_callback = self.create_callback(encoder, options.get('--progress'))
multipart_data = MultipartEncoderMonitor(encoder, progress_callback)
headers = {
'Content-Type': multipart_data.content_type
@ -359,40 +360,40 @@ class Peertube(pi.IPlatformPlugin):
'%s') % response)
exit(1)
# 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):
# # We want the condition to capture the varible from the parent scope, not a local variable that is created after
# global upload_finished
# progress = progress_lambda(monitor.bytes_read)
#
# bar.show(progress)
#
# if monitor.bytes_read == encoder.len:
# if not upload_finished:
# # We get two time in the callback with both bytes equals, skip the first
# upload_finished = True
# else:
# # Print a blank line to not (partly) override the progress bar
# print()
# logger.info("Peertube: Upload finish, Processing…")
#
# return callback
def create_callback(self, 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):
# We want the condition to capture the varible from the parent scope, not a local variable that is created after
global upload_finished
progress = progress_lambda(monitor.bytes_read)
bar.show(progress)
if monitor.bytes_read == encoder.len:
if not upload_finished:
# We get two time in the callback with both bytes equals, skip the first
upload_finished = True
else:
# Print a blank line to not (partly) override the progress bar
print()
logger.info("Peertube: Upload finish, Processing…")
return callback
def heartbeat(self):
"""

Loading…
Cancel
Save