forked from PseudoTV/PseudoTV_Live
-
Notifications
You must be signed in to change notification settings - Fork 0
/
capture.py
336 lines (284 loc) · 13.7 KB
/
capture.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# Copyright (C) 2015 Kevin S. Graer
#
#
# This file is part of PseudoTV Live.
#
# PseudoTV is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PseudoTV is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PseudoTV Live. If not, see <http://www.gnu.org/licenses/>.
import sys, os
import xbmc, xbmcgui, xbmcaddon, xbmcvfs
from urllib import unquote
from xml.dom.minidom import parse, parseString
from resources.lib.utils import *
from resources.lib.Globals import *
from resources.lib.ChannelList import ChannelList
class Main:
def log(self, msg, level = xbmc.LOGDEBUG):
log('capture: ' + msg, level)
def __init__(self):
self.log("__init__")
self.chnlst = ChannelList()
self.chnlst.fillPVR()
# InfoLabel Parameters
self.Label = xbmc.getInfoLabel('ListItem.Label')
self.Path = xbmc.getInfoLabel('ListItem.FolderPath')
self.FileName = xbmc.getInfoLabel('ListItem.FilenameAndPath')
self.DBIDType = xbmc.getInfoLabel('ListItem.DBTYPE')
self.AddonName = xbmc.getInfoLabel('Container.PluginName')
self.AddonType = xbmc.getInfoLabel('Container.Property(addoncategory)')
self.Description = xbmc.getInfoLabel('ListItem.Property(Addon.Description)')
self.plot = xbmc.getInfoLabel('ListItem.Plot')
self.plotOutline = xbmc.getInfoLabel('ListItem.PlotOutline')
self.isPlayable = xbmc.getInfoLabel('ListItem.Property(IsPlayable)').lower() == 'true'
self.isFolder = xbmc.getCondVisibility('ListItem.IsFolder') == 1
if not self.plot:
if self.plotOutline:
self.Description = self.plotOutline
elif not self.Description:
self.Description = self.Label
else:
self.Description = self.plot
if self.AddonName:
ADDON = xbmcaddon.Addon(id=self.AddonName)
ADDON_ID = ADDON.getAddonInfo('id')
self.AddonName = ADDON.getAddonInfo('name')
self.Label = self.chnlst.cleanLabels(self.Label)
self.Description = self.chnlst.cleanLabels(self.Description)
self.AddonName = self.chnlst.cleanLabels(self.AddonName)
self.log("%s, %s, %s, %s, %s, %s, %s, %s, %s"%(self.Label,self.Path,self.FileName,self.DBIDType,self.AddonName,self.AddonType,self.Description,str(self.isPlayable),str(self.isFolder)))
self.ImportChannel()
def ImportChannel(self):
self.log("ImportChannel")
show_busy_dialog()
self.chantype = 9999
self.setting1 = ''
self.setting2 = ''
self.setting3 = ''
self.setting4 = ''
self.channame = ''
self.theitem = []
self.itemlst = []
ADDON_SETTINGS.loadSettings()
for i in range(CHANNEL_LIMIT):
self.theitem.append(str(i + 1))
self.updateListing()
hide_busy_dialog()
available = False
if len(self.itemlst) == 0:
setProperty("PTVL.CM.LASTCHAN","0")
try:
Lastchan = int(getProperty("PTVL.CM.LASTCHAN"))
self.log("ImportChannel, Lastchan = " + str(Lastchan))
self.nitemlst = self.itemlst
self.itemlst = self.nitemlst[Lastchan:] + self.nitemlst[:Lastchan]
except:
pass
while not available:
select = selectDialog(self.itemlst, 'Select Channel Number')
if select != -1:
# self.channel = select + 1
self.channel = int(self.chnlst.cleanLabels((self.itemlst[select]).split(' - ')[0]))
if not (self.itemlst[select]).startswith('[COLOR=dimgrey]'):
available = True
if self.Path[-3:].lower() == 'xsp':
self.chantype = 0
elif self.Path.lower().startswith('plugin://plugin.video.youtube/channel/'):
self.chantype = 10
self.YTtype = 1
elif self.Path.lower().startswith(('plugin://plugin.video.youtube/playlist/','plugin://plugin.video.spotitube/?limit&mode=listyoutubeplaylist')):
self.chantype = 10
self.YTtype = 2
elif self.Path.lower().startswith(('plugin', 'http', 'rtmp', 'pvr', 'hdhomerun', 'upnp')):
if self.isPlayable == True:
if dlg.yesno("PseudoTV Live", 'Add source as', yeslabel="LiveTV", nolabel="InternetTV"):
self.chantype = 8
else:
self.chantype = 9
else:
if self.Path.lower().startswith(('pvr')):
self.chantype = 8
elif self.isFolder == True and self.Label in ['Networks','Leanback Channels'] and self.Path.lower().startswith(('plugin')):
return self.buildNetworks(self.Path)
elif self.isFolder == True and self.Path.lower().startswith(('plugin')):
self.chantype = 15
elif self.isFolder == True and self.Path.lower().startswith(('upnp')):
self.chantype = 16
elif self.isFolder == True:
if self.DBIDType == 'tvshow':
self.chantype = 6
elif self.DBIDType == '':
self.chantype = 7
self.buildChannel()
else:
infoDialog("Channel "+str(self.channel)+" already in use")
else:
available = True
self.log("chantype = "+str(self.chantype))
def buildNetworks(self, url):
self.log("buildNetworks, url = " + url)
detail = uni(self.chnlst.requestList(url))
if dlg.yesno("PseudoTV Live", 'Add %d Network Channels?' % len(detail)):
show_busy_dialog()
for f in detail:
files = re.search('"file" *: *"(.*?)",', f)
filetypes = re.search('"filetype" *: *"(.*?)",', f)
labels = re.search('"label" *: *"(.*?)",', f)
if filetypes and labels and files:
filetype = filetypes.group(1)
name = self.chnlst.cleanLabels(labels.group(1))
file = (files.group(1).replace("\\\\", "\\"))
if filetype == 'directory':
self.chantype = 15
self.setting1 = file
self.setting2 = ''
self.setting3 = str(MEDIA_LIMIT)
self.setting4 = '0'
self.channame = name
self.saveSettings()
self.fixChannel(self.channel)
hide_busy_dialog()
self.openManager()
def fixChannel(self, channel):
while self.getChtype(self.channel+1) != 9999:
self.channel +=1
def buildChannel(self):
self.log("buildChannel, chantype = " + str(self.chantype))
self.addonDirectoryPath = []
if self.chantype == 0:
self.setting1 = xbmc.translatePath(self.Path)
self.channame = self.chnlst.getSmartPlaylistName(self.Path)
elif self.chantype == 6:
self.setting1 = self.Label
self.setting2 = '4'
self.channame = self.Label
elif self.chantype == 7:
self.setting1 = xbmc.translatePath(self.Path)
self.setting3 = str(MEDIA_LIMIT)
self.setting4 = '0'
self.channame = self.Label
elif self.chantype == 8:
XMLTV = listXMLTV()
xmltvFle = xmltvflePath(XMLTV)
if self.Path.startswith('plugin://plugin.video.ustvnow'):
self.Label = self.Label.split(' - ')[0]
dname = "USTVnow - "+self.Label
else:
dname = self.Label
if xmltvFle:
self.channame, self.setting1 = self.chnlst.findZap2itID(dname, xmltvFle)
self.channame = self.Label+" USTV"
self.setting2 = self.Path
self.setting3 = XMLTV
elif self.chantype == 9:
self.setting1 = '5400'
self.setting2 = self.Path
self.setting3 = self.Label
self.setting4 = self.Description
self.channame = self.Label +' - '+ self.AddonName
elif self.chantype == 10:
if self.YTtype == 1:
self.setting1 = ((self.Path).replace('plugin://plugin.video.youtube/channel/','')).replace('/','')
elif self.YTtype == 2:
self.setting1 = ((self.Path).replace('plugin://plugin.video.','').replace('youtube/playlist/','').replace('spotitube/?limit&mode=listyoutubeplaylist&type=browse&url=','')).replace('/','')
self.setting2 = str(self.YTtype)
self.setting3 = str(MEDIA_LIMIT)
self.setting4 = '0'
self.channame = self.Label
elif self.chantype == 15:
self.setting1 = self.Path
self.setting2 = ''
self.setting3 = str(MEDIA_LIMIT)
self.setting4 = '0'
self.channame = self.Label +' - '+ self.AddonName
elif self.chantype == 16:
self.setting1 = self.Path
self.setting2 = ''
self.setting3 = str(MEDIA_LIMIT)
self.setting4 = '0'
self.channame = self.Label
self.saveSettings()
self.openManager()
def openManager(self):
if dlg.yesno("PseudoTV Live", 'Channel Successfully Added', 'Open Channel Manager?'):
xbmc.executebuiltin("RunScript("+ADDON_PATH+"/config.py, %s)" %str(self.channel))
def getChtype(self, channel):
self.log("getChtype")
try:
chantype = int(ADDON_SETTINGS.getSetting("Channel_" + str(channel - 1) + "_type"))
except:
chantype = 9999
return chantype
def updateListing(self, channel = -1):
self.log("updateListing")
start = 0
end = CHANNEL_LIMIT
if channel > -1:
start = channel - 1
end = channel
for i in range(start, end):
try:
theitem = self.theitem[i]
chantype = 9999
chansetting1 = ''
chansetting2 = ''
chansetting3 = ''
chansetting4 = ''
channame = ''
newlabel = ''
try:
chantype = int(ADDON_SETTINGS.getSetting("Channel_" + str(i + 1) + "_type"))
chansetting1 = ADDON_SETTINGS.getSetting("Channel_" + str(i + 1) + "_1")
chansetting2 = ADDON_SETTINGS.getSetting("Channel_" + str(i + 1) + "_2")
chansetting3 = ADDON_SETTINGS.getSetting("Channel_" + str(i + 1) + "_3")
chansetting4 = ADDON_SETTINGS.getSetting("Channel_" + str(i + 1) + "_4")
channame = ADDON_SETTINGS.getSetting("Channel_" + str(i + 1) + "_rule_1_opt_1")
except:
pass
if chantype <= 7:
option = chansetting1
else:
option = channame
newlabel = getChanPrefix(chantype, option)
if newlabel:
newlabel = '[COLOR=dimgrey][B]'+ theitem +'[/B] - '+ newlabel+'[/COLOR]'
else:
newlabel = '[COLOR=blue][B]'+theitem+'[/B][/COLOR]'
self.itemlst.append(newlabel)
except:
pass
self.log("updateListing return")
def saveSettings(self):
self.log("saveSettings channel " + str(self.channel))
chantype = 9999
chan = str(self.channel)
setProperty("PTVL.CM.LASTCHAN",chan)
chantype = "Channel_" + chan + "_type"
setting1 = "Channel_" + chan + "_1"
setting2 = "Channel_" + chan + "_2"
setting3 = "Channel_" + chan + "_3"
setting4 = "Channel_" + chan + "_4"
ADDON_SETTINGS.setSetting(chantype, str(self.chantype))
ADDON_SETTINGS.setSetting(setting1, self.setting1)
ADDON_SETTINGS.setSetting(setting2, self.setting2)
ADDON_SETTINGS.setSetting(setting3, self.setting3)
ADDON_SETTINGS.setSetting(setting4, self.setting4)
ADDON_SETTINGS.setSetting(setting4, self.setting4)
if chantype > 6:
ADDON_SETTINGS.setSetting("Channel_" + chan + "_rulecount", "1")
ADDON_SETTINGS.setSetting("Channel_" + chan + "_rule_1_id", "1")
ADDON_SETTINGS.setSetting("Channel_" + chan + "_rule_1_opt_1", self.channame)
ADDON_SETTINGS.setSetting("Channel_" + chan + "_changed", "True")
self.log("saveSettings return")
if (__name__ == "__main__"):
Main()
xbmc.log('PseudoTV Live Export Finished')