|
a/rdpl2stream/XspfPlaylistDecoder.py |
|
b/rdpl2stream/XspfPlaylistDecoder.py |
|
... |
|
... |
16 |
# You should have received a copy of the GNU General Public License
|
16 |
# You should have received a copy of the GNU General Public License
|
17 |
# along with Radio Tray. If not, see <http://www.gnu.org/licenses/>.
|
17 |
# along with Radio Tray. If not, see <http://www.gnu.org/licenses/>.
|
18 |
#
|
18 |
#
|
19 |
##########################################################################
|
19 |
##########################################################################
|
20 |
import urllib2
|
20 |
import urllib2
|
21 |
from lxml import etree
|
21 |
import xml.etree.ElementTree as ET
|
22 |
from lxml import objectify
|
|
|
23 |
from StringIO import StringIO
|
22 |
from StringIO import StringIO
|
24 |
from lib.common import USER_AGENT
|
23 |
from lib.common import USER_AGENT
|
25 |
import logging
|
24 |
import logging
|
26 |
|
25 |
|
27 |
class XspfPlaylistDecoder:
|
26 |
class XspfPlaylistDecoder:
|
|
... |
|
... |
52 |
f.close()
|
51 |
f.close()
|
53 |
|
52 |
|
54 |
self.log.info('Playlist downloaded')
|
53 |
self.log.info('Playlist downloaded')
|
55 |
self.log.info('Decoding playlist...')
|
54 |
self.log.info('Decoding playlist...')
|
56 |
|
55 |
|
57 |
parser = etree.XMLParser(recover=True)
|
|
|
58 |
root = etree.parse(StringIO(str),parser)
|
56 |
root = ET.parse(StringIO(str))
|
59 |
|
57 |
|
60 |
elements = root.xpath("//xspf:track/xspf:location",namespaces={'xspf':'http://xspf.org/ns/0/'})
|
58 |
ns = {'xspf':'http://xspf.org/ns/0/'}
|
|
|
59 |
elements = root.findall(".//xspf:track/xspf:location", ns)
|
61 |
|
60 |
|
62 |
result = []
|
61 |
result = []
|
63 |
for r in elements:
|
62 |
for r in elements:
|
64 |
result.append(r.text)
|
63 |
result.append(r.text)
|
65 |
|
64 |
|
66 |
if (len(result) > 0):
|
|
|
67 |
return result
|
65 |
return result
|
68 |
else:
|
|
|
69 |
return None
|
|
|