[gnome-music] utils: Fallback to filename as track title



commit abb0644b2652b7bb524b42ce0ae6b8bf0a4f7094
Author: Sumaid <sumaidsyed gmail com>
Date:   Mon Mar 25 22:37:12 2019 +0530

    utils: Fallback to filename as track title
    
    Songs without a title tag relied on Tracker to extract the filename as
    title. The Tracker support for generating this metadata is optional and has
    recently been disabled by default.
    Music now extracts a title from the filename for songs without a title tag
    itself and uses it as fallback.
    
    Closes: #223

 gnomemusic/utils.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/gnomemusic/utils.py b/gnomemusic/utils.py
index ec171663..468238da 100644
--- a/gnomemusic/utils.py
+++ b/gnomemusic/utils.py
@@ -25,6 +25,7 @@
 from enum import IntEnum
 
 from gettext import gettext as _
+from gi.repository import Gio
 
 
 class View(IntEnum):
@@ -83,8 +84,17 @@ def get_media_title(item):
     :rtype:
     """
 
-    return (item.get_title()
-            or _("Untitled"))
+    title = item.get_title()
+
+    if not title:
+        url = item.get_url()
+        file_ = Gio.File.new_for_uri(url)
+        fileinfo = file_.query_info(
+            "standard::display-name", Gio.FileQueryInfoFlags.NONE, None)
+        title = fileinfo.get_display_name()
+        title = title.replace("_", " ")
+
+    return title
 
 
 def get_media_year(item):


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