From: Boris Bobrov Date: Thu, 12 Jul 2018 16:27:44 +0000 (+0200) Subject: Fixes for small bugs X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4551a808beb8aa0dab3f1a331d022bfa84ee933c;p=mediagoblin.git Fixes for small bugs There were some blocking issues in the code. They are small, but break tests and/or production. Fixed some of them. --- diff --git a/mediagoblin/media_types/video/__init__.py b/mediagoblin/media_types/video/__init__.py index ea7bc021..0c822f69 100644 --- a/mediagoblin/media_types/video/__init__.py +++ b/mediagoblin/media_types/video/__init__.py @@ -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']) diff --git a/mediagoblin/media_types/video/processing.py b/mediagoblin/media_types/video/processing.py index c72c12f2..c377d100 100644 --- a/mediagoblin/media_types/video/processing.py +++ b/mediagoblin/media_types/video/processing.py @@ -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 diff --git a/mediagoblin/media_types/video/transcoders.py b/mediagoblin/media_types/video/transcoders.py index 75f5ef86..d6aae7cf 100644 --- a/mediagoblin/media_types/video/transcoders.py +++ b/mediagoblin/media_types/video/transcoders.py @@ -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)') diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py index f08a25f0..a7661e85 100644 --- a/mediagoblin/tests/test_submission.py +++ b/mediagoblin/tests/test_submission.py @@ -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 diff --git a/mediagoblin/tests/test_video.py b/mediagoblin/tests/test_video.py index 0f477bfe..89949332 100644 --- a/mediagoblin/tests/test_video.py +++ b/mediagoblin/tests/test_video.py @@ -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,