~ubuntu-branches/ubuntu/saucy/radiotray/saucy

« back to all changes in this revision

Viewing changes to src/XspfPlaylistDecoder.py

  • Committer: Package Import Robot
  • Author(s): Elías Alejandro Año Mendoza
  • Date: 2011-12-28 17:06:38 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20111228170638-cym2rxl7boqq8dxr
Tags: 0.7.1-1
* New upstream release
* debian/copyright
  + Added new copyright owners

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from lxml import objectify
23
23
from StringIO import StringIO
24
24
from lib.common import USER_AGENT
 
25
import logging
25
26
 
26
27
class XspfPlaylistDecoder:
27
28
 
28
29
    def __init__(self):
29
 
        print "XSPF playlist decoder"
 
30
        self.log = logging.getLogger('radiotray')
 
31
        self.log.debug('XSPF playlist decoder')
30
32
 
31
33
 
32
34
    def isStreamValid(self, contentType, firstBytes):
33
35
 
34
36
        if('application/xspf+xml' in contentType):
35
 
            print "Stream is readable by XSPF Playlist Decoder"
 
37
            self.log.info('Stream is readable by XSPF Playlist Decoder')
36
38
            return True
37
39
        else:
38
40
            return False
41
43
 
42
44
    def extractPlaylist(self,  url):
43
45
 
44
 
        print "Downloading playlist..."
 
46
        self.log.info('Downloading playlist...')
45
47
 
46
48
        req = urllib2.Request(url)
47
49
        req.add_header('User-Agent', USER_AGENT)
49
51
        str = f.read()
50
52
        f.close()
51
53
 
52
 
        print "Playlist downloaded"
53
 
        print "Decoding playlist..."
 
54
        self.log.info('Playlist downloaded')
 
55
        self.log.info('Decoding playlist...')
54
56
 
55
57
        parser = etree.XMLParser(recover=True)
56
58
        root = etree.parse(StringIO(str),parser)