From bd0b36be7916f756a701f29bb6b0aff8cb624f9c Mon Sep 17 00:00:00 2001 From: vijeth-aradhya Date: Sun, 25 Jun 2017 20:23:37 +0530 Subject: [PATCH] Implement copy_original and _keep_best _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 | 35 ++++++++++++++++++--- mediagoblin/media_types/video/util.py | 13 ++++---- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/mediagoblin/media_types/video/processing.py b/mediagoblin/media_types/video/processing.py index ee2aa443..f2fba38e 100644 --- a/mediagoblin/media_types/video/processing.py +++ b/mediagoblin/media_types/video/processing.py @@ -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) diff --git a/mediagoblin/media_types/video/util.py b/mediagoblin/media_types/video/util.py index 1f5e907d..cf8dc72d 100644 --- a/mediagoblin/media_types/video/util.py +++ b/mediagoblin/media_types/video/util.py @@ -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__) -- 2.25.1