Switch to unified view

a b/rdpl2stream/fetchStream.py
1
#!/usr/bin/env python2
2
from __future__ import print_function
3
4
import sys
5
import logging
6
7
from StreamDecoder import StreamDecoder
8
9
class myCfg:
10
    def __init__(self):
11
        self.cf = dict()
12
        self.cf["url_timeout"] = "20"
13
14
    def getConfigValue(self, s):
15
        if s in self.cf:
16
            return self.cf[s]
17
        else:
18
            return None
19
20
    def setConfigValue(self, s, v):
21
        self.cf[s] = v
22
23
24
25
logger = logging.getLogger('radiotray')
26
logger.setLevel(logging.ERROR)
27
handler = logging.StreamHandler()
28
#handler = logging.NullHandler()
29
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
30
handler.setFormatter(formatter)
31
logger.addHandler(handler)
32
33
34
35
decoder = StreamDecoder(myCfg())
36
37
38
urlInfo = decoder.getMediaStreamInfo(sys.argv[1])
39
40
while urlInfo is not None and urlInfo.isPlaylist():
41
    playlist = decoder.getPlaylist(urlInfo)
42
    if len(playlist) == 0:
43
        logger.error("Received empty stream from station", file=sys.stderr)
44
        sys.exit(1)
45
    stream = playlist.pop(0)
46
    logger.info('Stream %s' % stream)
47
    urlInfo = decoder.getMediaStreamInfo(stream)
48
49
if urlInfo is not None:
50
    logger.info("Result: isplaylist %d content-type %s url %s",
51
                urlInfo.isPlaylist(), urlInfo.getContentType(),
52
                urlInfo.getUrl())
53
    print("%s" % urlInfo.getUrl())
54
else:
55
    logger.error("Ended with null urlinfo")
56
    print
57
58