]> git.poda.fr Git - converter.git/commitdiff
xspf: Filter out non tracklist and non track nodes
authorJulien <julien@poda.fr>
Thu, 6 Feb 2025 19:09:12 +0000 (20:09 +0100)
committerJulien <julien@poda.fr>
Thu, 6 Feb 2025 19:09:12 +0000 (20:09 +0100)
converter.py

index a0e9bf6295338604bd68482c8fd9a93f6a033892..891075fa6e5580d0f69e7c1773201d78530ac60c 100755 (executable)
@@ -2,7 +2,7 @@
 
 '''
 BSD 3 License
-Copyright 2024 Julien Selamme
+Copyright 2025 Julien Selamme
 
 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 
@@ -567,16 +567,23 @@ class Converter:
         xspf: xml.etree.ElementTree.Element = xml.etree.ElementTree.parse(filePath).getroot()
         xmlns: str = "http://xspf.org/ns/0/"
 
-        # Each element is a string path.
-        for track in xspf[0]: # <track> in <tracks>
-            element: typing.Optional[xml.etree.ElementTree.Element] = track.find("{" + xmlns + "}location")
-
-            if element is None:
+        for node in xspf: # <trackList> in document.
+            if not node.tag.endswith("trackList"):
                 continue
 
-            urlDecodedString: str = urllib.parse.unquote(str(element.text))
-            playlist.add(os.path.dirname(urlDecodedString),
-                         os.path.basename(urlDecodedString))
+            # Each element is a string path.
+            for track in node: # <track> in <trackList>.
+                if not track.tag.endswith("track"):
+                    continue
+
+                element: typing.Optional[xml.etree.ElementTree.Element] = track.find("{" + xmlns + "}location")
+
+                if element is None:
+                    continue
+
+                urlDecodedString: str = urllib.parse.unquote(str(element.text))
+                playlist.add(os.path.dirname(urlDecodedString),
+                             os.path.basename(urlDecodedString))
 
     # Create or update playlist file from a directory.
     def _updatePlaylistFile(self, playlist: list[str], playlistPath: str) -> None: