Implement copy_original and _keep_best
authorvijeth-aradhya <vijthaaa@gmail.com>
Sun, 25 Jun 2017 14:53:37 +0000 (20:23 +0530)
committervijeth-aradhya <vijthaaa@gmail.com>
Sun, 25 Jun 2017 15:52:30 +0000 (21:22 +0530)
_keep_best is changed to keep_best now, and is added in processing_cleanup.
webm is added to ACCEPTED_RESOLUTIONS.

mediagoblin/media_types/video/processing.py
mediagoblin/media_types/video/util.py

index ee2aa443ed607f942b886f3b206a60b7dd945864..f2fba38ef9a143d8a7f05a2c59b03ab294d354bd 100644 (file)
@@ -198,6 +198,10 @@ def processing_cleanup(entry_id):
     print "\nEntered processing_cleanup()\n"
     entry, manager = get_entry_and_processing_manager(entry_id)
     with CommonVideoProcessor(manager, entry) as processor:
+        # no need to specify a resolution here
+        processor.common_setup()
+        processor.copy_original()
+        processor.keep_best()
         processor.delete_queue_file()
         print "\nDeleted queue_file\n"
 
@@ -235,13 +239,36 @@ class CommonVideoProcessor(MediaProcessor):
 
     def copy_original(self):
         # If we didn't transcode, then we need to keep the original
-        raise NotImplementedError
-
-    def _keep_best(self):
+        self.did_transcode = False
+        for each_res in self.video_config['available_resolutions']:
+            if ('webm_' + str(each_res)) in self.entry.media_files:
+                print "here  ==  1.1"
+                self.did_transcode = True
+                break
+        if not self.did_transcode or \
+           (self.video_config['keep_original'] and self.did_transcode):
+            copy_original(
+                self.entry, self.process_filename,
+                self.name_builder.fill('{basename}{ext}'))
+
+    def keep_best(self):
         """
         If there is no original, keep the best file that we have
         """
-        raise NotImplementedError
+        best_file = None
+        best_file_dim = (0, 0)
+        for each_res in self.video_config['available_resolutions']:
+            curr_dim = ACCEPTED_RESOLUTIONS[each_res]
+            if curr_dim[0] >= best_file_dim[0] and curr_dim[1] >= best_file_dim[1]:
+                best_file = each_res
+                best_file_dim = curr_dim
+        if not self.entry.media_files.get('best_quality'):
+            # Save the best quality file if no original?
+            if not self.entry.media_files.get('original') and \
+                    self.entry.media_files.get(str(best_file)):
+                self.entry.media_files['best_quality'] = self.entry \
+                    .media_files[str(best_file)]
+
 
     def _skip_processing(self, keyname, **kwargs):
         file_metadata = self.entry.get_file_metadata(keyname)
index 1f5e907da9a9c589e797d9028eeb2ad103efec65..cf8dc72d495cc9209ea1143bc358f58655249997 100644 (file)
@@ -19,12 +19,13 @@ import logging
 from mediagoblin import mg_globals as mgg
 
 ACCEPTED_RESOLUTIONS = {
-    '144p' : (256, 144),
-    '240p' : (352, 240),
-    '360p' : (480, 360),
-    '480p' : (858, 480),
-    '720p' : (1280, 720),
-    '1080p' : (1920, 1080),
+    '144p': (256, 144),
+    '240p': (352, 240),
+    '360p': (480, 360),
+    '480p': (858, 480),
+    '720p': (1280, 720),
+    '1080p': (1920, 1080),
+    'webm': (640, 640),
 }
 
 _log = logging.getLogger(__name__)