Keep the best quality file if there's no original
authorRodney Ewing <ewing.rj@gmail.com>
Thu, 15 Aug 2013 19:40:19 +0000 (12:40 -0700)
committerRodney Ewing <ewing.rj@gmail.com>
Fri, 16 Aug 2013 22:30:23 +0000 (15:30 -0700)
mediagoblin/media_types/audio/processing.py
mediagoblin/media_types/pdf/processing.py
mediagoblin/media_types/video/processing.py

index 4285526506f636bb64e0d5d5e8607b4e827c7577..6a506741e09062a31c01d2a01ca180ba8a713056 100644 (file)
@@ -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'))
index 6ef95a72e32461be60dad2131d0cc3b7b2068bf6..549def695f991bbea532c524ec2a5127b7ab548b 100644 (file)
@@ -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(
index bb854ffb18a07e3b2e856204878f9b90628dbd23..a3aa9bcf05dd023fc9a5af0854f7689e40ec6385 100644 (file)
@@ -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,