servicemp3.cpp: more simple/flexible streaming detection
[enigma2.git] / lib / python / Plugins / SystemPlugins / DefaultServicesScanner / plugin.py
1 #from Components.ActionMap import ActionMap, NumberActionMap
2 #from Components.Input import Input
3 #from Components.Ipkg import IpkgComponent
4 #from Components.Label import Label
5 #from Components.MenuList import MenuList
6 #from Components.Slider import Slider
7 from Components.NimManager import nimmanager
8 from Plugins.Plugin import PluginDescriptor
9 from Screens.ScanSetup import ScanSetup
10 from Screens.ServiceScan import ServiceScan
11 from Screens.MessageBox import MessageBox
12 from Tools.Directories import resolveFilename, SCOPE_CONFIG, copyfile
13 #from Screens.Screen import Screen
14 from os import unlink
15 from enigma import eTimer, eDVBDB
16
17 class DefaultServiceScan(ServiceScan):
18         skin = """
19                 <screen position="150,115" size="420,390" title="Service Scan">
20                 <widget source="FrontendInfo" render="Pixmap" pixmap="skin_default/icons/scan-s.png" position="5,5" size="64,64" transparent="1" alphatest="on">
21                         <convert type="FrontendInfo">TYPE</convert>
22                         <convert type="ValueRange">0,0</convert>
23                         <convert type="ConditionalShowHide" />
24                 </widget>
25                 <widget source="FrontendInfo" render="Pixmap" pixmap="skin_default/icons/scan-c.png" position="5,5" size="64,64" transparent="1" alphatest="on">
26                         <convert type="FrontendInfo">TYPE</convert>
27                         <convert type="ValueRange">1,1</convert>
28                         <convert type="ConditionalShowHide" />
29                 </widget>
30                 <widget source="FrontendInfo" render="Pixmap" pixmap="skin_default/icons/scan-t.png" position="5,5" size="64,64" transparent="1" alphatest="on">
31                         <convert type="FrontendInfo">TYPE</convert>
32                         <convert type="ValueRange">2,2</convert>
33                         <convert type="ConditionalShowHide" />
34                 </widget>
35                 <widget name="network" position="80,15" size="330,20" font="Regular;20" />
36                 <widget name="transponder" position="80,40" size="330,20" font="Regular;20" />
37                 <widget name="scan_state" position="10,80" zPosition="2" size="400,20" font="Regular;18" />
38                 <widget name="pass" position="10,80" size="400,20" font="Regular;18" />
39                 <widget name="scan_progress" position="10,105" size="400,15" pixmap="skin_default/progress_big.png" borderWidth="2" borderColor="#cccccc" />
40                 <widget name="servicelist" position="10,135" size="400,265" selectionDisabled="1" />
41         </screen>"""
42
43         def __init__(self, session, scanList):
44                 try:
45                         unlink(resolveFilename(SCOPE_CONFIG) + "/lamedb");
46                 except OSError:
47                         pass
48                 db = eDVBDB.getInstance()
49                 db.reloadServicelist()
50                 ServiceScan.__init__(self, session, scanList)
51                 self.timer = eTimer()
52                 self.timer.callback.append(self.ok)
53                 self.timer.start(1000)
54
55 class DefaultServicesScannerPlugin(ScanSetup):
56         skin = """
57                 <screen position="100,115" size="520,390" title="Service scan">
58                         <widget name="config" position="10,10" size="500,350" scrollbarMode="showOnDemand" />
59                         <widget name="introduction" position="10,365" size="500,25" font="Regular;20" halign="center" />
60                 </screen>"""
61                 
62         def __init__(self, session, args = None):
63                 ScanSetup.__init__(self, session)
64                 # backup lamedb
65                 confdir = resolveFilename(SCOPE_CONFIG)
66                 copyfile(confdir + "/lamedb", confdir + "/lamedb.backup")
67                 self.scan_type.value = "multisat"
68                 self.createSetup()
69                 self.scanIndex = 0
70                 self.selectSat(0)
71                 self.onFirstExecBegin.append(self.runScan)
72                 
73         def selectSat(self, index):
74                 for satindex in range(len(self.multiscanlist)):
75                         if satindex != index:
76                                 self.multiscanlist[satindex][1].value = False
77                         else:
78                                 self.multiscanlist[satindex][1].value = True
79                                 
80         def runScan(self):
81                 print "runScan"
82                 self.keyGo()
83
84         def startScan(self, tlist, flags, feid):
85                 print "startScan"
86                 if len(tlist):
87                         # flags |= eComponentScan.scanSearchBAT
88                         self.session.openWithCallback(self.scanFinished, DefaultServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
89                 else:
90                         self.session.openWithCallback(self.scanFinished, MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
91
92         def scanFinished(self, value = None):
93                 print "finished"
94                 print "self.scanIndex:", self.scanIndex
95                 db = eDVBDB.getInstance()
96                 print "self.multiscanlist:", self.multiscanlist
97                 if len(self.multiscanlist) - 1 >= self.scanIndex and len(self.multiscanlist[self.scanIndex]) > 0:
98                         satint = self.multiscanlist[self.scanIndex][0]
99                         print "scanned sat:", satint
100                         db.saveServicelist("/tmp/lamedb." + str(satint))
101                         file = open("/tmp/sat" + str(satint) + ".info", "w")
102                         xml = """<default>
103         <prerequisites>
104                 <tag type="services" />
105                 <bcastsystem type="DVB-S" />
106                 <satellite type="%d" />
107         </prerequisites>
108         
109         <info>
110                 <author>%s</author>
111                 <name>%s</name>
112         </info>
113
114         <files type="directories">
115                 <file type="services" name="lamedb.%d">
116                 </file>
117         </files>
118 </default>""" % (satint, "Dream", nimmanager.getSatDescription(satint), satint)
119                         file.write(xml)
120                         file.close()
121                 
122                 self.scanIndex += 1
123                 if self.scanIndex + 1 >= len(self.multiscanlist):
124                         print "no more sats to scan"
125                         confdir = resolveFilename(SCOPE_CONFIG)
126                         copyfile(confdir + "/lamedb.backup", confdir + "/lamedb")
127                         db.reloadServicelist()
128                         self.close()
129                 else:
130                         self.selectSat(self.scanIndex)
131                         self.keyGo()
132
133 def DefaultServicesScannerMain(session, **kwargs):
134         session.open(DefaultServicesScannerPlugin)
135
136 def Plugins(**kwargs):
137         return PluginDescriptor(name="Default Services Scanner", description=_("Scans default lamedbs sorted by satellite with a connected dish positioner"), where = PluginDescriptor.WHERE_PLUGINMENU, needsRestart = False, fnc=DefaultServicesScannerMain)