Parent: [17ed59] (diff)

Download this file

fetchStream.py    54 lines (41 with data), 1.4 kB

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