From 0a8c0c704d27fbff7328b94650b797ccb2383f16 Mon Sep 17 00:00:00 2001 From: Rodney Ewing Date: Thu, 15 Aug 2013 12:40:19 -0700 Subject: [PATCH] Keep the best quality file if there's no original --- mediagoblin/media_types/audio/processing.py | 15 ++++++++++++++- mediagoblin/media_types/pdf/processing.py | 2 +- mediagoblin/media_types/video/processing.py | 16 +++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/mediagoblin/media_types/audio/processing.py b/mediagoblin/media_types/audio/processing.py index 42855265..6a506741 100644 --- a/mediagoblin/media_types/audio/processing.py +++ b/mediagoblin/media_types/audio/processing.py @@ -52,7 +52,7 @@ class CommonAudioProcessor(MediaProcessor): """ Provides a base for various audio processing steps """ - acceptable_files = ['original', 'webm_audio'] + acceptable_files = ['original', 'best_quality', 'webm_audio'] def common_setup(self): """ @@ -76,6 +76,17 @@ class CommonAudioProcessor(MediaProcessor): 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 + """ + 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('webm_audio'): + self.entry.media_files['best_quality'] = self.entry \ + .media_files['webm_audio'] + def transcode(self, quality=None): if not quality: quality = self.audio_config['quality'] @@ -93,6 +104,8 @@ class CommonAudioProcessor(MediaProcessor): self.transcoder.discover(webm_audio_tmp) + self._keep_best() + _log.debug('Saving medium...') store_public(self.entry, 'webm_audio', webm_audio_tmp, self.name_builder.fill('{basename}.medium.webm')) diff --git a/mediagoblin/media_types/pdf/processing.py b/mediagoblin/media_types/pdf/processing.py index 6ef95a72..549def69 100644 --- a/mediagoblin/media_types/pdf/processing.py +++ b/mediagoblin/media_types/pdf/processing.py @@ -253,7 +253,7 @@ class CommonPdfProcessor(MediaProcessor): self._set_pdf_filename() def _set_pdf_filename(self): - if self.name_builder.ext == 'pdf': + if self.name_builder.ext == '.pdf': self.pdf_filename = self.process_filename elif self.entry.media_files.get('pdf'): self.pdf_filename = self.workbench.localized_file( diff --git a/mediagoblin/media_types/video/processing.py b/mediagoblin/media_types/video/processing.py index bb854ffb..a3aa9bcf 100644 --- a/mediagoblin/media_types/video/processing.py +++ b/mediagoblin/media_types/video/processing.py @@ -122,7 +122,7 @@ class CommonVideoProcessor(MediaProcessor): """ Provides a base for various video processing steps """ - acceptable_files = ['original', 'webm_640'] + acceptable_files = ['original', 'best_quality', 'webm_640'] def common_setup(self): self.video_config = mgg \ @@ -144,6 +144,18 @@ class CommonVideoProcessor(MediaProcessor): 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 + """ + 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('webm_640'): + self.entry.media_files['best_quality'] = self.entry \ + .media_files['webm_640'] + + def transcode(self, medium_size=None, vp8_quality=None, vp8_threads=None, vorbis_quality=None): progress_callback = ProgressCallback(self.entry) @@ -189,6 +201,8 @@ class CommonVideoProcessor(MediaProcessor): dst_dimensions = self.transcoder.dst_data.videowidth,\ self.transcoder.dst_data.videoheight + self._keep_best() + # Push transcoded video to public storage _log.debug('Saving medium...') store_public(self.entry, 'webm_640', tmp_dst, -- 2.25.1