示例#1
0
    def __init__(self, *args, **kwargs):
        self.log("__init__")
        if xbmcgui.Window(10000).getProperty("PseudoTVRunning") != "True":
            xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs)
            self.madeChanges = 0
            self.showingList = True
            self.channel = 0
            self.channel_type = 9999
            self.setting1 = ''
            self.setting2 = ''
            self.setting3 = ''
            self.setting4 = ''
            self.savedRules = False
            self.DirName = ''
            self.PluginSourcePathDir = ''
            self.LockBrowse = False
            self.chnlst = ChannelList()
            if CHANNEL_SHARING:
                realloc = REAL_SETTINGS.getSetting('SettingsFolder')
                FileAccess.copy(realloc + '/settings2.xml',
                                SETTINGS_LOC + '/settings2.xml')

            ADDON_SETTINGS.loadSettings()
            ADDON_SETTINGS.disableWriteOnSave()
            self.doModal()
            self.log("__init__ return")
        else:
            xbmc.executebuiltin(
                "Notification( %s, %s, %d, %s)" %
                ("PseudoTV Lite", "Not available while running.", 4000, THUMB))
示例#2
0
    def _parse_argv(self):
        self.handle = None
        self.infos = []
        self.params = {
            " Label": None,
            " Path": None,
            " FileName": None,
            " DBIDType": None,
            " AddonName": None,
            " AddonType": None,
            " Description": None,
            " isPlayable": None,
            " isFolder": None
        }
        for arg in sys.argv:
            if arg == 'script.pseudotv.live':
                continue
            param = (arg.replace('"', '').replace("'", " ").replace(
                "[ ", " ").replace(" ]", " ").replace("' ",
                                                      "'").replace(" ' ", "'"))
            try:
                self.params[param.split("=")[0]] = "=".join(
                    param.split("=")[1:]).strip()
            except:
                pass

        self.log("params = " + str(self.params))
        self.Label = self.params[" Label"] = self.params.get(" Label",
                                                             "").strip()
        self.Path = self.params[" Path"] = self.params.get(" Path", "").strip()
        self.FileName = self.params[" FileName"] = self.params.get(
            " FileName", "").strip()
        self.DBIDType = self.params[" DBIDType"] = self.params.get(
            " DBIDType", "").strip()
        self.AddonName = self.params[" AddonName"] = self.params.get(
            " AddonName", "").strip()
        self.AddonType = self.params[" AddonType"] = self.params.get(
            " AddonType", "").strip()

        try:
            self.Description = self.params[" Description"] = self.params.get(
                " Description", "").strip()
        except:
            self.Description = self.params[" Description"] = self.params.get(
                "Description", "").strip()

        self.isPlayable = self.params[" isPlayable"] = self.params.get(
            " isPlayable", "").strip()
        self.isFolder = self.params[" isFolder"] = self.params.get(
            " isFolder", "").strip()

        if self.AddonName:
            ADDON = xbmcaddon.Addon(id=self.AddonName)
            ADDON_ID = ADDON.getAddonInfo('id')
            self.AddonName = ADDON.getAddonInfo('name')
        self.chnlst = ChannelList()
        self.Label = self.chnlst.CleanLabels(self.Label)
        self.Description = self.chnlst.CleanLabels(self.Description)
        self.AddonName = self.chnlst.CleanLabels(self.AddonName)
        self.ImportChannel()
示例#3
0
def addBypass():
    chnlst = ChannelList()
    chnlst.fillPluginList()
    BYPASS_LST = matchMselect(
        chnlst.pluginPathList,
        mselectDialog(chnlst.pluginNameList,
                      header='Enable Seeking for specified Plugins'))
    REAL_SETTINGS.setSetting("BYPASS_LST", str(BYPASS_LST))
示例#4
0
def addBypass():
    try:
        from resources.lib.ChannelList import ChannelList
        chnlst = ChannelList()
        chnlst.fillPluginList()
        BYPASS_LST = matchMselect(chnlst.pluginList[1], mselectDialog(chnlst.pluginList[0], header='Disable Seeking for specified Plugins'))
        REAL_SETTINGS.setSetting("BYPASS_LST",str(BYPASS_LST))
    except:
        Unavailable()
示例#5
0
    def __init__(self, *args, **kwargs):
        self.log("__init__")
        if xbmcgui.Window(10000).getProperty("PseudoTVRunning") != "True":
            xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs)
            self.madeChanges = 0
            self.showingList = True
            self.channel = 0
            self.channel_type = 9999
            self.setting1 = ''
            self.setting2 = ''
            self.setting3 = ''
            self.setting4 = ''
            self.savedRules = False
            self.DirName = ''
            self.PluginSourcePathDir = ''
            self.LockBrowse = False
            self.chnlst = ChannelList()
            if CHANNEL_SHARING:
                realloc = REAL_SETTINGS.getSetting('SettingsFolder')
                FileAccess.copy(realloc + '/settings2.xml', SETTINGS_LOC + '/settings2.xml')

            ADDON_SETTINGS.loadSettings()
            ADDON_SETTINGS.disableWriteOnSave()
            self.doModal()
            self.log("__init__ return")
        else:
            xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % ("PseudoTV Lite", "Not available while running.", 4000, THUMB) )
示例#6
0
    def buildChannel(self):
        self.log("buildChannel, chantype = " + str(self.chantype))
        self.chnlst = ChannelList()
        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: 
            xmltvFle = xmltvflePath(listXMLTV())
            if self.Path.startswith('plugin://plugin.video.ustvnow'):
                self.Label = self.Label.split(' - ')[0]
                dname = "USTVnow - "+self.Label
            else:
                dname = self.Label
                
            self.channame, self.setting1 = self.chnlst.findZap2itID(dname, xmltvFle)
            self.channame = self.Label+" USTV"
            self.setting2 = self.Path
                
        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
            
        self.saveSettings()
        if dlg.yesno("PseudoTV Live", 'Channel Successfully Added', 'Open Channel Manager?'):
            xbmc.executebuiltin("RunScript("+ADDON_PATH+"/config.py, %s)" %str(self.channel))
示例#7
0
 def __init__(self):
     self.log("__init__")
     # 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.chnlst = ChannelList()
     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()
示例#8
0
    def __init__(self):
        self.log("__init__")
        setProperty("PseudoTVConfigRunning", "True")

        while getProperty("PseudoTVService") == "True":
            xbmc.sleep(25)

        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 prepareConfig(self):
        self.log("prepareConfig")
        self.showList = []
        self.getControl(105).setVisible(False)
        self.getControl(106).setVisible(False)
        self.dlg = xbmcgui.DialogProgress()
        self.dlg.create("PseudoTV Live", "Preparing Configuration")
        self.dlg.update(1)
        chnlst = ChannelList()
        self.dlg.update(50)
        chnlst.fillMusicInfo()
        self.dlg.update(60)
        chnlst.fillTVInfo()
        self.dlg.update(70)
        chnlst.fillMovieInfo()
        self.dlg.update(80)
        self.mixedGenreList = chnlst.makeMixedList(chnlst.showGenreList,
                                                   chnlst.movieGenreList)
        self.networkList = chnlst.networkList
        self.studioList = chnlst.studioList
        self.showGenreList = chnlst.showGenreList
        self.movieGenreList = chnlst.movieGenreList
        self.musicGenreList = chnlst.musicGenreList

        for i in range(len(chnlst.showList)):
            self.showList.append(chnlst.showList[i][0])

        self.mixedGenreList.sort(key=lambda x: x.lower())
        self.listcontrol = self.getControl(102)

        for i in range(999):
            theitem = xbmcgui.ListItem()
            theitem.setLabel(str(i + 1))
            self.listcontrol.addItem(theitem)

        self.dlg.update(90)
        self.updateListing()
        self.dlg.close()
        self.getControl(105).setVisible(True)
        self.getControl(106).setVisible(False)
        self.setFocusId(102)
        self.log("prepareConfig return")
示例#10
0
 def _parse_argv(self):
     self.handle = None
     self.infos = []
     self.params = {" Label": None,
                    " Path": None,
                    " FileName": None,
                    " DBIDType": None,
                    " AddonName": None,
                    " AddonType": None,
                    " Description": None,
                    " isPlayable": None,
                    " isFolder": None}
     for arg in sys.argv:
         if arg == 'script.pseudotv.live':
             continue
         param = (arg.replace('"', '').replace("'", " ").replace("[ ", " ").replace(" ]", " ").replace("' ", "'").replace(" ' ", "'"))
         try:
             self.params[param.split("=")[0]] = "=".join(param.split("=")[1:]).strip()
         except:
             pass
             
     self.log("params = " + str(self.params))
     self.Label = self.params[" Label"] = self.params.get(" Label", "").strip()
     self.Path = self.params[" Path"] = self.params.get(" Path", "").strip()
     self.FileName = self.params[" FileName"] = self.params.get(" FileName", "").strip()
     self.DBIDType = self.params[" DBIDType"] = self.params.get(" DBIDType", "").strip()
     self.AddonName = self.params[" AddonName"] = self.params.get(" AddonName", "").strip()
     self.AddonType = self.params[" AddonType"] = self.params.get(" AddonType", "").strip()
     
     try:
         self.Description = self.params[" Description"] = self.params.get(" Description", "").strip()
     except:
         self.Description = self.params[" Description"] = self.params.get("Description", "").strip()
     
     self.isPlayable = self.params[" isPlayable"] = self.params.get(" isPlayable", "").strip()
     self.isFolder = self.params[" isFolder"] = self.params.get(" isFolder", "").strip()
     
     if self.AddonName:
         ADDON = xbmcaddon.Addon(id=self.AddonName)
         ADDON_ID = ADDON.getAddonInfo('id')
         self.AddonName = ADDON.getAddonInfo('name')
     self.chnlst = ChannelList()
     self.Label = self.chnlst.CleanLabels(self.Label)
     self.Description  = self.chnlst.CleanLabels(self.Description)
     self.AddonName = self.chnlst.CleanLabels(self.AddonName)
     self.ImportChannel()
示例#11
0
    def prepareConfig(self):
        self.log("prepareConfig")
        self.showList = []
        self.getControl(105).setVisible(False)
        self.getControl(106).setVisible(False)
        self.dlg = xbmcgui.DialogProgress()
        self.dlg.create("PseudoTV Live", "Preparing Configuration")
        self.dlg.update(1)
        chnlst = ChannelList()        
        self.dlg.update(40)
        chnlst.fillMusicInfo()       
        self.dlg.update(60)
        chnlst.fillTVInfo()
        self.dlg.update(70)
        chnlst.fillMovieInfo()
        self.dlg.update(80)
        self.mixedGenreList = chnlst.makeMixedList(chnlst.showGenreList, chnlst.movieGenreList)
        self.networkList = chnlst.networkList
        self.studioList = chnlst.studioList
        self.showGenreList = chnlst.showGenreList
        self.movieGenreList = chnlst.movieGenreList
        self.musicGenreList = chnlst.musicGenreList

        for i in range(len(chnlst.showList)):
            self.showList.append(chnlst.showList[i][0])

        self.mixedGenreList.sort(key=lambda x: x.lower())
        self.listcontrol = self.getControl(102)

        for i in range(999):
            theitem = xbmcgui.ListItem()
            theitem.setLabel(str(i + 1))
            self.listcontrol.addItem(theitem)


        self.dlg.update(90)
        self.updateListing()
        self.dlg.close()
        self.getControl(105).setVisible(True)
        self.getControl(106).setVisible(False)
        self.setFocusId(102)
        self.log("prepareConfig return")
示例#12
0
    def ImportChannel(self):
        self.log("ImportChannel")
        show_busy_dialog()
        self.chnlst = ChannelList()
        self.chantype = 9999
        self.setting1 = ''
        self.setting2 = ''
        self.setting3 = ''
        self.setting4 = ''
        self.channame = ''
        self.theitem = []
        self.itemlst = []
        ADDON_SETTINGS.loadSettings()

        for i in range(999):
            self.theitem.append(str(i + 1))
        self.updateListing()
        hide_busy_dialog()
        available = False
        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.spotitube/?limit&mode=listyoutubeplaylist'
                    ):
                        self.chantype = 10
                        self.YTtype = 2
                    elif self.Path.lower().startswith(
                        ('plugin', 'http', 'rtmp', 'pvr')):
                        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':
                                self.chantype = 15
                    elif self.isFolder == 'True':
                        if self.DBIDType == 'tvshow':
                            self.chantype = 6
                        elif self.DBIDType == '':
                            self.chantype = 7
                    self.buildChannel()
                else:
                    xbmc.executebuiltin(
                        "Notification( %s, %s, %d, %s)" %
                        ("PseudoTV Live", "Channel " + str(self.channel) +
                         " already in use", 1000, THUMB))
            else:
                available = True
示例#13
0
class Main:
  
    def log(self, msg, level = xbmc.LOGDEBUG):
        log('capture: ' + msg, level)

        
    def __init__(self):
        self.log("__init__")
        # 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.chnlst = ChannelList()
        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.chnlst = ChannelList()
        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
        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.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 buildChannel(self):
        self.log("buildChannel, chantype = " + str(self.chantype))
        self.chnlst = ChannelList()
        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: 
            xmltvFle = xmltvflePath(listXMLTV())
            if self.Path.startswith('plugin://plugin.video.ustvnow'):
                self.Label = self.Label.split(' - ')[0]
                dname = "USTVnow - "+self.Label
            else:
                dname = self.Label
                
            self.channame, self.setting1 = self.chnlst.findZap2itID(dname, xmltvFle)
            self.channame = self.Label+" USTV"
            self.setting2 = self.Path
                
        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
            
        self.saveSettings()
        if dlg.yesno("PseudoTV Live", 'Channel Successfully Added', 'Open Channel Manager?'):
            xbmc.executebuiltin("RunScript("+ADDON_PATH+"/config.py, %s)" %str(self.channel))
                
        
    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 == 0:
                    newlabel = self.getSmartPlaylistName(chansetting1) + " - Playlist"
                elif chantype == 5:
                    newlabel = chansetting1 + " - Mixed"
                elif chantype in [1,3,6]:
                    newlabel = chansetting1 + " - TV"
                elif chantype in [2,4]:
                    newlabel = chansetting1 + " - Movies"
                elif chantype == 7:
                    if chansetting1[-1] == '/' or chansetting1[-1] == '\\':
                        newlabel = os.path.split(chansetting1[:-1])[1]
                    else:
                        newlabel = os.path.split(chansetting1)[1]
                    newlabel = newlabel + " - Directory" 
                elif chantype == 8:
                    newlabel = channame + " - LiveTV"
                elif chantype == 9:
                    newlabel = channame + " - InternetTV"
                elif chantype == 10:
                    newlabel = channame + " - Youtube"            
                elif chantype == 11:
                    newlabel = channame + " - RSS"            
                elif chantype == 12:
                    newlabel = channame + " - Music"
                elif chantype == 13:
                    newlabel = channame + " - Music Videos"
                elif chantype == 14:
                    newlabel = channame + " - Exclusive"
                elif chantype == 15:
                    newlabel = channame + " - Plugin"
                elif chantype == 16:
                    newlabel = channame + " - UPNP"
                    
                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")
示例#14
0
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

                    # determine chtype
                    if self.AddonName == 'PseudoCompanion' and self.Label.startswith(
                            'Cinema Theme'):
                        self.chantype = 14
                    elif 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 yesnoDialog('Add source as',
                                           no="LiveTV",
                                           yes="InternetTV"):
                                self.chantype = 8
                            else:
                                self.chantype = 9
                        else:
                            if self.Path.lower().startswith(
                                ('pvr')) and self.Label.startswith('Channels'):
                                self.chantype = 8
                                return self.buildNetworks(self.Path +
                                                          'tv/All channels/')
                            elif self.Path.lower().startswith(('pvr')):
                                self.chantype = 8
                            elif self.isFolder == True and self.Label.lower(
                            ) in ['pseudonetworks', 'networks', 'channels'
                                  ] and self.Path.lower().startswith(
                                      ('plugin')):
                                self.chantype = 15
                                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
                    else:
                        infoDialog("Not a valid source")
                    self.buildChannel()
                else:
                    infoDialog("Channel " + str(self.channel) +
                               " already in use")
            else:
                available = True
        self.log("chantype = " + str(self.chantype))

    # export bulk channels, add subfolders as channels.
    def buildNetworks(self, url):
        self.log("buildNetworks, url = " + url)
        detail = uni(self.chnlst.requestList(url))
        if yesnoDialog('Add %d 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':
                        if self.chantype == 15:
                            self.setting1 = file
                            self.setting2 = ''
                            self.setting3 = ''
                            self.setting4 = '1'
                            self.channame = name
                            self.saveSettings()
                            self.fixChannel(self.channel)

                    elif filetype == 'file':
                        if self.chantype == 8:
                            self.setting1 = name
                            self.setting2 = file
                            self.setting3 = 'pvr'
                            self.setting4 = ''
                            self.channame = name
                            self.saveSettings()
                            self.fixChannel(self.channel)
            hide_busy_dialog()
            self.openManager()

    # find next available channel when exporting bulk channels.
    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.setting2 = '4'
            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 = ''
            self.setting4 = '0'
            self.channame = self.Label

        elif self.chantype == 8:
            XMLTV = listXMLTV()
            if XMLTV:
                xmltvFle = xmltvflePath(XMLTV)
            else:
                self.chantype = 9
                self.buildChannel()

            if xmltvFle:
                self.channame, self.setting1 = self.chnlst.findZap2itID(
                    self.chnlst.cleanLabels(self.Label),
                    xbmc.translatePath(xmltvFle))
                self.channame = self.Label
                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 = '500'
            self.setting4 = '0'

            if self.Label.startswith('UC'):
                self.channame = self.chnlst.getYoutubeChname(self.Label)
            else:
                self.channame = self.Label

        elif self.chantype == 14:
            if self.Label.startswith('Cinema Theme'):
                self.setting1 = 'cinema'
                self.setting2 = self.Path
                self.setting3 = self.Label
                self.setting4 = ''
                self.channame = 'PseudoCinema'

        elif self.chantype == 15:
            self.setting1 = self.Path
            self.setting2 = ''
            self.setting3 = PLUGINUPNP_MAXPARSE
            self.setting4 = '0'
            self.channame = self.Label

        elif self.chantype == 16:
            self.setting1 = self.Path
            self.setting2 = ''
            self.setting3 = ''
            self.setting4 = '0'
            self.channame = self.Label

        self.saveSettings()
        self.openManager()

    def openManager(self):
        if yesnoDialog('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 = ''

                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")
                except:
                    pass

                if chantype != 9999:
                    name = self.chnlst.getChannelName(chantype, i + 1,
                                                      chansetting1, False)
                    channame = getChanPrefix(chantype, name)

                if channame:
                    channame = '[COLOR=dimgrey][B]' + theitem + '[/B] - ' + channame + '[/COLOR]'
                else:
                    channame = '[COLOR=blue][B]' + theitem + '[/B][/COLOR]'
                self.itemlst.append(channame)
            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("Channel_" + chan + "_changed", "True")
        # set chname rule
        if chantype > 7:
            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)

        # set PseudoCinema rules
        if chantype == 14 and self.channame == 'PseudoCinema':
            ADDON_SETTINGS.setSetting(
                "Channel_" + str(channelNum) + "_rulecount", "5")
            ADDON_SETTINGS.setSetting(
                "Channel_" + str(channelNum) + "_rule_1_id", "1")
            ADDON_SETTINGS.setSetting(
                "Channel_" + str(channelNum) + "_rule_1_opt_1", "PseudoCinema")
            ADDON_SETTINGS.setSetting(
                "Channel_" + str(channelNum) + "_rule_2_id", "8")
            ADDON_SETTINGS.setSetting(
                "Channel_" + str(channelNum) + "_rule_3_id", "14")
            ADDON_SETTINGS.setSetting(
                "Channel_" + str(channelNum) + "_rule_3_opt_1", "No")
            ADDON_SETTINGS.setSetting(
                "Channel_" + str(channelNum) + "_rule_4_id", "17")
            ADDON_SETTINGS.setSetting(
                "Channel_" + str(channelNum) + "_rule_4_opt_1", "No")
            ADDON_SETTINGS.setSetting(
                "Channel_" + str(channelNum) + "_rule_5_id", "15")
            ADDON_SETTINGS.setSetting(
                "Channel_" + str(channelNum) + "_rule_5_opt_1", "No")

        if chantype in [15, 16]:
            ADDON_SETTINGS.setSetting("Channel_" + chan + "_rulecount", "2")
            ADDON_SETTINGS.setSetting("Channel_" + chan + "_rule_2_id", "20")
            ADDON_SETTINGS.setSetting("Channel_" + chan + "_rule_2_opt_1",
                                      str(MINFILE_DURATION))
        self.log("saveSettings return")
示例#15
0
class Main:
    def log(self, msg, level=xbmc.LOGDEBUG):
        log('capture: ' + msg, level)

    def __init__(self):
        self.log("__init__")
        # 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.chnlst = ChannelList()
        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.chnlst = ChannelList()
        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
        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.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 buildChannel(self):
        self.log("buildChannel, chantype = " + str(self.chantype))
        self.chnlst = ChannelList()
        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:
            xmltvFle = xmltvflePath(listXMLTV())
            if self.Path.startswith('plugin://plugin.video.ustvnow'):
                self.Label = self.Label.split(' - ')[0]
                dname = "USTVnow - " + self.Label
            else:
                dname = self.Label

            self.channame, self.setting1 = self.chnlst.findZap2itID(
                dname, xmltvFle)
            self.channame = self.Label + " USTV"
            self.setting2 = self.Path

        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

        self.saveSettings()
        if dlg.yesno("PseudoTV Live", 'Channel Successfully Added',
                     'Open Channel Manager?'):
            xbmc.executebuiltin("RunScript(" + ADDON_PATH +
                                "/config.py, %s)" % str(self.channel))

    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 == 0:
                    newlabel = self.getSmartPlaylistName(
                        chansetting1) + " - Playlist"
                elif chantype == 5:
                    newlabel = chansetting1 + " - Mixed"
                elif chantype in [1, 3, 6]:
                    newlabel = chansetting1 + " - TV"
                elif chantype in [2, 4]:
                    newlabel = chansetting1 + " - Movies"
                elif chantype == 7:
                    if chansetting1[-1] == '/' or chansetting1[-1] == '\\':
                        newlabel = os.path.split(chansetting1[:-1])[1]
                    else:
                        newlabel = os.path.split(chansetting1)[1]
                    newlabel = newlabel + " - Directory"
                elif chantype == 8:
                    newlabel = channame + " - LiveTV"
                elif chantype == 9:
                    newlabel = channame + " - InternetTV"
                elif chantype == 10:
                    newlabel = channame + " - Youtube"
                elif chantype == 11:
                    newlabel = channame + " - RSS"
                elif chantype == 12:
                    newlabel = channame + " - Music"
                elif chantype == 13:
                    newlabel = channame + " - Music Videos"
                elif chantype == 14:
                    newlabel = channame + " - Exclusive"
                elif chantype == 15:
                    newlabel = channame + " - Plugin"
                elif chantype == 16:
                    newlabel = channame + " - UPNP"

                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")
示例#16
0
class ConfigWindow(xbmcgui.WindowXMLDialog):
    def __init__(self, *args, **kwargs):
        self.log("__init__")
        if xbmcgui.Window(10000).getProperty("PseudoTVRunning") != "True":
            xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs)
            self.madeChanges = 0
            self.showingList = True
            self.channel = 0
            self.channel_type = 9999
            self.setting1 = ''
            self.setting2 = ''
            self.setting3 = ''
            self.setting4 = ''
            self.savedRules = False
            self.DirName = ''
            self.PluginSourcePathDir = ''
            self.LockBrowse = False
            self.chnlst = ChannelList()
            if CHANNEL_SHARING:
                realloc = REAL_SETTINGS.getSetting('SettingsFolder')
                FileAccess.copy(realloc + '/settings2.xml', SETTINGS_LOC + '/settings2.xml')

            ADDON_SETTINGS.loadSettings()
            ADDON_SETTINGS.disableWriteOnSave()
            self.doModal()
            self.log("__init__ return")
        else:
            xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % ("PseudoTV Lite", "Not available while running.", 4000, THUMB) )


    def log(self, msg, level = xbmc.LOGDEBUG):
        log('ChannelConfig: ' + msg, level)


    def onInit(self):
        self.log("onInit")
        REAL_SETTINGS.setSetting('Autotune', "false")
        REAL_SETTINGS.setSetting('Warning1', "false") 
        self.KodiVideoSources()
        
        for i in range(NUMBER_CHANNEL_TYPES):
            try:
                self.getControl(120 + i).setVisible(False)
            except:
                pass

        migratemaster = Migrate()
        migratemaster.migrate()
        self.prepareConfig()
        self.myRules = AdvancedConfig("script.pseudotv.live.AdvancedConfig.xml", ADDON_PATH, "Default")
        self.log("onInit return")


    def onFocus(self, controlId):
        pass


    def onAction(self, act):
        action = act.getId()

        if action in ACTION_PREVIOUS_MENU:
            if self.showingList == False:
                self.cancelChan()
                self.hideChanDetails()
            else:
                if self.madeChanges == 1:
                    dlg = xbmcgui.Dialog()

                    if dlg.yesno("Save", "Do you want to save all changes?"):
                        ADDON_SETTINGS.writeSettings()
            
                        if CHANNEL_SHARING:
                            realloc = REAL_SETTINGS.getSetting('SettingsFolder')
                            FileAccess.copy(SETTINGS_LOC + '/settings2.xml', realloc + '/settings2.xml')

                self.close()
        elif act.getButtonCode() == 61575:      # Delete button
            curchan = self.listcontrol.getSelectedPosition() + 1

            if( (self.showingList == True) and (ADDON_SETTINGS.getSetting("Channel_" + str(curchan) + "_type") != "9999") ):
                dlg = xbmcgui.Dialog()

                if dlg.yesno("Save", "Are you sure you want to clear this channel?"):
                    ADDON_SETTINGS.setSetting("Channel_" + str(curchan) + "_type", "9999")
                    self.updateListing(curchan)
                    self.madeChanges = 1


    def KodiVideoSources(self):
        sourcepath = xbmc.translatePath(os.path.join('special://profile/','sources.xml'))
        self.log("KodiVideoSources, sources.xml = " + sourcepath)
        json_query = ('{"jsonrpc":"2.0","method":"Files.GetSources","params":{"media":"video"},"id":1}')
        json_folder_detail = self.chnlst.sendJSON(json_query)
        file_detail = re.compile( "{(.*?)}", re.DOTALL ).findall(json_folder_detail)
        PVR = False
        UPNP = False
        HDHR = False
        Restart = False
        a = '<video>'
        b = '<video>\n'

        for f in file_detail:
            match = re.search('"file" *: *"(.*?)",', f)
            if match:
                if match.group(1) == 'pvr://':
                    PVR = True
                elif match.group(1) == 'upnp://':
                    UPNP = True
                elif match.group(1) == 'hdhomerun://':
                    HDHR = True         
        self.log("KodiVideoSources, PVR = " + str(PVR) + " UPNP = " + str(UPNP) + " HDHR = " + str(HDHR))
        
        if PVR == False:
            b = b + '<source>\n<name>PVR</name>\n<path pathversion="1">pvr://</path>\n<allowsharing>true</allowsharing>\n</source>\n'
        if UPNP == False:
            b = b + '<source>\n<name>UPnP Media Servers (Auto-Discover)</name>\n<path pathversion="1">upnp://</path>\n<allowsharing>true</allowsharing>\n</source>\n'
        if HDHR == False:
            b = b + '<source>\n<name>HDHomerun Devices</name>\n<path pathversion="1">hdhomerun://</path>\n<allowsharing>true</allowsharing>\n</source>\n'
        
        try:
            f = open(sourcepath, "r")
            linesLST = f.readlines()  
            f.close()

            for i in range(len(linesLST)):
                line = linesLST[i]
                if a in line:
                    self.log("KodiVideoSources, a found replacing with b = " + b)
                    replaceAll(sourcepath,a,b)  
                    Restart = True      
                    break
        except:
            self.log("KodiVideoSources, sources.xml missing")
            # todo write missing sourcxml Restart = True
            pass

        if Restart:
            if dlg.yesno("PseudoTV Lite", "System Reboot recommend, Exit XBMC?"):
                xbmc.executebuiltin( "XBMC.AlarmClock(shutdowntimer,XBMC.Quit(),%d,true)" % ( 0.5, ) )      
            
            
    def saveSettings(self):
        self.log("saveSettings channel " + str(self.channel))
        chantype = 9999
        chan = str(self.channel)
        set1 = ''
        set2 = ''
        set3 = ''
        set4 = ''
        channame = ''

        try:
            chantype = int(ADDON_SETTINGS.getSetting("Channel_" + chan + "_type"))
        except:
            self.log("Unable to get channel type")

        setting1 = "Channel_" + chan + "_1"
        setting2 = "Channel_" + chan + "_2"
        setting3 = "Channel_" + chan + "_3"
        setting4 = "Channel_" + chan + "_4"
        channame = ADDON_SETTINGS.getSetting("Channel_" + chan + "_rule_1_opt_1")

        if chantype == 0:
            ADDON_SETTINGS.setSetting(setting1, self.getControl(330).getLabel2())
        elif chantype == 1:
            ADDON_SETTINGS.setSetting(setting1, self.getControl(142).getLabel())
        elif chantype == 2:
            ADDON_SETTINGS.setSetting(setting1, self.getControl(152).getLabel())
        elif chantype == 3:
            ADDON_SETTINGS.setSetting(setting1, self.getControl(162).getLabel())
        elif chantype == 4:
            ADDON_SETTINGS.setSetting(setting1, self.getControl(172).getLabel())
        elif chantype == 5:
            ADDON_SETTINGS.setSetting(setting1, self.getControl(182).getLabel())
        elif chantype == 6:
            ADDON_SETTINGS.setSetting(setting1, self.getControl(190).getLabel())
            if self.getControl(194).isSelected():
                ADDON_SETTINGS.setSetting(setting2, str(MODE_ORDERAIRDATE))
            else:
                ADDON_SETTINGS.setSetting(setting2, "0")
        elif chantype == 7:
            ADDON_SETTINGS.setSetting(setting1, self.getControl(200).getLabel())
            ADDON_SETTINGS.setSetting(setting3, self.getControl(201).getLabel())
            ADDON_SETTINGS.setSetting(setting4, self.getControl(202).getLabel())
        elif chantype == 8: #LiveTV
            ADDON_SETTINGS.setSetting(setting1, self.getControl(216).getLabel())
            ADDON_SETTINGS.setSetting(setting2, self.getControl(217).getLabel())
            ADDON_SETTINGS.setSetting(setting3, self.getControl(212).getLabel())
        elif chantype == 9: #InternetTV
            ADDON_SETTINGS.setSetting(setting1, self.getControl(226).getLabel())
            ADDON_SETTINGS.setSetting(setting2, self.getControl(227).getLabel())
            ADDON_SETTINGS.setSetting(setting3, self.getControl(222).getLabel())
            ADDON_SETTINGS.setSetting(setting4, self.getControl(223).getLabel())
        elif chantype == 9999:
            ADDON_SETTINGS.setSetting(setting1, '')
            ADDON_SETTINGS.setSetting(setting2, '')
            ADDON_SETTINGS.setSetting(setting3, '')
            ADDON_SETTINGS.setSetting(setting4, '')

        if self.savedRules:
            self.saveRules(self.channel)

        # Check to see if the user changed anything
        set1 = ''
        set2 = ''
        set3 = ''
        set4 = ''

        try:
            set1 = ADDON_SETTINGS.getSetting(setting1)
            set2 = ADDON_SETTINGS.getSetting(setting2)
            set3 = ADDON_SETTINGS.getSetting(setting3)
            set4 = ADDON_SETTINGS.getSetting(setting4)
        except:
            pass

        if chantype != self.channel_type or set1 != self.setting1 or set2 != self.setting2 or self.savedRules:
            self.madeChanges = 1
            ADDON_SETTINGS.setSetting('Channel_' + chan + '_changed', 'True')
        self.log("saveSettings return")


    def cancelChan(self):
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_type", str(self.channel_type))
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_1", self.setting1)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_2", self.setting2)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_3", self.setting3)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_4", self.setting4)


    def hideChanDetails(self):
        self.getControl(106).setVisible(False)
        
        for i in range(NUMBER_CHANNEL_TYPES):
            try:
                self.getControl(120 + i).setVisible(False)
            except:
                pass

        self.setFocusId(102)
        self.getControl(105).setVisible(True)
        self.showingList = True
        self.updateListing(self.channel)
        self.listcontrol.selectItem(self.channel - 1)


    def onClick(self, controlId):
        self.log("onClick " + str(controlId))
        dlg = xbmcgui.Dialog()
        YTFilter = ['User Subscription','User Favorites','Search Query','Raw gdata']  
        
        if controlId == 102:        # Channel list entry selected
            self.getControl(105).setVisible(False)
            self.getControl(106).setVisible(True)
            self.channel = self.listcontrol.getSelectedPosition() + 1
            self.changeChanType(self.channel, 0)
            self.setFocusId(110)
            self.showingList = False
            self.savedRules = False
        elif controlId == 110:      # Change channel type left
            self.changeChanType(self.channel, -1)
            self.clearLabel()
        elif controlId == 111:      # Change channel type right
            self.changeChanType(self.channel, 1)
            self.clearLabel()
        elif controlId == 112:      # Ok button
            self.saveSettings()
            self.hideChanDetails()
        elif controlId == 113:      # Cancel button
            self.cancelChan()
            self.hideChanDetails()
        elif controlId == 555:      # Help Guide
            self.help()
        elif controlId == 114:      # Rules button
            self.myRules.ruleList = self.ruleList
            self.myRules.doModal()
            if self.myRules.wasSaved == True:
                self.ruleList = self.myRules.ruleList
                self.savedRules = True
        elif controlId == 330:      # Playlist-type channel, playlist button
            retval = dlg.browse(1, "Channel " + str(self.channel) + " Playlist", "files", ".xsp", False, False, "special://videoplaylists/")
            if retval != "special://videoplaylists/":
                self.getControl(330).setLabel(self.getSmartPlaylistName(retval), label2=retval)
        
        elif controlId == 331:      # Playlist-type Editor button
            smartplaylist = "special://videoplaylists/" + os.path.split(self.getControl(330).getLabel2())[1]
            xbmc.executebuiltin( "ActivateWindow(10136,%s)" % (smartplaylist) )
        
        elif controlId == 140:      # Network TV channel, left
            self.changeListData(self.networkList, 142, -1)
        elif controlId == 141:      # Network TV channel, right
            self.changeListData(self.networkList, 142, 1)
        elif controlId == 150:      # Movie studio channel, left
            self.changeListData(self.studioList, 152, -1)
        elif controlId == 151:      # Movie studio channel, right
            self.changeListData(self.studioList, 152, 1)
        elif controlId == 160:      # TV Genre channel, left
            self.changeListData(self.showGenreList, 162, -1)     
        elif controlId == 161:      # TV Genre channel, right
            self.changeListData(self.showGenreList, 162, 1)
        elif controlId == 170:      # Movie Genre channel, left
            self.changeListData(self.movieGenreList, 172, -1)
        elif controlId == 171:      # Movie Genre channel, right
            self.changeListData(self.movieGenreList, 172, 1)
        elif controlId == 180:      # Mixed Genre channel, left
            self.changeListData(self.mixedGenreList, 182, -1)
        elif controlId == 181:      # Mixed Genre channel, right
            self.changeListData(self.mixedGenreList, 182, 1)
        elif controlId == 190:      # TV Show channel, left
            select = selectDialog(self.showList, 'Select TV Show')
            if len(self.showList[select]) > 0:
                self.getControl(190).setLabel(self.showList[select])
        
        elif controlId == 200:      # Directory channel, select
            retval = dlg.browse(0, "Channel " + str(self.channel) + " Directory", "files")
            if len(retval) > 0:
                self.getControl(200).setLabel(retval)       
        
        elif controlId == 201:    # setLabel MediaLimit, select 
            select = selectDialog(self.MediaLimitList, 'Select Media Limit')
            self.getControl(201).setLabel(self.MediaLimitList[select])
        elif controlId == 202:    # setLabel SortOrder, select 
            select = selectDialog(self.SortOrderList, 'Select Sorting Order')
            self.getControl(202).setLabel(self.SortOrderList[select]) 
        #LiveTV
        elif controlId == 216:    # LiveTV Channel ID, select
            setting3 = self.getControl(212).getLabel()
            if setting3 == '':
                xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % ("PseudoTV Lite", "Enter Channel & XMLTV Name", 4000, THUMB) )
            else:
                dnameID, CHid = self.chnlst.findZap2itID(self.getControl(213).getLabel(), 'pvr')
                self.getControl(216).setLabel(CHid)

        elif controlId == 211:    # LiveTV Browse, select
            if self.LockBrowse:
                xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % ("PseudoTV Lite", "File Already Selected", 1000, THUMB) )     
                return
            elif len(self.getControl(211).getLabel()) > 1:
                title, retval = self.fillSources('LiveTV', self.getControl(214).getLabel(), self.getControl(217).getLabel())
            else:
                try:
                    title, retval = self.fillSources('LiveTV', self.getControl(214).getLabel())
                except:
                    xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % ("PseudoTV Lite", "Select Source First", 1000, THUMB) )     
                    pass
            try:
                self.getControl(211).setLabel(title)
                self.getControl(217).setLabel(retval)
                title, genre = title.split(' - ')
            except:
                pass
        elif controlId == 212:    # LiveTV XMLTV Name, Select
            self.getControl(212).setLabel('pvr')
        
        elif controlId == 213:    # LiveTV Channel Name, input
            retval = dlg.input(self.getControl(213).getLabel(), type=xbmcgui.INPUT_ALPHANUM)
            if len(retval) > 0:
                if retval.startswith(' '):
                    retval = retval[1:]
                self.getControl(213).setLabel(retval)
                #Set Channel Name
                ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_rulecount", "1")
                ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_rule_1_id", "1")
                ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_rule_1_opt_1", retval) 
        
        elif controlId == 215:      # LiveTV Source Type, left
            self.changeListData(self.SourceList, 214, -1)
            self.clearLabel(211)
            self.clearLabel(217)
            self.LockBrowse = False
        elif controlId == 210:      # LiveTV Source Type, right
            self.changeListData(self.SourceList, 214, 1)
            self.clearLabel(211)
            self.clearLabel(217)
            self.LockBrowse = False

        #InternetTV
        elif controlId == 226:    # InternetTV Duration, input
            retval = dlg.input(self.getControl(226).getLabel(), type=xbmcgui.INPUT_NUMERIC)
            if len(retval) > 0:
                self.getControl(226).setLabel(retval)
            
        elif controlId == 221:    # InternetTV Browse, select
            if self.LockBrowse:
                xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % ("PseudoTV Lite", "File Already Selected", 1000, THUMB) )     
                return
            elif len(self.getControl(221).getLabel()) > 1:
                title, retval = self.fillSources('InternetTV', self.getControl(224).getLabel(), self.getControl(227).getLabel())
            else:   
                try:
                    title, retval = self.fillSources('InternetTV', self.getControl(224).getLabel())                
                    if title.startswith(' '):
                        title = title[1:]
                except:
                    xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % ("PseudoTV Lite", "Select Source First", 1000, THUMB) )
            self.getControl(221).setLabel(title)
            self.getControl(227).setLabel(retval)
            self.getControl(226).setLabel('5400')
            
            try:
                title, genre = title.split(' - ')
            except:
                pass
            #Set Channel Name
            self.getControl(222).setLabel(title)
            self.getControl(223).setLabel(self.getControl(224).getLabel())
            ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_rulecount", "1")
            ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_rule_1_id", "1")
            ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_rule_1_opt_1", title)
        
        elif controlId == 222:    # InternetTV Title, input
            retval = dlg.input(self.getControl(222).getLabel(), type=xbmcgui.INPUT_ALPHANUM)
            self.getControl(222).setLabel(retval)
        
        elif controlId == 223:    # InternetTV Description, input
            retval = dlg.input(self.getControl(223).getLabel(), type=xbmcgui.INPUT_ALPHANUM)
            self.getControl(223).setLabel(retval)
        
        elif controlId == 225:      # InternetTV Source Type, left
            self.changeListData(self.SourceList, 224, -1)
            self.clearLabel(221)
            self.clearLabel(227)
            self.LockBrowse = False
        elif controlId == 220:      # InternetTV Source Type, right
            self.changeListData(self.SourceList, 224, 1)
            self.clearLabel(221)
            self.clearLabel(227)
            self.LockBrowse = False
        self.log("onClick return")


    def changeListData(self, thelist, controlid, val):
        self.log("changeListData " + str(controlid) + ", " + str(val))
        curval = self.getControl(controlid).getLabel()
        found = False
        index = 0

        if len(thelist) == 0:
            self.getControl(controlid).setLabel('')
            self.log("changeListData return Empty list")
            return

        for item in thelist:
            if item == curval:
                found = True
                break
            index += 1
        if found == True:
            index += val
        while index < 0:
            index += len(thelist)
        while index >= len(thelist):
            index -= len(thelist)

        self.getControl(controlid).setLabel(thelist[index])
        self.log("changeListData return")


    def getSmartPlaylistName(self, fle):
        self.log("getSmartPlaylistName " + fle)
        fle = xbmc.translatePath(fle)

        try:
            xml = FileAccess.open(fle, "r")
        except:
            self.log('Unable to open smart playlist')
            return ''

        try:
            dom = parse(xml)
        except:
            xml.close()
            self.log("getSmartPlaylistName return unable to parse")
            return ''

        xml.close()

        try:
            plname = dom.getElementsByTagName('name')
            self.log("getSmartPlaylistName return " + plname[0].childNodes[0].nodeValue)
            return plname[0].childNodes[0].nodeValue
        except:
            self.playlist('Unable to find element name')

        self.log("getSmartPlaylistName return")


    def changeChanType(self, channel, val):
        self.log("changeChanType " + str(channel) + ", " + str(val))
        chantype = 9999

        try:
            chantype = int(ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_type"))
        except:
            self.log("Unable to get channel type")

        if val != 0:
            chantype += val

            if chantype < 0:
                chantype = 9999
            elif chantype == 10000:
                chantype = 0
            elif chantype == 9998:
                chantype = NUMBER_CHANNEL_TYPES - 1
            elif chantype == NUMBER_CHANNEL_TYPES:
                chantype = 9999

            ADDON_SETTINGS.setSetting("Channel_" + str(channel) + "_type", str(chantype))
        else:
            self.channel_type = chantype
            self.setting1 = ''
            self.setting2 = ''
            self.setting3 = ''
            self.setting4 = ''

            try:
                self.setting1 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_1")
                self.setting2 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_2")
                self.setting3 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_3")
                self.setting4 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_4")
            except:
                pass

        for i in range(NUMBER_CHANNEL_TYPES):
            if i == chantype:
                self.getControl(120 + i).setVisible(True)
                if chantype != 0:
                    self.getControl(110).controlDown(self.getControl(120 + ((i + 1) * 10)))
                    try:
                        if chantype >= 8:
                            raise
                        self.getControl(111).controlDown(self.getControl(120 + ((i + 1) * 10 + 1)))
                    except:
                        self.getControl(111).controlDown(self.getControl(120 + ((i + 1) * 10)))
                else:
                    self.getControl(110).controlDown(self.getControl(330))
            else:
                try:
                    self.getControl(120 + i).setVisible(False)
                except:
                    pass

        self.fillInDetails(channel)
        self.log("changeChanType return")


    def fillInDetails(self, channel):
        self.log("fillInDetails " + str(channel))
        self.getControl(104).setLabel("Channel " + str(channel))
        chantype = 9999
        chansetting1 = ''
        chansetting2 = ''
        chansetting3 = ''
        chansetting4 = ''
        channame = ''
        try:
            chantype = int(ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_type"))
            chansetting1 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_1")
            chansetting2 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_2")
            chansetting3 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_3")
            chansetting4 = (ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_4")).replace('1','Default').replace('2','Random').replace('3','Reverse')
            channame = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_rule_1_opt_1")
        except:
            self.log("Unable to get some setting")

        chansetting4 = chansetting4.replace('0','Default').replace('1','Random').replace('2','Reverse')
        self.getControl(109).setLabel(self.getChanTypeLabel(chantype))
   
        if chantype == 0:
            plname = self.getSmartPlaylistName(chansetting1)

            if len(plname) == 0:
                chansetting1 = ''
                # chansetting1 = 'Playlist:                                                                                                                      '
            self.getControl(330).setLabel(self.getSmartPlaylistName(chansetting1), label2=chansetting1)
            
        elif chantype == 1:
            self.getControl(142).setLabel(self.findItemInList(self.networkList, chansetting1))
        elif chantype == 2:
            self.getControl(152).setLabel(self.findItemInList(self.studioList, chansetting1))
        elif chantype == 3:
            self.getControl(162).setLabel(self.findItemInList(self.showGenreList, chansetting1))
        elif chantype == 4:
            self.getControl(172).setLabel(self.findItemInList(self.movieGenreList, chansetting1))
        elif chantype == 5:
            self.getControl(182).setLabel(self.findItemInList(self.mixedGenreList, chansetting1))
        elif chantype == 6:
            self.getControl(190).setLabel(self.findItemInList(self.showList, chansetting1))
            self.getControl(194).setSelected(chansetting2 == str(MODE_ORDERAIRDATE))
        elif chantype == 7:
            if (chansetting1.find('/') > -1) or (chansetting1.find('\\') > -1):
                plname = self.getSmartPlaylistName(chansetting1)
                if len(plname) != 0:
                    chansetting1 = ''
            else:
                chansetting1 = ''
            self.getControl(200).setLabel(chansetting1)
            self.getControl(201).setLabel(self.findItemInList(self.MediaLimitList, chansetting3))
            self.getControl(202).setLabel(self.findItemInList(self.SortOrderList, chansetting4))
        elif chantype == 8:
            self.getControl(216).setLabel(chansetting1)
            self.getControl(217).setLabel(chansetting2)
            self.getControl(212).setLabel(chansetting3)
            self.getControl(213).setLabel(channame)
        elif chantype == 9:
            self.getControl(226).setLabel(chansetting1)
            self.getControl(227).setLabel(chansetting2)
            self.getControl(222).setLabel(chansetting3)
            self.getControl(223).setLabel(chansetting4)
                    
        self.loadRules(channel)
        self.log("fillInDetails return")


    def loadRules(self, channel):
        self.log("loadRules")
        self.ruleList = []
        self.myRules.allRules

        try:
            rulecount = int(ADDON_SETTINGS.getSetting('Channel_' + str(channel) + '_rulecount'))

            for i in range(rulecount):
                ruleid = int(ADDON_SETTINGS.getSetting('Channel_' + str(channel) + '_rule_' + str(i + 1) + '_id'))

                for rule in self.myRules.allRules.ruleList:
                    if rule.getId() == ruleid:
                        self.ruleList.append(rule.copy())

                        for x in range(rule.getOptionCount()):
                            self.ruleList[-1].optionValues[x] = ADDON_SETTINGS.getSetting('Channel_' + str(channel) + '_rule_' + str(i + 1) + '_opt_' + str(x + 1))

                        foundrule = True
                        break
        except:
            self.ruleList = []


    def saveRules(self, channel):
        self.log("saveRules")
        rulecount = len(self.ruleList)
        ADDON_SETTINGS.setSetting('Channel_' + str(channel) + '_rulecount', str(rulecount))
        index = 1

        for rule in self.ruleList:
            ADDON_SETTINGS.setSetting('Channel_' + str(channel) + '_rule_' + str(index) + '_id', str(rule.getId()))

            for x in range(rule.getOptionCount()):
                ADDON_SETTINGS.setSetting('Channel_' + str(channel) + '_rule_' + str(index) + '_opt_' + str(x + 1), rule.getOptionValue(x))

            index += 1


    def findItemInList(self, thelist, item):
        loitem = item.lower()

        for i in thelist:
            if loitem == i.lower():
                return item

        if len(thelist) > 0:
            return thelist[0]
        return ''    
        
        
    def findItemLens(self, thelist, item):
        loitem = item.lower()

        for i in range(len(thelist)):
            line = (thelist[i]).lower()
            if line == loitem:
                return i
        return ''


    def getChanTypeLabel(self, chantype):
        if chantype == 0:
            return "Custom Playlist"
        elif chantype == 1:
            return "TV Network"
        elif chantype == 2:
            return "Movie Studio"
        elif chantype == 3:
            return "TV Genre"
        elif chantype == 4:
            return "Movie Genre"
        elif chantype == 5:
            return "Mixed Genre"
        elif chantype == 6:
            return "TV Show"
        elif chantype == 7:
            return "Directory"
        elif chantype == 8:
            return "LiveTV"
        elif chantype == 9:
            return "InternetTV"
        elif chantype == 9999:
            return "None"
        return ''

        
    def prepareConfig(self):
        self.log("prepareConfig")
        self.showList = []
        self.getControl(105).setVisible(False)
        self.getControl(106).setVisible(False)
        self.dlg = xbmcgui.DialogProgress()
        self.dlg.create("PseudoTV Lite", "Preparing Configuration")
        self.dlg.update(1)        
        self.dlg.update(50)
        self.chnlst.fillMusicInfo()       
        self.dlg.update(60)
        self.chnlst.fillTVInfo()
        self.dlg.update(70)
        self.chnlst.fillMovieInfo()
        self.dlg.update(80)
        self.chnlst.fillFavourites()
        self.dlg.update(90)
        self.mixedGenreList = self.chnlst.makeMixedList(self.chnlst.showGenreList, self.chnlst.movieGenreList)
        self.networkList = self.chnlst.networkList
        self.studioList = self.chnlst.studioList
        self.showGenreList = self.chnlst.showGenreList
        self.movieGenreList = self.chnlst.movieGenreList
        self.musicGenreList = self.chnlst.musicGenreList
        self.FavouritesPathList = self.chnlst.FavouritesPathList
        self.FavouritesNameList = self.chnlst.FavouritesNameList
        self.MediaLimitList = ['25','50','100','150','200','250','500','1000']
        self.SortOrderList = ['Default','Random','Reverse']
        self.SourceTypes = ['PVR','HDhomerun','Local Video','Local Music','UPNP','Kodi Favourites','URL']
        self.SourceList = self.SourceTypes
            
        for i in range(len(self.chnlst.showList)):
            self.showList.append(self.chnlst.showList[i][0])
        
        self.showList =  sorted_nicely(self.showList)
        self.mixedGenreList.sort(key=lambda x: x.lower())
        self.listcontrol = self.getControl(102)

        for i in range(999):
            theitem = xbmcgui.ListItem()
            theitem.setLabel(str(i + 1))
            self.listcontrol.addItem(theitem)

        self.dlg.update(90)
        self.updateListing()
        self.dlg.close()
        self.getControl(105).setVisible(True)
        self.getControl(106).setVisible(False)
        self.setFocusId(102)
        self.log("prepareConfig return")

    def clearLabel(self, id=None):
        print 'clearLabel'
        if id: 
            try:
                self.getControl(id).reset()
            except:
                pass
        else:
            for i in range(NUMBER_CHANNEL_TYPES):
                if i >= 7:
                    base = (120 + ((i + 1) * 10))
                    for n in range(10):
                        id = base + n
                        try:
                            self.getControl(id).reset()
                        except:
                            break
                            
                            
    def fillSources(self, type, source, path=None):
        self.log("fillSources")
        dlg = xbmcgui.Dialog()
        print source, type, path
        # Parse Source, return title, path
        try:
            if source == 'PVR':
                self.log("PVR")
                retval = dlg.browse(1, "Select File", "video", "", False, False, "pvr://")
                if len(retval) > 0:
                    return retval, retval
            elif source == 'HDhomerun':
                self.log("HDhomerun")
                xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % ("PseudoTV Lite", "Coming Soon", 4000, THUMB) )
            elif source == 'Local Video':
                self.log("Local Video")
                retval = dlg.browse(1, "Select File", "video", ".avi|.mp4|.m4v|.3gp|.3g2|.f4v|.mov|.mkv|.flv|.ts|.m2ts|.strm", False, False, "")
                if len(retval) > 0:
                    return retval, retval           
            elif source == 'Local Music':
                self.log("Local Music")
                retval = dlg.browse(1, "Select File", "music", ".mp3|.flac|.mp4", False, False, "")
                if len(retval) > 0:
                    return retval, retval
            elif source == 'UPNP':
                self.log("UPNP")
                retval = dlg.browse(1, "Select File", "video", "", False, False, "upnp://")
                return retval
            elif source == 'Kodi Favourites':
                self.log("Kodi Favourites")
                select = selectDialog(self.FavouritesNameList, 'Select Favourites')
                return self.FavouritesNameList[select], self.FavouritesPathList[select]  
            elif source == 'URL':
                self.log("URL")
                input = dlg.input('Enter URL', type=xbmcgui.INPUT_ALPHANUM)
                if len(input) > 0:
                    return input, input
            else:
                return  
        except:
            xbmc.executebuiltin( "Dialog.Close(busydialog)" )
            buggalo.onExceptionRaised() 
            
            
    def help(self):
        BaseURL = 'https://pseudotv-live-community.googlecode.com/svn/'
        type = self.getControl(109).getLabel()
        URL = BaseURL + "help_" + type.lower()
        self.log("help URL = " + URL)
        title = type + ' Channel Configuration Help'
        f = Open_URL(URL)
        text = f.read()
        showText(title, text)
           
           
    def updateListing(self, channel = -1):
        self.log("updateListing")
        start = 0
        end = 999

        if channel > -1:
            start = channel - 1
            end = channel

        for i in range(start, end):
            theitem = self.listcontrol.getListItem(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 == 0:
                newlabel = self.getSmartPlaylistName(chansetting1)
            elif chantype == 1 or chantype == 2 or chantype == 5 or chantype == 6:
                newlabel = chansetting1
            elif chantype == 3:
                newlabel = chansetting1 + " - TV"
            elif chantype == 4:
                newlabel = chansetting1 + " - Movies"
            elif chantype == 7:
                if chansetting1[-1] == '/' or chansetting1[-1] == '\\':
                    newlabel = os.path.split(chansetting1[:-1])[1]
                else:
                    newlabel = os.path.split(chansetting1)[1]
            elif chantype == 8:
                newlabel = channame + " - LiveTV"
            elif chantype == 9:
                newlabel = channame + " - InternetTV"
            
            theitem.setLabel2(newlabel)
        self.log("updateListing return")
示例#17
0
class Main:
  
    def log(self, msg, level = xbmc.LOGDEBUG):
        log('capture: ' + msg, level)

        
    def __init__(self):
        self.log("__init__")
        setProperty("PseudoTVConfigRunning", "True")
        
        while getProperty("PseudoTVService") == "True":
            xbmc.sleep(25)
            
        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 onInit(self):
        self.log("onInit")
        chkLowPower()
        
        
    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
                    
                    # determine chtype
                    if self.AddonName == 'PseudoCompanion' and self.Label.startswith('Cinema Theme'):
                        self.chantype = 14
                    elif 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 yesnoDialog('Add source as', no="LiveTV", yes="InternetTV"):
                                self.chantype = 8
                            else:
                                self.chantype = 9
                        else:
                            if self.Path.lower().startswith(('pvr')) and self.Label.startswith('Channels'):
                                self.chantype = 8
                                return self.buildNetworks(self.Path+'tv/All channels/')
                            elif self.Path.lower().startswith(('pvr')):
                                self.chantype = 8
                            elif self.isFolder == True and self.Label.lower() in ['pseudonetworks','networks','channels'] and self.Path.lower().startswith(('plugin')):
                                self.chantype = 15
                                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    
                    else:
                        infoDialog("Not a valid source")                    
                    self.buildChannel()
                else:
                    infoDialog("Channel "+str(self.channel)+" already in use")
            else:
                available = True
        self.log("chantype = "+str(self.chantype))
            
            
    # export bulk channels, add subfolders as channels.
    def buildNetworks(self, url):
        self.log("buildNetworks, url = " + url)
        detail = uni(self.chnlst.requestList(url))
        if yesnoDialog('Add %d 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':
                        if self.chantype == 15:
                            self.setting1 = file
                            self.setting2 = ''
                            self.setting3 = ''
                            self.setting4 = '1'
                            self.channame = name
                            self.saveSettings()
                            self.fixChannel(self.channel)
                            
                    elif filetype == 'file':
                        if self.chantype == 8:
                            self.setting1 = name
                            self.setting2 = file
                            self.setting3 = 'pvr'
                            self.setting4 = ''
                            self.channame = name
                            self.saveSettings()
                            self.fixChannel(self.channel)
            hide_busy_dialog()
            self.openManager()
    
    
    # find next available channel when exporting bulk channels.
    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.setting2 = '4'
            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 = ''
            self.setting4 = '0'
            self.channame = self.Label
            
        elif self.chantype == 8:
            XMLTV = listXMLTV()
            xmltvFle = False
            if XMLTV:
                xmltvFle = xmltvflePath(XMLTV)
                if xmltvFle:
                    self.channame, self.setting1 = self.chnlst.findZap2itID(self.chnlst.cleanLabels(self.Label), xbmc.translatePath(xmltvFle))
                    self.channame = self.Label
                    self.setting2 = self.Path
                    self.setting3 = XMLTV
            else:
                return
                # self.chantype = 9
                # self.buildChannel()
            
        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 = '500'
            self.setting4 = '0'
            
            if self.Label.startswith('UC'):
                self.channame = self.chnlst.getYoutubeChname(self.Label) 
            else:
                self.channame = self.Label
            
        elif self.chantype == 14:
            if self.Label.startswith('Cinema Theme'):
                self.setting1 = 'cinema'
                self.setting2 = self.Path
                self.setting3 = self.Label
                self.setting4 = ''
                self.channame = 'PseudoCinema'   
            
        elif self.chantype == 15:
            self.setting1 = self.Path
            self.setting2 = ''
            self.setting3 = PLUGINUPNP_MAXPARSE
            self.setting4 = '0'
            self.channame = self.Label
            
        elif self.chantype == 16:
            self.setting1 = self.Path
            self.setting2 = ''
            self.setting3 = ''
            self.setting4 = '0'
            self.channame = self.Label
            
        self.saveSettings()
        self.openManager()
        
        
    def openManager(self):
        if yesnoDialog('Channel Successfully Added', 'Open Channel Manager?'):
            xbmc.executebuiltin("RunScript("+ADDON_PATH+"/config.py, %s)" %str(self.channel))
        else:
            setProperty("PseudoTVConfigRunning", "False")

            
    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 = ''

                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")
                except:
                    pass

                if chantype != 9999:
                    name = self.chnlst.getChannelName(chantype, i+1, chansetting1, False)
                    channame = getChanPrefix(chantype, name)
                    
                if channame:
                    channame = '[COLOR=dimgrey][B]'+ theitem +'[/B] - '+ channame+'[/COLOR]'
                else:
                    channame = '[COLOR=blue][B]'+theitem+'[/B][/COLOR]'
                self.itemlst.append(channame)
            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("Channel_" + chan + "_changed", "True")
        # set chname rule
        if chantype > 7:
            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)    
            
        # set PseudoCinema rules
        if chantype == 14 and self.channame == 'PseudoCinema':
            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rulecount", "5")
            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_id", "1")
            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_opt_1", "PseudoCinema")  
            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_2_id", "8")
            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_3_id", "14")
            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_3_opt_1", "No")  
            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_4_id", "17")
            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_4_opt_1", "No")  
            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_5_id", "15")
            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_5_opt_1", "No") 
            
        if chantype in [15,16]:
            ADDON_SETTINGS.setSetting("Channel_" + chan + "_rulecount", "2")
            ADDON_SETTINGS.setSetting("Channel_" + chan + "_rule_2_id", "20")
            ADDON_SETTINGS.setSetting("Channel_" + chan + "_rule_2_opt_1", str(MINFILE_DURATION))   
        self.log("saveSettings return")
示例#18
0
class ConfigWindow(xbmcgui.WindowXMLDialog):
    def __init__(self, *args, **kwargs):
        self.log("__init__")
        if xbmcgui.Window(10000).getProperty("PseudoTVRunning") != "True":
            xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs)
            self.madeChanges = 0
            self.showingList = True
            self.channel = 0
            self.channel_type = 9999
            self.setting1 = ''
            self.setting2 = ''
            self.setting3 = ''
            self.setting4 = ''
            self.savedRules = False
            self.DirName = ''
            self.PluginSourcePathDir = ''
            self.LockBrowse = False
            self.chnlst = ChannelList()
            if CHANNEL_SHARING:
                realloc = REAL_SETTINGS.getSetting('SettingsFolder')
                FileAccess.copy(realloc + '/settings2.xml',
                                SETTINGS_LOC + '/settings2.xml')

            ADDON_SETTINGS.loadSettings()
            ADDON_SETTINGS.disableWriteOnSave()
            self.doModal()
            self.log("__init__ return")
        else:
            xbmc.executebuiltin(
                "Notification( %s, %s, %d, %s)" %
                ("PseudoTV Lite", "Not available while running.", 4000, THUMB))

    def log(self, msg, level=xbmc.LOGDEBUG):
        log('ChannelConfig: ' + msg, level)

    def onInit(self):
        self.log("onInit")
        REAL_SETTINGS.setSetting('Autotune', "false")
        REAL_SETTINGS.setSetting('Warning1', "false")
        self.KodiVideoSources()

        for i in range(NUMBER_CHANNEL_TYPES):
            try:
                self.getControl(120 + i).setVisible(False)
            except:
                pass

        migratemaster = Migrate()
        migratemaster.migrate()
        self.prepareConfig()
        self.myRules = AdvancedConfig(
            "script.pseudotv.live.AdvancedConfig.xml", ADDON_PATH, "Default")
        self.log("onInit return")

    def onFocus(self, controlId):
        pass

    def onAction(self, act):
        action = act.getId()

        if action in ACTION_PREVIOUS_MENU:
            if self.showingList == False:
                self.cancelChan()
                self.hideChanDetails()
            else:
                if self.madeChanges == 1:
                    dlg = xbmcgui.Dialog()

                    if dlg.yesno("Save", "Do you want to save all changes?"):
                        ADDON_SETTINGS.writeSettings()

                        if CHANNEL_SHARING:
                            realloc = REAL_SETTINGS.getSetting(
                                'SettingsFolder')
                            FileAccess.copy(SETTINGS_LOC + '/settings2.xml',
                                            realloc + '/settings2.xml')

                self.close()
        elif act.getButtonCode() == 61575:  # Delete button
            curchan = self.listcontrol.getSelectedPosition() + 1

            if ((self.showingList == True) and
                (ADDON_SETTINGS.getSetting("Channel_" + str(curchan) + "_type")
                 != "9999")):
                dlg = xbmcgui.Dialog()

                if dlg.yesno("Save",
                             "Are you sure you want to clear this channel?"):
                    ADDON_SETTINGS.setSetting(
                        "Channel_" + str(curchan) + "_type", "9999")
                    self.updateListing(curchan)
                    self.madeChanges = 1

    def KodiVideoSources(self):
        sourcepath = xbmc.translatePath(
            os.path.join('special://profile/', 'sources.xml'))
        self.log("KodiVideoSources, sources.xml = " + sourcepath)
        json_query = (
            '{"jsonrpc":"2.0","method":"Files.GetSources","params":{"media":"video"},"id":1}'
        )
        json_folder_detail = self.chnlst.sendJSON(json_query)
        file_detail = re.compile("{(.*?)}",
                                 re.DOTALL).findall(json_folder_detail)
        PVR = False
        UPNP = False
        HDHR = False
        Restart = False
        a = '<video>'
        b = '<video>\n'

        for f in file_detail:
            match = re.search('"file" *: *"(.*?)",', f)
            if match:
                if match.group(1) == 'pvr://':
                    PVR = True
                elif match.group(1) == 'upnp://':
                    UPNP = True
                elif match.group(1) == 'hdhomerun://':
                    HDHR = True
        self.log("KodiVideoSources, PVR = " + str(PVR) + " UPNP = " +
                 str(UPNP) + " HDHR = " + str(HDHR))

        if PVR == False:
            b = b + '<source>\n<name>PVR</name>\n<path pathversion="1">pvr://</path>\n<allowsharing>true</allowsharing>\n</source>\n'
        if UPNP == False:
            b = b + '<source>\n<name>UPnP Media Servers (Auto-Discover)</name>\n<path pathversion="1">upnp://</path>\n<allowsharing>true</allowsharing>\n</source>\n'
        if HDHR == False:
            b = b + '<source>\n<name>HDHomerun Devices</name>\n<path pathversion="1">hdhomerun://</path>\n<allowsharing>true</allowsharing>\n</source>\n'

        try:
            f = open(sourcepath, "r")
            linesLST = f.readlines()
            f.close()

            for i in range(len(linesLST)):
                line = linesLST[i]
                if a in line:
                    self.log("KodiVideoSources, a found replacing with b = " +
                             b)
                    replaceAll(sourcepath, a, b)
                    Restart = True
                    break
        except:
            self.log("KodiVideoSources, sources.xml missing")
            # todo write missing sourcxml Restart = True
            pass

        if Restart:
            if dlg.yesno("PseudoTV Lite",
                         "System Reboot recommend, Exit XBMC?"):
                xbmc.executebuiltin(
                    "XBMC.AlarmClock(shutdowntimer,XBMC.Quit(),%d,true)" %
                    (0.5, ))

    def saveSettings(self):
        self.log("saveSettings channel " + str(self.channel))
        chantype = 9999
        chan = str(self.channel)
        set1 = ''
        set2 = ''
        set3 = ''
        set4 = ''
        channame = ''

        try:
            chantype = int(
                ADDON_SETTINGS.getSetting("Channel_" + chan + "_type"))
        except:
            self.log("Unable to get channel type")

        setting1 = "Channel_" + chan + "_1"
        setting2 = "Channel_" + chan + "_2"
        setting3 = "Channel_" + chan + "_3"
        setting4 = "Channel_" + chan + "_4"
        channame = ADDON_SETTINGS.getSetting("Channel_" + chan +
                                             "_rule_1_opt_1")

        if chantype == 0:
            ADDON_SETTINGS.setSetting(setting1,
                                      self.getControl(330).getLabel2())
        elif chantype == 1:
            ADDON_SETTINGS.setSetting(setting1,
                                      self.getControl(142).getLabel())
        elif chantype == 2:
            ADDON_SETTINGS.setSetting(setting1,
                                      self.getControl(152).getLabel())
        elif chantype == 3:
            ADDON_SETTINGS.setSetting(setting1,
                                      self.getControl(162).getLabel())
        elif chantype == 4:
            ADDON_SETTINGS.setSetting(setting1,
                                      self.getControl(172).getLabel())
        elif chantype == 5:
            ADDON_SETTINGS.setSetting(setting1,
                                      self.getControl(182).getLabel())
        elif chantype == 6:
            ADDON_SETTINGS.setSetting(setting1,
                                      self.getControl(190).getLabel())
            if self.getControl(194).isSelected():
                ADDON_SETTINGS.setSetting(setting2, str(MODE_ORDERAIRDATE))
            else:
                ADDON_SETTINGS.setSetting(setting2, "0")
        elif chantype == 7:
            ADDON_SETTINGS.setSetting(setting1,
                                      self.getControl(200).getLabel())
            ADDON_SETTINGS.setSetting(setting3,
                                      self.getControl(201).getLabel())
            ADDON_SETTINGS.setSetting(setting4,
                                      self.getControl(202).getLabel())
        elif chantype == 8:  #LiveTV
            ADDON_SETTINGS.setSetting(setting1,
                                      self.getControl(216).getLabel())
            ADDON_SETTINGS.setSetting(setting2,
                                      self.getControl(217).getLabel())
            ADDON_SETTINGS.setSetting(setting3,
                                      self.getControl(212).getLabel())
        elif chantype == 9:  #InternetTV
            ADDON_SETTINGS.setSetting(setting1,
                                      self.getControl(226).getLabel())
            ADDON_SETTINGS.setSetting(setting2,
                                      self.getControl(227).getLabel())
            ADDON_SETTINGS.setSetting(setting3,
                                      self.getControl(222).getLabel())
            ADDON_SETTINGS.setSetting(setting4,
                                      self.getControl(223).getLabel())
        elif chantype == 9999:
            ADDON_SETTINGS.setSetting(setting1, '')
            ADDON_SETTINGS.setSetting(setting2, '')
            ADDON_SETTINGS.setSetting(setting3, '')
            ADDON_SETTINGS.setSetting(setting4, '')

        if self.savedRules:
            self.saveRules(self.channel)

        # Check to see if the user changed anything
        set1 = ''
        set2 = ''
        set3 = ''
        set4 = ''

        try:
            set1 = ADDON_SETTINGS.getSetting(setting1)
            set2 = ADDON_SETTINGS.getSetting(setting2)
            set3 = ADDON_SETTINGS.getSetting(setting3)
            set4 = ADDON_SETTINGS.getSetting(setting4)
        except:
            pass

        if chantype != self.channel_type or set1 != self.setting1 or set2 != self.setting2 or self.savedRules:
            self.madeChanges = 1
            ADDON_SETTINGS.setSetting('Channel_' + chan + '_changed', 'True')
        self.log("saveSettings return")

    def cancelChan(self):
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_type",
                                  str(self.channel_type))
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_1",
                                  self.setting1)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_2",
                                  self.setting2)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_3",
                                  self.setting3)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_4",
                                  self.setting4)

    def hideChanDetails(self):
        self.getControl(106).setVisible(False)

        for i in range(NUMBER_CHANNEL_TYPES):
            try:
                self.getControl(120 + i).setVisible(False)
            except:
                pass

        self.setFocusId(102)
        self.getControl(105).setVisible(True)
        self.showingList = True
        self.updateListing(self.channel)
        self.listcontrol.selectItem(self.channel - 1)

    def onClick(self, controlId):
        self.log("onClick " + str(controlId))
        dlg = xbmcgui.Dialog()
        YTFilter = [
            'User Subscription', 'User Favorites', 'Search Query', 'Raw gdata'
        ]

        if controlId == 102:  # Channel list entry selected
            self.getControl(105).setVisible(False)
            self.getControl(106).setVisible(True)
            self.channel = self.listcontrol.getSelectedPosition() + 1
            self.changeChanType(self.channel, 0)
            self.setFocusId(110)
            self.showingList = False
            self.savedRules = False
        elif controlId == 110:  # Change channel type left
            self.changeChanType(self.channel, -1)
            self.clearLabel()
        elif controlId == 111:  # Change channel type right
            self.changeChanType(self.channel, 1)
            self.clearLabel()
        elif controlId == 112:  # Ok button
            self.saveSettings()
            self.hideChanDetails()
        elif controlId == 113:  # Cancel button
            self.cancelChan()
            self.hideChanDetails()
        elif controlId == 555:  # Help Guide
            self.help()
        elif controlId == 114:  # Rules button
            self.myRules.ruleList = self.ruleList
            self.myRules.doModal()
            if self.myRules.wasSaved == True:
                self.ruleList = self.myRules.ruleList
                self.savedRules = True
        elif controlId == 330:  # Playlist-type channel, playlist button
            retval = dlg.browse(1,
                                "Channel " + str(self.channel) + " Playlist",
                                "files", ".xsp", False, False,
                                "special://videoplaylists/")
            if retval != "special://videoplaylists/":
                self.getControl(330).setLabel(
                    self.getSmartPlaylistName(retval), label2=retval)

        elif controlId == 331:  # Playlist-type Editor button
            smartplaylist = "special://videoplaylists/" + os.path.split(
                self.getControl(330).getLabel2())[1]
            xbmc.executebuiltin("ActivateWindow(10136,%s)" % (smartplaylist))

        elif controlId == 140:  # Network TV channel, left
            self.changeListData(self.networkList, 142, -1)
        elif controlId == 141:  # Network TV channel, right
            self.changeListData(self.networkList, 142, 1)
        elif controlId == 150:  # Movie studio channel, left
            self.changeListData(self.studioList, 152, -1)
        elif controlId == 151:  # Movie studio channel, right
            self.changeListData(self.studioList, 152, 1)
        elif controlId == 160:  # TV Genre channel, left
            self.changeListData(self.showGenreList, 162, -1)
        elif controlId == 161:  # TV Genre channel, right
            self.changeListData(self.showGenreList, 162, 1)
        elif controlId == 170:  # Movie Genre channel, left
            self.changeListData(self.movieGenreList, 172, -1)
        elif controlId == 171:  # Movie Genre channel, right
            self.changeListData(self.movieGenreList, 172, 1)
        elif controlId == 180:  # Mixed Genre channel, left
            self.changeListData(self.mixedGenreList, 182, -1)
        elif controlId == 181:  # Mixed Genre channel, right
            self.changeListData(self.mixedGenreList, 182, 1)
        elif controlId == 190:  # TV Show channel, left
            select = selectDialog(self.showList, 'Select TV Show')
            if len(self.showList[select]) > 0:
                self.getControl(190).setLabel(self.showList[select])

        elif controlId == 200:  # Directory channel, select
            retval = dlg.browse(0,
                                "Channel " + str(self.channel) + " Directory",
                                "files")
            if len(retval) > 0:
                self.getControl(200).setLabel(retval)

        elif controlId == 201:  # setLabel MediaLimit, select
            select = selectDialog(self.MediaLimitList, 'Select Media Limit')
            self.getControl(201).setLabel(self.MediaLimitList[select])
        elif controlId == 202:  # setLabel SortOrder, select
            select = selectDialog(self.SortOrderList, 'Select Sorting Order')
            self.getControl(202).setLabel(self.SortOrderList[select])
        #LiveTV
        elif controlId == 216:  # LiveTV Channel ID, select
            setting3 = self.getControl(212).getLabel()
            if setting3 == '':
                xbmc.executebuiltin(
                    "Notification( %s, %s, %d, %s)" %
                    ("PseudoTV Lite", "Enter Channel & XMLTV Name", 4000,
                     THUMB))
            else:
                dnameID, CHid = self.chnlst.findZap2itID(
                    self.getControl(213).getLabel(), 'pvr')
                self.getControl(216).setLabel(CHid)

        elif controlId == 211:  # LiveTV Browse, select
            if self.LockBrowse:
                xbmc.executebuiltin(
                    "Notification( %s, %s, %d, %s)" %
                    ("PseudoTV Lite", "File Already Selected", 1000, THUMB))
                return
            elif len(self.getControl(211).getLabel()) > 1:
                title, retval = self.fillSources(
                    'LiveTV',
                    self.getControl(214).getLabel(),
                    self.getControl(217).getLabel())
            else:
                try:
                    title, retval = self.fillSources(
                        'LiveTV',
                        self.getControl(214).getLabel())
                except:
                    xbmc.executebuiltin(
                        "Notification( %s, %s, %d, %s)" %
                        ("PseudoTV Lite", "Select Source First", 1000, THUMB))
                    pass
            try:
                self.getControl(211).setLabel(title)
                self.getControl(217).setLabel(retval)
                title, genre = title.split(' - ')
            except:
                pass
        elif controlId == 212:  # LiveTV XMLTV Name, Select
            self.getControl(212).setLabel('pvr')

        elif controlId == 213:  # LiveTV Channel Name, input
            retval = dlg.input(self.getControl(213).getLabel(),
                               type=xbmcgui.INPUT_ALPHANUM)
            if len(retval) > 0:
                if retval.startswith(' '):
                    retval = retval[1:]
                self.getControl(213).setLabel(retval)
                #Set Channel Name
                ADDON_SETTINGS.setSetting(
                    "Channel_" + str(self.channel) + "_rulecount", "1")
                ADDON_SETTINGS.setSetting(
                    "Channel_" + str(self.channel) + "_rule_1_id", "1")
                ADDON_SETTINGS.setSetting(
                    "Channel_" + str(self.channel) + "_rule_1_opt_1", retval)

        elif controlId == 215:  # LiveTV Source Type, left
            self.changeListData(self.SourceList, 214, -1)
            self.clearLabel(211)
            self.clearLabel(217)
            self.LockBrowse = False
        elif controlId == 210:  # LiveTV Source Type, right
            self.changeListData(self.SourceList, 214, 1)
            self.clearLabel(211)
            self.clearLabel(217)
            self.LockBrowse = False

        #InternetTV
        elif controlId == 226:  # InternetTV Duration, input
            retval = dlg.input(self.getControl(226).getLabel(),
                               type=xbmcgui.INPUT_NUMERIC)
            if len(retval) > 0:
                self.getControl(226).setLabel(retval)

        elif controlId == 221:  # InternetTV Browse, select
            if self.LockBrowse:
                xbmc.executebuiltin(
                    "Notification( %s, %s, %d, %s)" %
                    ("PseudoTV Lite", "File Already Selected", 1000, THUMB))
                return
            elif len(self.getControl(221).getLabel()) > 1:
                title, retval = self.fillSources(
                    'InternetTV',
                    self.getControl(224).getLabel(),
                    self.getControl(227).getLabel())
            else:
                try:
                    title, retval = self.fillSources(
                        'InternetTV',
                        self.getControl(224).getLabel())
                    if title.startswith(' '):
                        title = title[1:]
                except:
                    xbmc.executebuiltin(
                        "Notification( %s, %s, %d, %s)" %
                        ("PseudoTV Lite", "Select Source First", 1000, THUMB))
            self.getControl(221).setLabel(title)
            self.getControl(227).setLabel(retval)
            self.getControl(226).setLabel('5400')

            try:
                title, genre = title.split(' - ')
            except:
                pass
            #Set Channel Name
            self.getControl(222).setLabel(title)
            self.getControl(223).setLabel(self.getControl(224).getLabel())
            ADDON_SETTINGS.setSetting(
                "Channel_" + str(self.channel) + "_rulecount", "1")
            ADDON_SETTINGS.setSetting(
                "Channel_" + str(self.channel) + "_rule_1_id", "1")
            ADDON_SETTINGS.setSetting(
                "Channel_" + str(self.channel) + "_rule_1_opt_1", title)

        elif controlId == 222:  # InternetTV Title, input
            retval = dlg.input(self.getControl(222).getLabel(),
                               type=xbmcgui.INPUT_ALPHANUM)
            self.getControl(222).setLabel(retval)

        elif controlId == 223:  # InternetTV Description, input
            retval = dlg.input(self.getControl(223).getLabel(),
                               type=xbmcgui.INPUT_ALPHANUM)
            self.getControl(223).setLabel(retval)

        elif controlId == 225:  # InternetTV Source Type, left
            self.changeListData(self.SourceList, 224, -1)
            self.clearLabel(221)
            self.clearLabel(227)
            self.LockBrowse = False
        elif controlId == 220:  # InternetTV Source Type, right
            self.changeListData(self.SourceList, 224, 1)
            self.clearLabel(221)
            self.clearLabel(227)
            self.LockBrowse = False
        self.log("onClick return")

    def changeListData(self, thelist, controlid, val):
        self.log("changeListData " + str(controlid) + ", " + str(val))
        curval = self.getControl(controlid).getLabel()
        found = False
        index = 0

        if len(thelist) == 0:
            self.getControl(controlid).setLabel('')
            self.log("changeListData return Empty list")
            return

        for item in thelist:
            if item == curval:
                found = True
                break
            index += 1
        if found == True:
            index += val
        while index < 0:
            index += len(thelist)
        while index >= len(thelist):
            index -= len(thelist)

        self.getControl(controlid).setLabel(thelist[index])
        self.log("changeListData return")

    def getSmartPlaylistName(self, fle):
        self.log("getSmartPlaylistName " + fle)
        fle = xbmc.translatePath(fle)

        try:
            xml = FileAccess.open(fle, "r")
        except:
            self.log('Unable to open smart playlist')
            return ''

        try:
            dom = parse(xml)
        except:
            xml.close()
            self.log("getSmartPlaylistName return unable to parse")
            return ''

        xml.close()

        try:
            plname = dom.getElementsByTagName('name')
            self.log("getSmartPlaylistName return " +
                     plname[0].childNodes[0].nodeValue)
            return plname[0].childNodes[0].nodeValue
        except:
            self.playlist('Unable to find element name')

        self.log("getSmartPlaylistName return")

    def changeChanType(self, channel, val):
        self.log("changeChanType " + str(channel) + ", " + str(val))
        chantype = 9999

        try:
            chantype = int(
                ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_type"))
        except:
            self.log("Unable to get channel type")

        if val != 0:
            chantype += val

            if chantype < 0:
                chantype = 9999
            elif chantype == 10000:
                chantype = 0
            elif chantype == 9998:
                chantype = NUMBER_CHANNEL_TYPES - 1
            elif chantype == NUMBER_CHANNEL_TYPES:
                chantype = 9999

            ADDON_SETTINGS.setSetting("Channel_" + str(channel) + "_type",
                                      str(chantype))
        else:
            self.channel_type = chantype
            self.setting1 = ''
            self.setting2 = ''
            self.setting3 = ''
            self.setting4 = ''

            try:
                self.setting1 = ADDON_SETTINGS.getSetting("Channel_" +
                                                          str(channel) + "_1")
                self.setting2 = ADDON_SETTINGS.getSetting("Channel_" +
                                                          str(channel) + "_2")
                self.setting3 = ADDON_SETTINGS.getSetting("Channel_" +
                                                          str(channel) + "_3")
                self.setting4 = ADDON_SETTINGS.getSetting("Channel_" +
                                                          str(channel) + "_4")
            except:
                pass

        for i in range(NUMBER_CHANNEL_TYPES):
            if i == chantype:
                self.getControl(120 + i).setVisible(True)
                if chantype != 0:
                    self.getControl(110).controlDown(
                        self.getControl(120 + ((i + 1) * 10)))
                    try:
                        if chantype >= 8:
                            raise
                        self.getControl(111).controlDown(
                            self.getControl(120 + ((i + 1) * 10 + 1)))
                    except:
                        self.getControl(111).controlDown(
                            self.getControl(120 + ((i + 1) * 10)))
                else:
                    self.getControl(110).controlDown(self.getControl(330))
            else:
                try:
                    self.getControl(120 + i).setVisible(False)
                except:
                    pass

        self.fillInDetails(channel)
        self.log("changeChanType return")

    def fillInDetails(self, channel):
        self.log("fillInDetails " + str(channel))
        self.getControl(104).setLabel("Channel " + str(channel))
        chantype = 9999
        chansetting1 = ''
        chansetting2 = ''
        chansetting3 = ''
        chansetting4 = ''
        channame = ''
        try:
            chantype = int(
                ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_type"))
            chansetting1 = ADDON_SETTINGS.getSetting("Channel_" +
                                                     str(channel) + "_1")
            chansetting2 = ADDON_SETTINGS.getSetting("Channel_" +
                                                     str(channel) + "_2")
            chansetting3 = ADDON_SETTINGS.getSetting("Channel_" +
                                                     str(channel) + "_3")
            chansetting4 = (
                ADDON_SETTINGS.getSetting("Channel_" + str(channel) +
                                          "_4")).replace('1',
                                                         'Default').replace(
                                                             '2',
                                                             'Random').replace(
                                                                 '3',
                                                                 'Reverse')
            channame = ADDON_SETTINGS.getSetting("Channel_" + str(channel) +
                                                 "_rule_1_opt_1")
        except:
            self.log("Unable to get some setting")

        chansetting4 = chansetting4.replace('0', 'Default').replace(
            '1', 'Random').replace('2', 'Reverse')
        self.getControl(109).setLabel(self.getChanTypeLabel(chantype))

        if chantype == 0:
            plname = self.getSmartPlaylistName(chansetting1)

            if len(plname) == 0:
                chansetting1 = ''
                # chansetting1 = 'Playlist:                                                                                                                      '
            self.getControl(330).setLabel(
                self.getSmartPlaylistName(chansetting1), label2=chansetting1)

        elif chantype == 1:
            self.getControl(142).setLabel(
                self.findItemInList(self.networkList, chansetting1))
        elif chantype == 2:
            self.getControl(152).setLabel(
                self.findItemInList(self.studioList, chansetting1))
        elif chantype == 3:
            self.getControl(162).setLabel(
                self.findItemInList(self.showGenreList, chansetting1))
        elif chantype == 4:
            self.getControl(172).setLabel(
                self.findItemInList(self.movieGenreList, chansetting1))
        elif chantype == 5:
            self.getControl(182).setLabel(
                self.findItemInList(self.mixedGenreList, chansetting1))
        elif chantype == 6:
            self.getControl(190).setLabel(
                self.findItemInList(self.showList, chansetting1))
            self.getControl(194).setSelected(
                chansetting2 == str(MODE_ORDERAIRDATE))
        elif chantype == 7:
            if (chansetting1.find('/') > -1) or (chansetting1.find('\\') > -1):
                plname = self.getSmartPlaylistName(chansetting1)
                if len(plname) != 0:
                    chansetting1 = ''
            else:
                chansetting1 = ''
            self.getControl(200).setLabel(chansetting1)
            self.getControl(201).setLabel(
                self.findItemInList(self.MediaLimitList, chansetting3))
            self.getControl(202).setLabel(
                self.findItemInList(self.SortOrderList, chansetting4))
        elif chantype == 8:
            self.getControl(216).setLabel(chansetting1)
            self.getControl(217).setLabel(chansetting2)
            self.getControl(212).setLabel(chansetting3)
            self.getControl(213).setLabel(channame)
        elif chantype == 9:
            self.getControl(226).setLabel(chansetting1)
            self.getControl(227).setLabel(chansetting2)
            self.getControl(222).setLabel(chansetting3)
            self.getControl(223).setLabel(chansetting4)

        self.loadRules(channel)
        self.log("fillInDetails return")

    def loadRules(self, channel):
        self.log("loadRules")
        self.ruleList = []
        self.myRules.allRules

        try:
            rulecount = int(
                ADDON_SETTINGS.getSetting('Channel_' + str(channel) +
                                          '_rulecount'))

            for i in range(rulecount):
                ruleid = int(
                    ADDON_SETTINGS.getSetting('Channel_' + str(channel) +
                                              '_rule_' + str(i + 1) + '_id'))

                for rule in self.myRules.allRules.ruleList:
                    if rule.getId() == ruleid:
                        self.ruleList.append(rule.copy())

                        for x in range(rule.getOptionCount()):
                            self.ruleList[-1].optionValues[
                                x] = ADDON_SETTINGS.getSetting('Channel_' +
                                                               str(channel) +
                                                               '_rule_' +
                                                               str(i + 1) +
                                                               '_opt_' +
                                                               str(x + 1))

                        foundrule = True
                        break
        except:
            self.ruleList = []

    def saveRules(self, channel):
        self.log("saveRules")
        rulecount = len(self.ruleList)
        ADDON_SETTINGS.setSetting('Channel_' + str(channel) + '_rulecount',
                                  str(rulecount))
        index = 1

        for rule in self.ruleList:
            ADDON_SETTINGS.setSetting(
                'Channel_' + str(channel) + '_rule_' + str(index) + '_id',
                str(rule.getId()))

            for x in range(rule.getOptionCount()):
                ADDON_SETTINGS.setSetting(
                    'Channel_' + str(channel) + '_rule_' + str(index) +
                    '_opt_' + str(x + 1), rule.getOptionValue(x))

            index += 1

    def findItemInList(self, thelist, item):
        loitem = item.lower()

        for i in thelist:
            if loitem == i.lower():
                return item

        if len(thelist) > 0:
            return thelist[0]
        return ''

    def findItemLens(self, thelist, item):
        loitem = item.lower()

        for i in range(len(thelist)):
            line = (thelist[i]).lower()
            if line == loitem:
                return i
        return ''

    def getChanTypeLabel(self, chantype):
        if chantype == 0:
            return "Custom Playlist"
        elif chantype == 1:
            return "TV Network"
        elif chantype == 2:
            return "Movie Studio"
        elif chantype == 3:
            return "TV Genre"
        elif chantype == 4:
            return "Movie Genre"
        elif chantype == 5:
            return "Mixed Genre"
        elif chantype == 6:
            return "TV Show"
        elif chantype == 7:
            return "Directory"
        elif chantype == 8:
            return "LiveTV"
        elif chantype == 9:
            return "InternetTV"
        elif chantype == 9999:
            return "None"
        return ''

    def prepareConfig(self):
        self.log("prepareConfig")
        self.showList = []
        self.getControl(105).setVisible(False)
        self.getControl(106).setVisible(False)
        self.dlg = xbmcgui.DialogProgress()
        self.dlg.create("PseudoTV Lite", "Preparing Configuration")
        self.dlg.update(1)
        self.dlg.update(50)
        self.chnlst.fillMusicInfo()
        self.dlg.update(60)
        self.chnlst.fillTVInfo()
        self.dlg.update(70)
        self.chnlst.fillMovieInfo()
        self.dlg.update(80)
        self.chnlst.fillFavourites()
        self.dlg.update(90)
        self.mixedGenreList = self.chnlst.makeMixedList(
            self.chnlst.showGenreList, self.chnlst.movieGenreList)
        self.networkList = self.chnlst.networkList
        self.studioList = self.chnlst.studioList
        self.showGenreList = self.chnlst.showGenreList
        self.movieGenreList = self.chnlst.movieGenreList
        self.musicGenreList = self.chnlst.musicGenreList
        self.FavouritesPathList = self.chnlst.FavouritesPathList
        self.FavouritesNameList = self.chnlst.FavouritesNameList
        self.MediaLimitList = [
            '25', '50', '100', '150', '200', '250', '500', '1000'
        ]
        self.SortOrderList = ['Default', 'Random', 'Reverse']
        self.SourceTypes = [
            'PVR', 'HDhomerun', 'Local Video', 'Local Music', 'UPNP',
            'Kodi Favourites', 'URL'
        ]
        self.SourceList = self.SourceTypes

        for i in range(len(self.chnlst.showList)):
            self.showList.append(self.chnlst.showList[i][0])

        self.showList = sorted_nicely(self.showList)
        self.mixedGenreList.sort(key=lambda x: x.lower())
        self.listcontrol = self.getControl(102)

        for i in range(999):
            theitem = xbmcgui.ListItem()
            theitem.setLabel(str(i + 1))
            self.listcontrol.addItem(theitem)

        self.dlg.update(90)
        self.updateListing()
        self.dlg.close()
        self.getControl(105).setVisible(True)
        self.getControl(106).setVisible(False)
        self.setFocusId(102)
        self.log("prepareConfig return")

    def clearLabel(self, id=None):
        print 'clearLabel'
        if id:
            try:
                self.getControl(id).reset()
            except:
                pass
        else:
            for i in range(NUMBER_CHANNEL_TYPES):
                if i >= 7:
                    base = (120 + ((i + 1) * 10))
                    for n in range(10):
                        id = base + n
                        try:
                            self.getControl(id).reset()
                        except:
                            break

    def fillSources(self, type, source, path=None):
        self.log("fillSources")
        dlg = xbmcgui.Dialog()
        print source, type, path
        # Parse Source, return title, path
        try:
            if source == 'PVR':
                self.log("PVR")
                retval = dlg.browse(1, "Select File", "video", "", False,
                                    False, "pvr://")
                if len(retval) > 0:
                    return retval, retval
            elif source == 'HDhomerun':
                self.log("HDhomerun")
                xbmc.executebuiltin(
                    "Notification( %s, %s, %d, %s)" %
                    ("PseudoTV Lite", "Coming Soon", 4000, THUMB))
            elif source == 'Local Video':
                self.log("Local Video")
                retval = dlg.browse(
                    1, "Select File", "video",
                    ".avi|.mp4|.m4v|.3gp|.3g2|.f4v|.mov|.mkv|.flv|.ts|.m2ts|.strm",
                    False, False, "")
                if len(retval) > 0:
                    return retval, retval
            elif source == 'Local Music':
                self.log("Local Music")
                retval = dlg.browse(1, "Select File", "music",
                                    ".mp3|.flac|.mp4", False, False, "")
                if len(retval) > 0:
                    return retval, retval
            elif source == 'UPNP':
                self.log("UPNP")
                retval = dlg.browse(1, "Select File", "video", "", False,
                                    False, "upnp://")
                return retval
            elif source == 'Kodi Favourites':
                self.log("Kodi Favourites")
                select = selectDialog(self.FavouritesNameList,
                                      'Select Favourites')
                return self.FavouritesNameList[
                    select], self.FavouritesPathList[select]
            elif source == 'URL':
                self.log("URL")
                input = dlg.input('Enter URL', type=xbmcgui.INPUT_ALPHANUM)
                if len(input) > 0:
                    return input, input
            else:
                return
        except:
            xbmc.executebuiltin("Dialog.Close(busydialog)")
            buggalo.onExceptionRaised()

    def help(self):
        BaseURL = 'https://pseudotv-live-community.googlecode.com/svn/'
        type = self.getControl(109).getLabel()
        URL = BaseURL + "help_" + type.lower()
        self.log("help URL = " + URL)
        title = type + ' Channel Configuration Help'
        f = Open_URL(URL)
        text = f.read()
        showText(title, text)

    def updateListing(self, channel=-1):
        self.log("updateListing")
        start = 0
        end = 999

        if channel > -1:
            start = channel - 1
            end = channel

        for i in range(start, end):
            theitem = self.listcontrol.getListItem(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 == 0:
                newlabel = self.getSmartPlaylistName(chansetting1)
            elif chantype == 1 or chantype == 2 or chantype == 5 or chantype == 6:
                newlabel = chansetting1
            elif chantype == 3:
                newlabel = chansetting1 + " - TV"
            elif chantype == 4:
                newlabel = chansetting1 + " - Movies"
            elif chantype == 7:
                if chansetting1[-1] == '/' or chansetting1[-1] == '\\':
                    newlabel = os.path.split(chansetting1[:-1])[1]
                else:
                    newlabel = os.path.split(chansetting1)[1]
            elif chantype == 8:
                newlabel = channame + " - LiveTV"
            elif chantype == 9:
                newlabel = channame + " - InternetTV"

            theitem.setLabel2(newlabel)
        self.log("updateListing return")
示例#19
0
    def ImportChannel(self):
        self.log("ImportChannel")
        show_busy_dialog()
        self.chnlst = ChannelList()
        self.chantype = 9999
        self.setting1 = ""
        self.setting2 = ""
        self.setting3 = ""
        self.setting4 = ""
        self.channame = ""
        self.theitem = []
        self.itemlst = []
        ADDON_SETTINGS.loadSettings()

        for i in range(999):
            self.theitem.append(str(i + 1))
        self.updateListing()
        hide_busy_dialog()
        available = False
        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.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:
                    xbmc.executebuiltin(
                        "Notification( %s, %s, %d, %s)"
                        % ("PseudoTV Live", "Channel " + str(self.channel) + " already in use", 1000, THUMB)
                    )
            else:
                available = True
        self.log("chantype = " + str(self.chantype))
示例#20
0
class Main:

    def __init__(self):
        self._parse_argv()
    
    def log(self, msg, level = xbmc.LOGDEBUG):
        log('capture: ' + msg, level)


    def _parse_argv(self):
        self.handle = None
        self.infos = []
        self.params = {" Label": None,
                       " Path": None,
                       " FileName": None,
                       " DBIDType": None,
                       " AddonName": None,
                       " AddonType": None,
                       " Description": None,
                       " isPlayable": None,
                       " isFolder": None}
        for arg in sys.argv:
            if arg == 'script.pseudotv.live':
                continue
            param = (arg.replace('"', '').replace("'", " ").replace("[ ", " ").replace(" ]", " ").replace("' ", "'").replace(" ' ", "'"))
            try:
                self.params[param.split("=")[0]] = "=".join(param.split("=")[1:]).strip()
            except:
                pass
                
        print self.params
        self.Label = self.params[" Label"] = self.params.get(" Label", "").strip()
        self.Path = self.params[" Path"] = self.params.get(" Path", "").strip()
        self.FileName = self.params[" FileName"] = self.params.get(" FileName", "").strip()
        self.DBIDType = self.params[" DBIDType"] = self.params.get(" DBIDType", "").strip()
        self.AddonName = self.params[" AddonName"] = self.params.get(" AddonName", "").strip()
        self.AddonType = self.params[" AddonType"] = self.params.get(" AddonType", "").strip()
        try:
            self.Description = self.params[" Description"] = self.params.get(" Description", "").strip()
        except:
            self.Description = self.params[" Description"] = self.params.get("Description", "").strip()
        self.isPlayable = self.params[" isPlayable"] = self.params.get(" isPlayable", "").strip()
        self.isFolder = self.params[" isFolder"] = self.params.get(" isFolder", "").strip()
        # print 'self.params', self.Label, self.Path, self.FileName, self.DBIDType, self.AddonName, self.AddonType, self.Description, self.isPlayable, self.isFolder
        if self.AddonName:
            ADDON = xbmcaddon.Addon(id=self.AddonName)
            ADDON_ID = ADDON.getAddonInfo('id')
            self.AddonName = ADDON.getAddonInfo('name')
        self.ImportChannel()
        
        
    def ImportChannel(self):
        self.log("ImportChannel")
        show_busy_dialog()
        self.chnlst = ChannelList()
        self.chantype = 9999
        self.setting1 = ''
        self.setting2 = ''
        self.setting3 = ''
        self.setting4 = ''
        self.channame = ''
        self.theitem = []
        self.itemlst = []
        
        ADDON_SETTINGS.loadSettings()
        
        for i in range(999):
            self.theitem.append(str(i + 1))
        self.updateListing()
        hide_busy_dialog()
        available = False
        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.spotitube/?limit&mode=listyoutubeplaylist'):
                        self.chantype = 10
                        self.YTtype = 2
                    elif self.Path.lower().startswith(('plugin', 'http', 'rtmp', 'pvr')):
                        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':
                                self.chantype = 15
                    elif self.isFolder == 'True':
                        if self.DBIDType == 'tvshow':
                            self.chantype = 6
                        elif self.DBIDType == '':
                            self.chantype = 7                        
                    self.buildChannel()
                else:
                    xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % ("PseudoTV Live", "Channel "+str(self.channel)+" already in use", 1000, THUMB) )
            else:
                available = True
            
            
    def buildChannel(self):
        self.log("buildChannel, chantype = " + str(self.chantype))
        self.chnlst = ChannelList()
        self.addonDirectoryPath = []
        
        if self.chantype == 0:
            self.setting1 = xbmc.translatePath(self.Path)
            self.channame = self.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: 
            dname = self.Label
            xmltvFle = xmltvFile(listXMLTV())
            # try:
            self.channame, self.setting1 = self.chnlst.findZap2itID(dname, xmltvFle)
            # except:
                # return
            self.setting2 = self.Path
                
        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:
                YTstring = 'plugin://plugin.video.youtube/channel/'
            elif self.YTtype == 2:
                YTstring = 'plugin://plugin.video.spotitube/?limit&mode=listyoutubeplaylist&type=browse&url='
            
            self.setting1 = ((self.Path.lower()).replace(YTstring,'')).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
            
        self.saveSettings()
        if dlg.yesno("PseudoTV Live", 'Channel Successfully Added', 'Open Channel Manager?'):
            xbmc.executebuiltin("RunScript("+ADDON_PATH+"/config.py, %s)" %str(self.channel))
                
        
    def updateListing(self, channel = -1):
        self.log("updateListing")
        start = 0
        end = 999

        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 == 0:
                    newlabel = self.getSmartPlaylistName(chansetting1)
                elif chantype == 1 or chantype == 2 or chantype == 5 or chantype == 6:
                    newlabel = chansetting1
                elif chantype == 3:
                    newlabel = chansetting1 + " - TV"
                elif chantype == 4:
                    newlabel = chansetting1 + " - Movies"
                elif chantype == 7:
                    if chansetting1[-1] == '/' or chansetting1[-1] == '\\':
                        newlabel = os.path.split(chansetting1[:-1])[1]
                    else:
                        newlabel = os.path.split(chansetting1)[1]
                elif chantype == 8:
                    newlabel = channame + " - LiveTV"
                elif chantype == 9:
                    newlabel = channame + " - InternetTV"
                elif chantype == 10:
                    newlabel = channame + " - Youtube"            
                elif chantype == 11:
                    newlabel = channame + " - RSS"            
                elif chantype == 12:
                    newlabel = channame + " - Music"
                elif chantype == 13:
                    newlabel = channame + " - Music Videos"
                elif chantype == 14:
                    newlabel = channame + " - Exclusive"
                elif chantype == 15:
                    newlabel = channame + " - Plugin"
                elif chantype == 16:
                    newlabel = channame + " - UPNP"
                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 getSmartPlaylistName(self, fle):
        self.log("getSmartPlaylistName " + fle)
        fle = xbmc.translatePath(fle)

        try:
            xml = FileAccess.open(fle, "r")
        except:
            self.log('Unable to open smart playlist')
            return ''

        try:
            dom = parse(xml)
        except:
            xml.close()
            self.log("getSmartPlaylistName return unable to parse")
            return ''

        xml.close()

        try:
            plname = dom.getElementsByTagName('name')
            self.log("getSmartPlaylistName return " + plname[0].childNodes[0].nodeValue)
            return plname[0].childNodes[0].nodeValue
        except:
            self.playlist('Unable to find element name')

        self.log("getSmartPlaylistName 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"
        channame = "Channel_" + chan + "_rule_1_opt_1"

        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)
        ADDON_SETTINGS.setSetting("Channel_" + chan + "_rulecount", "2")
        ADDON_SETTINGS.setSetting("Channel_" + chan + "_rule_1_id", "1")
        ADDON_SETTINGS.setSetting(channame, self.channame)           
        ADDON_SETTINGS.setSetting("Channel_" + chan + "_rule_2_id", "12")        
        ADDON_SETTINGS.setSetting("Channel_" + chan + "_changed", "True")
        self.log("saveSettings return")
示例#21
0
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")
示例#22
0
class Main:
    def __init__(self):
        self._parse_argv()

    def log(self, msg, level=xbmc.LOGDEBUG):
        log('capture: ' + msg, level)

    def _parse_argv(self):
        self.handle = None
        self.infos = []
        self.params = {
            " Label": None,
            " Path": None,
            " FileName": None,
            " DBIDType": None,
            " AddonName": None,
            " AddonType": None,
            " Description": None,
            " isPlayable": None,
            " isFolder": None
        }
        for arg in sys.argv:
            if arg == 'script.pseudotv.live':
                continue
            param = (arg.replace('"', '').replace("'", " ").replace(
                "[ ", " ").replace(" ]", " ").replace("' ",
                                                      "'").replace(" ' ", "'"))
            try:
                self.params[param.split("=")[0]] = "=".join(
                    param.split("=")[1:]).strip()
            except:
                pass

        self.log("params = " + str(self.params))
        self.Label = self.params[" Label"] = self.params.get(" Label",
                                                             "").strip()
        self.Path = self.params[" Path"] = self.params.get(" Path", "").strip()
        self.FileName = self.params[" FileName"] = self.params.get(
            " FileName", "").strip()
        self.DBIDType = self.params[" DBIDType"] = self.params.get(
            " DBIDType", "").strip()
        self.AddonName = self.params[" AddonName"] = self.params.get(
            " AddonName", "").strip()
        self.AddonType = self.params[" AddonType"] = self.params.get(
            " AddonType", "").strip()

        try:
            self.Description = self.params[" Description"] = self.params.get(
                " Description", "").strip()
        except:
            self.Description = self.params[" Description"] = self.params.get(
                "Description", "").strip()

        self.isPlayable = self.params[" isPlayable"] = self.params.get(
            " isPlayable", "").strip()
        self.isFolder = self.params[" isFolder"] = self.params.get(
            " isFolder", "").strip()

        if self.AddonName:
            ADDON = xbmcaddon.Addon(id=self.AddonName)
            ADDON_ID = ADDON.getAddonInfo('id')
            self.AddonName = ADDON.getAddonInfo('name')
        self.chnlst = ChannelList()
        self.Label = self.chnlst.CleanLabels(self.Label)
        self.Description = self.chnlst.CleanLabels(self.Description)
        self.AddonName = self.chnlst.CleanLabels(self.AddonName)
        self.ImportChannel()

    def ImportChannel(self):
        self.log("ImportChannel")
        show_busy_dialog()
        self.chnlst = ChannelList()
        self.chantype = 9999
        self.setting1 = ''
        self.setting2 = ''
        self.setting3 = ''
        self.setting4 = ''
        self.channame = ''
        self.theitem = []
        self.itemlst = []
        ADDON_SETTINGS.loadSettings()

        for i in range(999):
            self.theitem.append(str(i + 1))
        self.updateListing()
        hide_busy_dialog()
        available = False
        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.spotitube/?limit&mode=listyoutubeplaylist'
                    ):
                        self.chantype = 10
                        self.YTtype = 2
                    elif self.Path.lower().startswith(
                        ('plugin', 'http', 'rtmp', 'pvr')):
                        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':
                                self.chantype = 15
                    elif self.isFolder == 'True':
                        if self.DBIDType == 'tvshow':
                            self.chantype = 6
                        elif self.DBIDType == '':
                            self.chantype = 7
                    self.buildChannel()
                else:
                    xbmc.executebuiltin(
                        "Notification( %s, %s, %d, %s)" %
                        ("PseudoTV Live", "Channel " + str(self.channel) +
                         " already in use", 1000, THUMB))
            else:
                available = True

    def buildChannel(self):
        self.log("buildChannel, chantype = " + str(self.chantype))
        self.chnlst = ChannelList()
        self.addonDirectoryPath = []

        if self.chantype == 0:
            self.setting1 = xbmc.translatePath(self.Path)
            self.channame = self.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:
            dname = self.Label
            xmltvFle = xmltvFile(listXMLTV())
            # try:
            self.channame, self.setting1 = self.chnlst.findZap2itID(
                dname, xmltvFle)
            # except:
            # return
            self.setting2 = self.Path

        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:
                YTstring = 'plugin://plugin.video.youtube/channel/'
            elif self.YTtype == 2:
                YTstring = 'plugin://plugin.video.spotitube/?limit&mode=listyoutubeplaylist&type=browse&url='

            self.setting1 = ((self.Path.lower()).replace(YTstring,
                                                         '')).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

        self.saveSettings()
        if dlg.yesno("PseudoTV Live", 'Channel Successfully Added',
                     'Open Channel Manager?'):
            xbmc.executebuiltin("RunScript(" + ADDON_PATH +
                                "/config.py, %s)" % str(self.channel))

    def updateListing(self, channel=-1):
        self.log("updateListing")
        start = 0
        end = 999

        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 == 0:
                    newlabel = self.getSmartPlaylistName(chansetting1)
                elif chantype == 1 or chantype == 2 or chantype == 5 or chantype == 6:
                    newlabel = chansetting1
                elif chantype == 3:
                    newlabel = chansetting1 + " - TV"
                elif chantype == 4:
                    newlabel = chansetting1 + " - Movies"
                elif chantype == 7:
                    if chansetting1[-1] == '/' or chansetting1[-1] == '\\':
                        newlabel = os.path.split(chansetting1[:-1])[1]
                    else:
                        newlabel = os.path.split(chansetting1)[1]
                elif chantype == 8:
                    newlabel = channame + " - LiveTV"
                elif chantype == 9:
                    newlabel = channame + " - InternetTV"
                elif chantype == 10:
                    newlabel = channame + " - Youtube"
                elif chantype == 11:
                    newlabel = channame + " - RSS"
                elif chantype == 12:
                    newlabel = channame + " - Music"
                elif chantype == 13:
                    newlabel = channame + " - Music Videos"
                elif chantype == 14:
                    newlabel = channame + " - Exclusive"
                elif chantype == 15:
                    newlabel = channame + " - Plugin"
                elif chantype == 16:
                    newlabel = channame + " - UPNP"
                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 getSmartPlaylistName(self, fle):
        self.log("getSmartPlaylistName " + fle)
        fle = xbmc.translatePath(fle)

        try:
            xml = FileAccess.open(fle, "r")
        except:
            self.log('Unable to open smart playlist')
            return ''

        try:
            dom = parse(xml)
        except:
            xml.close()
            self.log("getSmartPlaylistName return unable to parse")
            return ''

        xml.close()

        try:
            plname = dom.getElementsByTagName('name')
            self.log("getSmartPlaylistName return " +
                     plname[0].childNodes[0].nodeValue)
            return plname[0].childNodes[0].nodeValue
        except:
            self.playlist('Unable to find element name')

        self.log("getSmartPlaylistName 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"
        channame = "Channel_" + chan + "_rule_1_opt_1"

        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)
        ADDON_SETTINGS.setSetting("Channel_" + chan + "_rulecount", "2")
        ADDON_SETTINGS.setSetting("Channel_" + chan + "_rule_1_id", "1")
        ADDON_SETTINGS.setSetting(channame, self.channame)
        ADDON_SETTINGS.setSetting("Channel_" + chan + "_rule_2_id", "12")
        ADDON_SETTINGS.setSetting("Channel_" + chan + "_changed", "True")
        self.log("saveSettings return")
示例#23
0
    def buildChannel(self):
        self.log("buildChannel, chantype = " + str(self.chantype))
        self.chnlst = ChannelList()
        self.addonDirectoryPath = []

        if self.chantype == 0:
            self.setting1 = xbmc.translatePath(self.Path)
            self.channame = self.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:
            dname = self.Label
            xmltvFle = xmltvFile(listXMLTV())
            # try:
            self.channame, self.setting1 = self.chnlst.findZap2itID(
                dname, xmltvFle)
            # except:
            # return
            self.setting2 = self.Path

        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:
                YTstring = 'plugin://plugin.video.youtube/channel/'
            elif self.YTtype == 2:
                YTstring = 'plugin://plugin.video.spotitube/?limit&mode=listyoutubeplaylist&type=browse&url='

            self.setting1 = ((self.Path.lower()).replace(YTstring,
                                                         '')).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

        self.saveSettings()
        if dlg.yesno("PseudoTV Live", 'Channel Successfully Added',
                     'Open Channel Manager?'):
            xbmc.executebuiltin("RunScript(" + ADDON_PATH +
                                "/config.py, %s)" % str(self.channel))
示例#24
0
 def ImportChannel(self):
     self.log("ImportChannel")
     show_busy_dialog()
     self.chnlst = ChannelList()
     self.chantype = 9999
     self.setting1 = ''
     self.setting2 = ''
     self.setting3 = ''
     self.setting4 = ''
     self.channame = ''
     self.theitem = []
     self.itemlst = []
     
     ADDON_SETTINGS.loadSettings()
     
     for i in range(999):
         self.theitem.append(str(i + 1))
     self.updateListing()
     hide_busy_dialog()
     available = False
     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.spotitube/?limit&mode=listyoutubeplaylist'):
                     self.chantype = 10
                     self.YTtype = 2
                 elif self.Path.lower().startswith(('plugin', 'http', 'rtmp', 'pvr')):
                     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':
                             self.chantype = 15
                 elif self.isFolder == 'True':
                     if self.DBIDType == 'tvshow':
                         self.chantype = 6
                     elif self.DBIDType == '':
                         self.chantype = 7                        
                 self.buildChannel()
             else:
                 xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % ("PseudoTV Live", "Channel "+str(self.channel)+" already in use", 1000, THUMB) )
         else:
             available = True
示例#25
0
def addBypass():
    chnlst = ChannelList()
    chnlst.fillPluginList()
    BYPASS_LST = matchMselect(chnlst.pluginPathList, mselectDialog(chnlst.pluginNameList, header='Enable Seeking for specified Plugins'))
    REAL_SETTINGS.setSetting("BYPASS_LST",str(BYPASS_LST))