From 47e8f74da9879239f6066f346cfaf109f54b92e9 Mon Sep 17 00:00:00 2001 From: Brannon King Date: Thu, 16 Jan 2020 17:51:49 -0700 Subject: [PATCH] changed to list append, relative claim test --- lbry/file_analysis.py | 30 +++++++++---------- .../blockchain/test_transcoding.py | 3 +- .../blockchain/test_wallet_commands.py | 5 ++-- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lbry/file_analysis.py b/lbry/file_analysis.py index f1d3ea93e..135942411 100644 --- a/lbry/file_analysis.py +++ b/lbry/file_analysis.py @@ -286,12 +286,9 @@ class VideoFileAnalyzer: return file_path if not repair: - errors = "Streamability verification failed:\n" - for message in messages: - if message: - errors += f" {message}\n" - - raise Exception(errors) + errors = ["Streamability verification failed:"] + errors.extend(filter(None, messages)) + raise Exception("\n ".join(errors)) # the plan for transcoding: # we have to re-encode the video if it is in a nonstandard format @@ -299,34 +296,35 @@ class VideoFileAnalyzer: # we also re-encode if our bitrate is too high try: - transcode_command = f'-i "{file_path}" -y -c:s copy -c:d copy -c:v ' + transcode_command = [f'-i "{file_path}" -y -c:s copy -c:d copy -c:v'] video_encoder = "" if video_msg or bitrate_msg: video_encoder = await self._get_video_encoder(scan_data) - transcode_command += f"{video_encoder} " + transcode_command.append(video_encoder) else: - transcode_command += "copy " + transcode_command.append("copy") - transcode_command += "-movflags +faststart -c:a " + transcode_command.append("-movflags +faststart -c:a") path = pathlib.Path(file_path) extension = self._get_best_container_extension(scan_data, video_encoder) if audio_msg or volume_msg: audio_encoder = await self._get_audio_encoder(extension) - transcode_command += f"{audio_encoder} " + transcode_command.append(audio_encoder) if volume_msg: volume_filter = await self._get_volume_filter() - transcode_command += f"{volume_filter} " + transcode_command.append(volume_filter) else: - transcode_command += "copy " + transcode_command.append("copy") # TODO: put it in a temp folder and delete it after we upload? output = path.parent / f"{path.stem}_fixed.{extension}" - transcode_command += f'"{output}"' + transcode_command.append(f'"{output}"') - log.info("Proceeding on transcode via: ffmpeg %s", transcode_command) - result, code = await self._execute("ffmpeg", transcode_command) + ffmpeg_command = " ".join(transcode_command) + log.info("Proceeding on transcode via: ffmpeg %s", ffmpeg_command) + result, code = await self._execute("ffmpeg", ffmpeg_command) if code != 0: raise Exception(f"Failure to complete the transcode command. Output: {result}") except Exception as e: diff --git a/tests/integration/blockchain/test_transcoding.py b/tests/integration/blockchain/test_transcoding.py index 125b4c795..12ed4c51d 100644 --- a/tests/integration/blockchain/test_transcoding.py +++ b/tests/integration/blockchain/test_transcoding.py @@ -5,7 +5,7 @@ import time import lbry.wallet # just to make the following line work: from lbry.conf import TranscodeConfig from lbry.file_analysis import VideoFileAnalyzer -from tests.integration.blockchain.test_claim_commands import ClaimTestCase +from .test_claim_commands import ClaimTestCase log = logging.getLogger(__name__) @@ -146,4 +146,3 @@ class TranscodeValidation(ClaimTestCase): await self.analyzer.verify_or_repair(True, False, self.video_file_name) finally: self.conf.ffmpeg_folder = "" - diff --git a/tests/integration/blockchain/test_wallet_commands.py b/tests/integration/blockchain/test_wallet_commands.py index 126f3fd9a..8500efa3c 100644 --- a/tests/integration/blockchain/test_wallet_commands.py +++ b/tests/integration/blockchain/test_wallet_commands.py @@ -199,8 +199,9 @@ class WalletEncryptionAndSynchronization(CommandTestCase): await self.confirm_tx(sendtxid, self.daemon2.ledger) def assertWalletEncrypted(self, wallet_path, encrypted): - wallet = json.load(open(wallet_path)) - self.assertEqual(wallet['accounts'][0]['private_key'][1:4] != 'prv', encrypted) + with open(wallet_path) as opened: + wallet = json.load(opened) + self.assertEqual(wallet['accounts'][0]['private_key'][1:4] != 'prv', encrypted) async def test_sync(self): daemon, daemon2 = self.daemon, self.daemon2