From 0f749702c48f74297370a7b87df3daac0754121f Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Tue, 28 May 2013 23:10:16 +0200 Subject: [PATCH] audio: Add simple parsers for m3u, pls, xspf and uri lists. These parsers, and the detectors should probably be moved out at some point, but for now the simple version of these will do. --- mopidy/audio/playlists.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/mopidy/audio/playlists.py b/mopidy/audio/playlists.py index 5235d4dd..b7821ed7 100644 --- a/mopidy/audio/playlists.py +++ b/mopidy/audio/playlists.py @@ -4,6 +4,8 @@ import pygst pygst.require('0.10') import gst +import ConfigParser as configparser +import xml.etree.ElementTree import xml.dom.pulldom @@ -35,6 +37,36 @@ def detect_xspf_header(typefind): return False +def parse_m3u(data): + # TODO: convert non uris to file uris. + for line in data.readlines(): + if not line.startswith('#') and line.strip(): + yield line + + +def parse_pls(data): + # TODO: error handling of bad playlists. + # TODO: convert non uris to file uris. + cp = configparser.RawConfigParser() + cp.readfp(data) + for i in xrange(1, cp.getint('playlist', 'numberofentries')): + yield cp.get('playlist', 'file%d' % i) + + +def parse_xspf(data): + # TODO: handle parser errors + root = xml.etree.ElementTree.fromstring(data.read()) + tracklist = tree.find('{http://xspf.org/ns/0/}trackList') + for track in tracklist.findall('{http://xspf.org/ns/0/}track'): + yield track.findtext('{http://xspf.org/ns/0/}location') + + +def parse_urilist(data): + for line in data.readlines(): + if not line.startswith('#') and line.strip(): + yield line + + def playlist_typefinder(typefind, func, caps): if func(typefind): typefind.suggest(gst.TYPE_FIND_MAXIMUM, caps)