-
Notifications
You must be signed in to change notification settings - Fork 3
/
MuMu_List.py
executable file
·98 lines (75 loc) · 3.47 KB
/
MuMu_List.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os, cgi
import simplejson as json
from optparse import OptionParser
from MultiMuMuLib.globals import *
from MultiMuMuLib.MuMuStation import MuMuStation
from MultiMuMuLib.MuMuMaster import MuMuMaster
from MultiMuMuLib.RenderUI import RenderCLI, RenderCGI, RenderM3U
if __name__ == "__main__":
MyLogger_log_http_source()
parser = OptionParser(description="list dvb")
parser.add_option('-f', '--format', action="store", dest="format", help="display format in 'cli','cgi,'m3u' [default:%default]", default='cli')
parser.add_option('-b', '--bouquet', action="store", dest="bouquet", help="filter, not yet implemented [default:%default]", default='all')
parser.add_option('-p', '--pretune', action="store_true", dest="pretune", help="if bouquet == single station, pretune here", default=False)
options, args = parser.parse_args()
cgi_data = cgi.FieldStorage()
out_format = cgi_data.getvalue('format') or options.format
out_bouquet = cgi_data.getvalue('bouquet') or options.bouquet
out_pretune = cgi_data.getvalue('pretune') or options.pretune
out_format = out_format.lower()
if out_format not in ['cli','cgi','m3u']:
raise Exception
# initialize the right output render class
if out_format == 'm3u':
MyUi = RenderM3U('MultiMuMuDVB.' + out_bouquet + '.m3u')
elif out_format == 'cgi' or 'HTTP_USER_AGENT' in os.environ:
MyUi = RenderCGI()
else:
MyUi = RenderCLI()
import time
stime = time.time()
MyLogger.info("listing " + out_bouquet)
MyMuMuMasterInstance = MuMuMaster()
MyUi.title('List of stations (' + out_bouquet + ')')
list = []
preTune = None
favorites_file = 'config/favorite.' + out_bouquet + '.json'
# types of list
if out_bouquet == 'current':
list = MyMuMuMasterInstance.get_current_stations()
elif out_bouquet == 'all':
list = MyMuMuMasterInstance.stations
elif os.path.isfile(favorites_file):
try:
fc = open(favorites_file).read()
favorites = json.loads(fc)
for f in favorites:
s = MyMuMuMasterInstance.get_station_by_name(f)
if isinstance(s, MuMuStation):
list.append( s )
else:
MyLogger.warn("unknown station '" + f + "' in " + favorites_file)
except json.scanner.JSONDecodeError as e:
MyLogger.error('could not decode ' + favorites_file)
else:
search = MyMuMuMasterInstance.get_station_by_name(out_bouquet)
if search is None:
MyLogger.critical("COULD NOT FIND '" + out_bouquet + "'")
MyLogger.critical("mybe missing '" + favorites_file + "' ?")
quit()
list = [search]
preTune = search
MyUi.table_begin(['m3u','direct','proxy','host/tuner','sid','freq','pol','srate','DiSEqC'])
for s in list:
assert isinstance(s, MuMuStation)
MyUi.table_entry(s)
MyUi.table_end()
MyLogger.info("DONE, listed '" + out_bouquet + "' in " + str(round(time.time() - stime, 1)) + " secs")
if preTune is not None and out_pretune:
assert isinstance(preTune, MuMuStation)
MyLogger.info('m3u and direct station: assuming pre-tune')
r = MyMuMuMasterInstance.tune_to(preTune)
MyLogger.ddebug('m3u and direct station: pre-tuned ' + str(r))
MyLogger.info("DONE, pretuned '" + out_bouquet + "' in " + str(round(time.time() - stime, 1)) + " secs")