[pitivi] medialibrary: Use is_proxy_asset instead of checking the file extension



commit 7fef52205746c533d307f14e2381cf88eea56525
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Mon Jun 27 12:35:36 2016 +0200

    medialibrary: Use is_proxy_asset instead of checking the file extension
    
    Differential Revision: https://phabricator.freedesktop.org/D1130

 pitivi/medialibrary.py |   12 +++++++-----
 pitivi/project.py      |    2 +-
 pitivi/utils/proxy.py  |   12 +++++++-----
 3 files changed, 15 insertions(+), 11 deletions(-)
---
diff --git a/pitivi/medialibrary.py b/pitivi/medialibrary.py
index 0107696..f2e1422 100644
--- a/pitivi/medialibrary.py
+++ b/pitivi/medialibrary.py
@@ -54,6 +54,7 @@ from pitivi.utils.misc import path_from_uri
 from pitivi.utils.misc import PathWalker
 from pitivi.utils.misc import quote_uri
 from pitivi.utils.proxy import ProxyingStrategy
+from pitivi.utils.proxy import ProxyManager
 from pitivi.utils.ui import beautify_asset
 from pitivi.utils.ui import beautify_ETA
 from pitivi.utils.ui import beautify_length
@@ -649,11 +650,12 @@ class MediaLibraryWidget(Gtk.Box, Loggable):
             self.treeview_scrollwin.hide()
             self.iconview_scrollwin.show_all()
 
-    def __filterProxies(self, filter_info):
+    def __filter_proxies(self, filter_info):
+        """Returns whether the specified item should be displayed."""
         if filter_info.mime_type not in SUPPORTED_MIMETYPES:
             return False
 
-        if filter_info.uri.endswith(".proxy.mkv"):
+        if ProxyManager.is_proxy_asset(filter_info.uri):
             return False
 
         return True
@@ -687,7 +689,7 @@ class MediaLibraryWidget(Gtk.Box, Loggable):
         filt_supported.set_name(_("Supported file formats"))
         filt_supported.add_custom(Gtk.FileFilterFlags.URI |
                                   Gtk.FileFilterFlags.MIME_TYPE,
-                                  self.__filterProxies)
+                                  self.__filter_proxies)
         # ...and allow the user to override our whitelists
         default = Gtk.FileFilter()
         default.set_name(_("All files"))
@@ -759,7 +761,7 @@ class MediaLibraryWidget(Gtk.Box, Loggable):
         LARGE_SIZE = 96
         info = asset.get_info()
 
-        if self.app.proxy_manager.isProxyAsset(asset) and \
+        if self.app.proxy_manager.is_proxy_asset(asset) and \
                 not asset.props.proxy_target:
             self.info("%s is a proxy asset but has no target, "
                       "not displaying it.", asset.props.id)
@@ -936,7 +938,7 @@ class MediaLibraryWidget(Gtk.Box, Loggable):
     def _errorCreatingAssetCb(self, unused_project, error, id, type):
         """Gathers asset loading errors."""
         if GObject.type_is_a(type, GES.UriClip):
-            if self.app.proxy_manager.isProxyAsset(id):
+            if self.app.proxy_manager.is_proxy_asset(id):
                 self.debug("Error %s with a proxy"
                            ", not showing the error message", error)
                 return
diff --git a/pitivi/project.py b/pitivi/project.py
index 4fd4365..d5eaa4f 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -1195,7 +1195,7 @@ class Project(Loggable, GES.Project):
                 self.debug("Stop proxying %s", proxy_target.props.id)
                 proxy_target.set_proxy(None)
                 if delete_proxy_file:
-                    if not self.app.proxy_manager.isProxyAsset(asset):
+                    if not self.app.proxy_manager.is_proxy_asset(asset):
                         raise RuntimeError("Trying to remove proxy %s"
                                            " but it does not look like one!",
                                            asset.props.id)
diff --git a/pitivi/utils/proxy.py b/pitivi/utils/proxy.py
index 574204d..e0b6d85 100644
--- a/pitivi/utils/proxy.py
+++ b/pitivi/utils/proxy.py
@@ -94,6 +94,8 @@ class ProxyManager(GObject.Object, Loggable):
                 WHITELIST_FORMATS.append(createEncodingProfileSimple(
                     container, audio, video))
 
+    proxy_extension = "proxy.mkv"
+
     def __init__(self, app):
         GObject.Object.__init__(self)
         Loggable.__init__(self)
@@ -103,7 +105,6 @@ class ProxyManager(GObject.Object, Loggable):
         self._total_transcoded_time = 0
         self._start_proxying_time = 0
         self._estimated_time = 0
-        self.proxy_extension = "proxy.mkv"
         self.__running_transcoders = []
         self.__pending_transcoders = []
 
@@ -185,16 +186,17 @@ class ProxyManager(GObject.Object, Loggable):
 
         return encoding_profile
 
-    def isProxyAsset(self, obj):
+    @classmethod
+    def is_proxy_asset(cls, obj):
         if isinstance(obj, GES.Asset):
             uri = obj.props.id
         else:
             uri = obj
 
-        return uri.endswith("." + self.proxy_extension)
+        return uri.endswith("." + cls.proxy_extension)
 
     def checkProxyLoadingSucceeded(self, proxy):
-        if self.isProxyAsset(proxy):
+        if self.is_proxy_asset(proxy):
             return True
 
         self.emit("error-preparing-asset", None, proxy, proxy.get_error())
@@ -242,7 +244,7 @@ class ProxyManager(GObject.Object, Loggable):
             return False
 
         if self.app.settings.proxyingStrategy == ProxyingStrategy.AUTOMATIC \
-                and not self.isProxyAsset(asset) and \
+                and not self.is_proxy_asset(asset) and \
                 self.isAssetFormatWellSupported(asset):
             return False
 


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