Add main_transcoding_progress to ProgressCallback
authorvijeth-aradhya <vijthaaa@gmail.com>
Tue, 22 Aug 2017 08:00:13 +0000 (13:30 +0530)
committervijeth-aradhya <vijthaaa@gmail.com>
Tue, 22 Aug 2017 08:04:53 +0000 (13:34 +0530)
mediagoblin/media_types/video/transcoders.py
mediagoblin/processing/__init__.py

index a2c8f4316e382feac64dcc0716d633cfea321ec7..dbe56d9eb71f0703937d85e74b7cd3df613ed482 100644 (file)
@@ -190,6 +190,7 @@ class VideoTranscoder(object):
         # Get number of resolutions available for the video
         video_config = mgg.global_config['plugins']['mediagoblin.media_types.video']
         self.num_of_resolutions = len(video_config['available_resolutions'])
+        self.default_resolution = video_config['default_resolution']
 
         if not type(self.destination_dimensions) == tuple:
             raise Exception('dimensions must be tuple: (width, height)')
@@ -368,7 +369,10 @@ class VideoTranscoder(object):
                     percent_increment = percent - self.progress_percentage
                     self.progress_percentage = percent
                     if self._progress_callback:
-                        self._progress_callback(percent_increment/self.num_of_resolutions)
+                        if ACCEPTED_RESOLUTIONS[self.default_resolution] == self.destination_dimensions:
+                            self._progress_callback(percent_increment/self.num_of_resolutions, percent)
+                        else:
+                            self._progress_callback(percent_increment/self.num_of_resolutions)
                     _log.info('{percent}% of {dest} resolution done..'
                               '.'.format(percent=percent, dest=self.destination_dimensions))
                     _log.info('{0:.2f}% of all resolutions done'
index a9d5442b40abd7ee8d2289dbd25dc00468b9a378..2897b5e737a066ede50c718c13caf5d1c2f139b1 100644 (file)
@@ -39,12 +39,14 @@ class ProgressCallback(object):
     def __init__(self, entry):
         self.entry = entry
 
-    def __call__(self, progress):
+    def __call__(self, progress, default_quality_progress=None):
         if progress:
             if 100 - (self.entry.transcoding_progress + progress) < 0.01:
                 self.entry.transcoding_progress = 100
             else:
-                self.entry.transcoding_progress += progress
+                self.entry.transcoding_progress += round(progress, 2)
+            if default_quality_progress:
+                self.entry.main_transcoding_progress = default_quality_progress
             self.entry.save()