[pitivi] proxy: Fix traceback when loading projects with audio-only assets



commit dbcf8d76031bf026fe99e4096d1e5a9de78f6e88
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Thu Oct 10 03:43:22 2019 +0200

    proxy: Fix traceback when loading projects with audio-only assets

 pitivi/utils/proxy.py       | 11 +++++++++--
 tests/test_media_library.py | 18 ++++++++++++------
 2 files changed, 21 insertions(+), 8 deletions(-)
---
diff --git a/pitivi/utils/proxy.py b/pitivi/utils/proxy.py
index 7c13268f..48535bc3 100644
--- a/pitivi/utils/proxy.py
+++ b/pitivi/utils/proxy.py
@@ -324,10 +324,13 @@ class ProxyManager(GObject.Object, Loggable):
         return ".".join(uri.split(".")[:-3])
 
     def getProxyUri(self, asset, scaled=False):
-        """Returns the URI of a possible proxy file.
+        """Gets the URI of the corresponding proxy file for the specified asset.
 
         The name looks like:
-            <filename>.<file_size>.<proxy_extension>
+            <filename>.<file_size>[.<proxy_resolution>].<proxy_extension>
+
+        Returns:
+            str: The URI or None if it can't be computed for any reason.
         """
         asset_file = Gio.File.new_for_uri(asset.get_id())
         try:
@@ -339,7 +342,11 @@ class ProxyManager(GObject.Object, Loggable):
                 return None
             else:
                 raise
+
         if scaled:
+            if not asset.get_info().get_video_streams():
+                return None
+
             max_w = self.app.project_manager.current_project.scaled_proxy_width
             max_h = self.app.project_manager.current_project.scaled_proxy_height
             t_width, t_height = self._scale_asset_resolution(asset, max_w, max_h)
diff --git a/tests/test_media_library.py b/tests/test_media_library.py
index c3dcbe09..89291b1f 100644
--- a/tests/test_media_library.py
+++ b/tests/test_media_library.py
@@ -49,14 +49,14 @@ class BaseTestMediaLibrary(common.TestCase):
             self.medialibrary.finalize()
             self.medialibrary = None
 
-    def _customSetUp(self, project_uri=None, **kwargs):
+    def _customSetUp(self, project_uri=None, **settings):
         # Always make sure we start with a clean medialibrary, and no other
         # is connected to some assets.
         self.clean()
 
         self.mainloop = common.create_main_loop()
         self.check_no_transcoding = False
-        self.app = common.create_pitivi_mock(**kwargs)
+        self.app = common.create_pitivi_mock(**settings)
         self.app.project_manager = ProjectManager(self.app)
         self.medialibrary = medialibrary.MediaLibraryWidget(self.app)
 
@@ -420,6 +420,13 @@ class TestMediaLibrary(BaseTestMediaLibrary):
                 # Delete HQ Proxy
                 self.check_disable_proxy(proxy, asset, delete=True)
 
+    def test_load_audio_only(self):
+        audio_sample = "mp3_sample.mp3"
+        with common.cloned_sample(audio_sample):
+            asset_uri = common.get_sample_uri(audio_sample)
+            with common.created_project_file(asset_uri) as uri:
+                self._customSetUp(project_uri=uri)
+
     def test_scale_proxy_audio_post_import(self):
         sample = "mp3_sample.mp3"
         with common.cloned_sample(sample):
@@ -436,8 +443,7 @@ class TestMediaLibrary(BaseTestMediaLibrary):
                 proxying_strategy=ProxyingStrategy.AUTOMATIC)
 
     def test_missing_uri_displayed(self):
-        with common.cloned_sample():
-            asset_uri = common.get_sample_uri("missing.png")
-            with common.created_project_file(asset_uri) as uri:
-                self._customSetUp(project_uri=uri)
+        asset_uri = common.get_sample_uri("image-which-does-not-exist.png")
+        with common.created_project_file(asset_uri) as uri:
+            self._customSetUp(project_uri=uri)
         self.assertTrue(self.medialibrary._import_warning_infobar.props.visible)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]