audio: Handle all caps ASX tags.
Also add support for simple asx format.
This commit is contained in:
parent
8f70899855
commit
c87684aa6b
@ -18,7 +18,7 @@ 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, 8).upper() == b'#EXTM3U\n'
|
||||
|
||||
|
||||
def detect_pls_header(typefind):
|
||||
@ -27,7 +27,7 @@ def detect_pls_header(typefind):
|
||||
|
||||
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():
|
||||
|
||||
@ -33,21 +33,28 @@ Length3=213
|
||||
Version=2
|
||||
"""
|
||||
|
||||
ASX = b"""<asx version="3.0">
|
||||
<title>Example</title>
|
||||
<entry>
|
||||
<title>Sample Title</title>
|
||||
<ref href="file:///tmp/foo" />
|
||||
</entry>
|
||||
<entry>
|
||||
<title>Example title</title>
|
||||
<ref href="file:///tmp/bar" />
|
||||
</entry>
|
||||
<entry>
|
||||
<title>Other title</title>
|
||||
<ref href="file:///tmp/baz" />
|
||||
</entry>
|
||||
</asx>
|
||||
ASX = b"""<ASX version="3.0">
|
||||
<TITLE>Example</TITLE>
|
||||
<ENTRY>
|
||||
<TITLE>Sample Title</TITLE>
|
||||
<REF href="file:///tmp/foo" />
|
||||
</ENTRY>
|
||||
<ENTRY>
|
||||
<TITLE>Example title</TITLE>
|
||||
<REF href="file:///tmp/bar" />
|
||||
</ENTRY>
|
||||
<ENTRY>
|
||||
<TITLE>Other title</TITLE>
|
||||
<REF href="file:///tmp/baz" />
|
||||
</ENTRY>
|
||||
</ASX>
|
||||
"""
|
||||
|
||||
SIMPLE_ASX = b"""<ASX version="3.0">
|
||||
<ENTRY href="file:///tmp/foo" />
|
||||
<ENTRY href="file:///tmp/bar" />
|
||||
<ENTRY href="file:///tmp/baz" />
|
||||
</ASX>
|
||||
"""
|
||||
|
||||
XSPF = b"""<?xml version="1.0" encoding="UTF-8"?>
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user