From 8c54494b7aa377983a8dce82e3c8c8218ae86a48 Mon Sep 17 00:00:00 2001 From: Julien Date: Thu, 6 Feb 2025 20:09:12 +0100 Subject: [PATCH] xspf: Filter out non tracklist and non track nodes --- converter.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/converter.py b/converter.py index a0e9bf6..891075f 100755 --- a/converter.py +++ b/converter.py @@ -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]: # in - element: typing.Optional[xml.etree.ElementTree.Element] = track.find("{" + xmlns + "}location") - - if element is None: + for node in xspf: # 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: # in . + 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: -- 2.47.3