diff --git a/mopidy/audio/playlists.py b/mopidy/audio/playlists.py
index 59236dba..35e0800d 100644
--- a/mopidy/audio/playlists.py
+++ b/mopidy/audio/playlists.py
@@ -18,16 +18,16 @@ except ImportError:
# TODO: make detect_FOO_header reusable in general mopidy code.
# i.e. give it just a "peek" like function.
def detect_m3u_header(typefind):
- return typefind.peek(0, 8) == b'#EXTM3U\n'
+ return typefind.peek(0, 7).upper() == b'#EXTM3U'
def detect_pls_header(typefind):
- return typefind.peek(0, 11).lower() == b'[playlist]\n'
+ return typefind.peek(0, 10).lower() == b'[playlist]'
def detect_xspf_header(typefind):
data = typefind.peek(0, 150)
- if b'xspf' not in data:
+ if b'xspf' not in data.lower():
return False
try:
@@ -41,7 +41,7 @@ def detect_xspf_header(typefind):
def detect_asx_header(typefind):
data = typefind.peek(0, 50)
- if b'asx' not in data:
+ if b'asx' not in data.lower():
return False
try:
@@ -82,6 +82,7 @@ def parse_pls(data):
def parse_xspf(data):
try:
+ # Last element will be root.
for event, element in elementtree.iterparse(data):
element.tag = element.tag.lower() # normalize
except elementtree.ParseError:
@@ -94,14 +95,18 @@ def parse_xspf(data):
def parse_asx(data):
try:
+ # Last element will be root.
for event, element in elementtree.iterparse(data):
element.tag = element.tag.lower() # normalize
except elementtree.ParseError:
return
- for ref in element.findall('entry/ref'):
+ for ref in element.findall('entry/ref[@href]'):
yield ref.get('href', '').strip()
+ for entry in element.findall('entry[@href]'):
+ yield entry.get('href', '').strip()
+
def parse_urilist(data):
for line in data.readlines():
diff --git a/tests/audio/test_playlists.py b/tests/audio/test_playlists.py
index 26a8634e..51c36eac 100644
--- a/tests/audio/test_playlists.py
+++ b/tests/audio/test_playlists.py
@@ -33,21 +33,28 @@ Length3=213
Version=2
"""
-ASX = b"""
- Example
-
- Sample Title
-
-
-
- Example title
-
-
-
- Other title
-
-
-
+ASX = b"""
+ Example
+
+ Sample Title
+
+
+
+ Example title
+
+
+
+ Other title
+
+
+
+"""
+
+SIMPLE_ASX = b"""
+
+
+
+
"""
XSPF = b"""
@@ -121,6 +128,13 @@ class AsxPlsPlaylistTest(BasePlaylistTest, unittest.TestCase):
parse = staticmethod(playlists.parse_asx)
+class SimpleAsxPlsPlaylistTest(BasePlaylistTest, unittest.TestCase):
+ valid = SIMPLE_ASX
+ invalid = BAD
+ detect = staticmethod(playlists.detect_asx_header)
+ parse = staticmethod(playlists.parse_asx)
+
+
class XspfPlaylistTest(BasePlaylistTest, unittest.TestCase):
valid = XSPF
invalid = BAD