Fixes for small bugs
authorBoris Bobrov <breton@cynicmansion.ru>
Thu, 12 Jul 2018 16:27:44 +0000 (18:27 +0200)
committerBoris Bobrov <breton@cynicmansion.ru>
Thu, 12 Jul 2018 16:27:44 +0000 (18:27 +0200)
There were some blocking issues in the code. They are small, but break
tests and/or production. Fixed some of them.

mediagoblin/media_types/video/__init__.py
mediagoblin/media_types/video/processing.py
mediagoblin/media_types/video/transcoders.py
mediagoblin/tests/test_submission.py
mediagoblin/tests/test_video.py

index ea7bc0217675d1314a08f5f41d9bbfb41fdfb189..0c822f69820499fd3acd7a1e678c9056f536b942 100644 (file)
@@ -40,7 +40,7 @@ class VideoMediaManager(MediaManagerBase):
         video_res = video_config['available_resolutions']
         video_res.remove(video_config['default_resolution'])
         video_res.insert(0, video_config['default_resolution'])
-        video_res = map((lambda x: unicode('webm_' + str(x), 'utf-8')), video_res)
+        video_res = ['webm_{}'.format(x) for x in video_res]
         return ([u'webm_video'] + video_res + [u'original'])
 
 
index c72c12f21b836dc013dd03720aeb771bb0b80ed8..c377d100a0a3b5c5ae9089704847dd8d17f06df5 100644 (file)
@@ -172,29 +172,34 @@ def main_task(entry_id, resolution, medium_size, **process_info):
     entry, manager = get_entry_and_processing_manager(entry_id)
     with CommonVideoProcessor(manager, entry) as processor:
         processor.common_setup(resolution)
-        processor.transcode(medium_size=tuple(medium_size), vp8_quality=process_info['vp8_quality'],
-                            vp8_threads=process_info['vp8_threads'], vorbis_quality=process_info['vorbis_quality'])
+        processor.transcode(medium_size=tuple(medium_size),
+                            vp8_quality=process_info['vp8_quality'],
+                            vp8_threads=process_info['vp8_threads'],
+                            vorbis_quality=process_info['vorbis_quality'])
         processor.generate_thumb(thumb_size=process_info['thumb_size'])
         processor.store_orig_metadata()
     # Make state of entry as processed
     entry.state = u'processed'
     entry.save()
-    _log.info(u'MediaEntry ID {0} is processed (transcoded to default resolution'
-              '): {1}'.format(unicode(entry.id), unicode(medium_size)))
+    _log.info(u'MediaEntry ID {0} is processed (transcoded to default'
+              ' resolution): {1}'.format(entry.id, medium_size))
     _log.debug('MediaEntry processed')
 
 
 @celery.task()
-def complementary_task(entry_id, resolution, medium_size, **process_info):    
+def complementary_task(entry_id, resolution, medium_size, **process_info):
     """
     Side celery task to transcode the video to other resolutions
     """
     entry, manager = get_entry_and_processing_manager(entry_id)
     with CommonVideoProcessor(manager, entry) as processor:
         processor.common_setup(resolution)
-        processor.transcode(medium_size=tuple(medium_size), vp8_quality=process_info['vp8_quality'],
-                            vp8_threads=process_info['vp8_threads'], vorbis_quality=process_info['vorbis_quality'])
-    _log.info(u'MediaEntry ID {0} is transcoded to {1}'.format(unicode(entry.id), unicode(medium_size)))
+        processor.transcode(medium_size=tuple(medium_size),
+                            vp8_quality=process_info['vp8_quality'],
+                            vp8_threads=process_info['vp8_threads'],
+                            vorbis_quality=process_info['vorbis_quality'])
+    _log.info(u'MediaEntry ID {0} is transcoded to {1}'.format(
+        entry.id, medium_size))
 
 
 @celery.task()
@@ -215,7 +220,7 @@ class CommonVideoProcessor(MediaProcessor):
     Provides a base for various video processing steps
     """
     acceptable_files = ['original, best_quality', 'webm_144p', 'webm_360p',
-                        'webm_480p', 'webm_720p', 'webm_1080p', 'webm_video'] 
+                        'webm_480p', 'webm_720p', 'webm_1080p', 'webm_video']
 
     def common_setup(self, resolution=None):
         self.video_config = mgg \
@@ -225,7 +230,7 @@ class CommonVideoProcessor(MediaProcessor):
         self.process_filename = get_process_filename(
             self.entry, self.workbench, self.acceptable_files)
         self.name_builder = FilenameBuilder(self.process_filename)
-        
+
         self.transcoder = transcoders.VideoTranscoder()
         self.did_transcode = False
 
@@ -336,7 +341,12 @@ class CommonVideoProcessor(MediaProcessor):
 
         else:
             _log.debug('Entered transcoder')
+            video_config = (mgg.global_config['plugins']
+                            ['mediagoblin.media_types.video'])
+            num_res = len(video_config['available_resolutions'])
+            default_res = video_config['default_resolution']
             self.transcoder.transcode(self.process_filename, tmp_dst,
+                                      default_res, num_res,
                                       vp8_quality=vp8_quality,
                                       vp8_threads=vp8_threads,
                                       vorbis_quality=vorbis_quality,
@@ -569,7 +579,7 @@ class VideoProcessingManager(ProcessingManager):
 
     def workflow(self, entry, feed_url, reprocess_action, reprocess_info=None):
 
-        video_config = mgg.global_config['plugins'][MEDIA_TYPE]        
+        video_config = mgg.global_config['plugins'][MEDIA_TYPE]
         def_res = video_config['default_resolution']
         priority_num = len(video_config['available_resolutions']) + 1
 
index 75f5ef862b06085ebf0a8efd510de7b0842c6ecb..d6aae7cf2bd284b45adff9e4b527fcc19022b0b6 100644 (file)
@@ -158,7 +158,7 @@ class VideoTranscoder(object):
         self.progress_percentage = 0
         self.loop = GLib.MainLoop()
 
-    def transcode(self, src, dst, **kwargs):
+    def transcode(self, src, dst, default_res, num_res, **kwargs):
         '''
         Transcode a video file into a 'medium'-sized version.
         '''
@@ -187,9 +187,8 @@ class VideoTranscoder(object):
         self._progress_callback = kwargs.get('progress_callback') or None
 
         # 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']
+        self.num_of_resolutions = num_res
+        self.default_resolution = default_res
 
         if not type(self.destination_dimensions) == tuple:
             raise Exception('dimensions must be tuple: (width, height)')
index f08a25f0a4253a134c53033dbb4dfe84b968dd07..a7661e85020d640d4591c5ef420f97aa428a68fc 100644 (file)
@@ -47,7 +47,10 @@ import os
 import pytest
 import webtest.forms
 import pkg_resources
-import mock
+try:
+    import mock
+except ImportError:
+    import unittest.mock as mock
 
 import six.moves.urllib.parse as urlparse
 
@@ -635,7 +638,7 @@ class TestSubmissionVideo(BaseTestSubmission):
         manager.workflow(entry, feed_url=None, reprocess_action='initial')
 
         # test section
-        mock_main_task.assert_called_once_with(args=(entry.id, def_res, 
+        mock_main_task.assert_called_once_with(args=(entry.id, def_res,
                                                ACCEPTED_RESOLUTIONS[def_res]),
                                                kwargs=reprocess_info, queue='default',
                                                priority=main_priority, immutable=True)
@@ -724,7 +727,7 @@ class TestSubmissionVideo(BaseTestSubmission):
         manager = VideoProcessingManager()
         processor = CommonVideoProcessor(manager, entry)
         acceptable_files = ['original, best_quality', 'webm_144p', 'webm_360p',
-                            'webm_480p', 'webm_720p', 'webm_1080p', 'webm_video'] 
+                            'webm_480p', 'webm_720p', 'webm_1080p', 'webm_video']
         assert processor.acceptable_files == acceptable_files
 
 
index 0f477bfe4219d758c774bf79653636f5dea1f5fd..899493322f5e4e3d6a4009a42ba0b0b724ba0ce5 100644 (file)
@@ -32,6 +32,7 @@ from mediagoblin.media_types.video.transcoders import (capture_thumb,
         VideoTranscoder)
 from mediagoblin.media_types.video.util import ACCEPTED_RESOLUTIONS
 from mediagoblin.media_types.tools import discover
+from mediagoblin.tests.tools import get_app
 
 @contextmanager
 def create_data(suffix=None, make_audio=False):
@@ -115,6 +116,7 @@ def test_transcoder():
         transcoder = VideoTranscoder()
         transcoder.transcode(
                 video_name, result_name,
+                '480p', 1,
                 vp8_quality=8,
                 vp8_threads=0,  # autodetect
                 vorbis_quality=0.3,
@@ -125,6 +127,7 @@ def test_transcoder():
         transcoder = VideoTranscoder()
         transcoder.transcode(
                 video_name, result_name,
+                '480p', 1,
                 vp8_quality=8,
                 vp8_threads=0,  # autodetect
                 vorbis_quality=0.3,