예제 #1
0
    def prepareConfig(self):
        self.log("prepareConfig")
        self.showList = []
        self.getControl(105).setVisible(False)
        self.getControl(106).setVisible(False)
        xbmc.executebuiltin("ActivateWindow(busydialog)")
        chnlst = ChannelList()
        chnlst.fillTVInfo()
        chnlst.fillMovieInfo()
        self.mixedGenreList = chnlst.makeMixedList(chnlst.showGenreList,
                                                   chnlst.movieGenreList)
        self.networkList = chnlst.networkList
        self.studioList = chnlst.studioList
        self.showGenreList = chnlst.showGenreList
        self.movieGenreList = chnlst.movieGenreList

        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.updateListing()
        xbmc.executebuiltin("Dialog.Close(busydialog)")
        self.getControl(105).setVisible(True)
        self.getControl(106).setVisible(False)
        self.setFocusId(102)
        self.log("prepareConfig return")
예제 #2
0
    def prepareConfig(self):
        self.log("prepareConfig")
        self.showList = []
        self.getControl(105).setVisible(False)
        self.getControl(106).setVisible(False)
        BUSY.create()
        chnlst = ChannelList()
        chnlst.fillTVInfo()
        chnlst.fillMovieInfo()
        self.mixedGenreList = chnlst.makeMixedList(chnlst.showGenreList, chnlst.movieGenreList)
        self.networkList = chnlst.networkList
        self.studioList = chnlst.studioList
        self.showGenreList = chnlst.showGenreList
        self.movieGenreList = chnlst.movieGenreList

        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.updateListing()
        BUSY.close()
        self.getControl(105).setVisible(True)
        self.getControl(106).setVisible(False)
        self.setFocusId(102)
        self.log("prepareConfig return")
예제 #3
0
class Migrate:
    def __init__(self):
        self.chanlist = ChannelList()
        chkLowPower()
        
        
    def log(self, msg, level = xbmc.LOGDEBUG):
        log('Migrate: ' + msg, level)
          
   
    def onInit(self):
        self.log("onInit")
        
        
    def autoTune(self):
        self.log("autoTune")
        if REAL_SETTINGS.getSetting("Autotune") == "true" and REAL_SETTINGS.getSetting("Warning1") == "true":
            self.log('starting autoTune')
            Youtube = self.chanlist.youtube_player_ok()
            self.chanlist.background = True
            self.chanlist.makenewlists = True
            self.chanlist.forceReset = True
            self.myOverlay.setBackgroundStatus("Initializing: Autotuning",0,string2=" ")
            
            #Reserve channel check 
            channelNum = 1       
            if REAL_SETTINGS.getSetting("reserveChannels") == "true":
                self.log('autoTune, using reserve Channels')
                channelNum = 500
            baseNum = channelNum
            self.log('autoTune, Starting channelNum = ' + str(baseNum))
            
            # LiveTV - PVR
            if REAL_SETTINGS.getSetting("autoFindLivePVR") == "true":
                self.log("autoTune, adding Live PVR Channels")
                channelNum = baseNum
                PVRChannels = self.chanlist.getPVRChannels()
                for i in range(len(PVRChannels)):
                    try:
                        CHid = PVRChannels[i][0]
                        CHname = self.chanlist.cleanLabels(PVRChannels[i][1])
                        CHthmb = PVRChannels[i][2]
                        if REAL_SETTINGS.getSetting("respectChannels") == "true":
                            channelNum = self.chkChannelNum(int(CHid))
                        else:
                            channelNum = self.chkChannelNum(channelNum)
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "8")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", CHid)
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", self.chanlist.getPVRLink(i))
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_3", 'pvr')
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_id", "1")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_opt_1", CHname + ' PVR')
                        rulecnt = 1
                        if isLowPower() == True:
                            rulecnt = 2
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_2_id", "23")
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_2_opt_1", 'No')
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rulecount", "%s" %str(rulecnt))
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")  
                        self.myOverlay.setBackgroundStatus("Initializing: Autotuning adding PVR channels",string2=CHname,progress=int(channelNum*100//CHANNEL_LIMIT))
                    except:
                        pass
            
            # LiveTV - HDHomeRun           
            if REAL_SETTINGS.getSetting("autoFindLiveHDHR")  == "true":
                self.log("autoTune, adding Live HDHomeRun Channels")
                channelNum = baseNum
                self.chanlist.cached_readXMLTV = []
                HDHRChannels = self.chanlist.getHDHRChannels(True)
                for i in range(len(HDHRChannels)):
                    try:
                        CHid = HDHRChannels[i][0]
                        CHname = self.chanlist.cleanLabels(HDHRChannels[i][1])
                        link = HDHRChannels[i][4]
                        if REAL_SETTINGS.getSetting("respectChannels") == "true":
                            channelNum = self.chkChannelNum(int(CHid))
                        else:
                            channelNum = self.chkChannelNum(channelNum)
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "8")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", CHid)
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", link)
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_3", "hdhomerun")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_id", "1")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_opt_1", CHname + ' HDHR')
                        rulecnt = 1
                        if isLowPower() == True:
                            rulecnt = 2
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_2_id", "23")
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_2_opt_1", 'No')
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rulecount", "%s" %str(rulecnt))
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")     
                        self.myOverlay.setBackgroundStatus("Initializing: Autotuning adding HDHomeRun channels",string2=CHname,progress=int(channelNum*100//CHANNEL_LIMIT))
                    except Exception,e:
                        self.log("autoFindLiveHD 2, Failed! " + str(e))
             
            # LiveTV - USTVnow
            if REAL_SETTINGS.getSetting("autoFindUSTVNOW") == "true" and isUSTVnow() != False:
                self.log("autoTune, adding USTVnow Channels")
                channelNum = baseNum
                USTVChannels = self.chanlist.getUSTVChannels()
                for i in range(len(USTVChannels)):
                    try:
                        CHname, path, thumb = USTVChannels[i]
                        channelNum = self.chkChannelNum(channelNum)
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "8")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", CHname)
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", path)
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_3", "ustvnow")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_id", "1")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_opt_1", CHname + ' USTV')    
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_2_id", "13")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_2_opt_1", "2") 
                        rulecnt = 2
                        if isLowPower() == True:
                            rulecnt = 3
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_3_id", "23")
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_3_opt_1", 'No')
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rulecount", "%s" %str(rulecnt))
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")                 
                        self.myOverlay.setBackgroundStatus("Initializing: Autotuning adding USTVnow channels",string2=CHname,progress=int(channelNum*100//CHANNEL_LIMIT))
                    except:
                        pass

            # Custom Playlists
            if REAL_SETTINGS.getSetting("autoFindCustom") == "true":
                self.log("autoTune, adding Custom SmartPlaylists")
                channelNum = baseNum
                Music_path = 'special://profile/playlists/music'
                Mixed_path = 'special://profile/playlists/mixed'
                Video_path = 'special://profile/playlists/video'
                xsp_path = [Music_path, Mixed_path, Video_path]
                i = 0
                for path in xsp_path:
                    xspLst = self.chanlist.walk(path,['.xsp'])
                    for xsp in xspLst:
                        if xsp.endswith('.xsp') and len(re.findall("channel_",xsp)) != 0:
                            i += 1
                            if REAL_SETTINGS.getSetting("respectChannels") == "true":
                                channelNum = self.chkChannelNum(int((re.findall("channel_(\d+)", xsp))[0]))
                            else:
                                channelNum = self.chkChannelNum(channelNum)
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "0")
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", xbmc.translatePath(xsp))
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                            self.myOverlay.setBackgroundStatus("Initializing: Autotuning adding Custom SmartPlaylists",string2=uni(self.chanlist.getSmartPlaylistName(xsp)),progress=int(channelNum*100//CHANNEL_LIMIT))

            # Custom SuperFavs
            
            if REAL_SETTINGS.getSetting("autoFindSuperFav") == "true" :
                self.log("autoTune, adding Super Favourites")
                channelNum = baseNum
                plugin_details = self.chanlist.requestList('plugin://plugin.program.super.favourites')
                
                for i in plugin_details:
                    include = False
                    
                    try:
                        filetypes = re.search('"filetype" *: *"(.*?)"', i)
                        labels = re.search('"label" *: *"(.*?)"', i)
                        files = re.search('"file" *: *"(.*?)"', i)

                        #if core variables have info proceed
                        if filetypes and files and labels:
                            filetype = filetypes.group(1)
                            file = (files.group(1))
                            label = (labels.group(1))
                            
                            if label.lower() not in SF_FILTER:
                                if filetype == 'directory':
                                    if label.lower() in ['pseudotv']:
                                        plugin_details = self.chanlist.requestList(file)
                                        include = True
                                    
                                    elif label.lower().startswith('channel'):
                                        plugin_details = self.chanlist.requestList(file)
                                        include = True

                                    if include == True:
                                        channelNum = self.chkChannelNum(channelNum)         
                                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "15")
                                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", file)
                                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", "")
                                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_3", str(MEDIA_LIMIT))
                                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_4", "0")
                                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rulecount", "1")
                                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_id", "1")
                                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_opt_1", label)
                                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                                        self.myOverlay.setBackgroundStatus("Initializing: Autotuning adding Super Favourites",string2=label,progress=int(channelNum*100//CHANNEL_LIMIT))
                    except:
                        pass
                      
            #TV - Networks/Genres
            
            if (REAL_SETTINGS.getSetting("autoFindNetworks") == "true" or REAL_SETTINGS.getSetting("autoFindTVGenres") == "true"):
                self.log("autoTune, Searching for TV Channels")
                self.chanlist.fillTVInfo()

            # need to add check for auto find network channels
            
            if REAL_SETTINGS.getSetting("autoFindNetworks") == "true":
                self.log("autoTune, adding TV Networks")
                channelNum = baseNum
                for i in range(len(self.chanlist.networkList)):
                    channelNum = self.chkChannelNum(channelNum)
                    ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "1")
                    ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                    ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1",uni(self.chanlist.networkList[i]))
                    ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", "4")
                    ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                    self.myOverlay.setBackgroundStatus("Initializing: Autotuning adding TV Networks",string2=uni(self.chanlist.networkList[i]),progress=int(channelNum*100//CHANNEL_LIMIT))
            
            
            if REAL_SETTINGS.getSetting("autoFindTVGenres") == "true":
                self.log("autoTune, adding TV Genres")
                channelNum = baseNum
                for i in range(len(self.chanlist.showGenreList)):
                    if self.chanlist.showGenreList[i] != '':
                        channelNum = self.chkChannelNum(channelNum)
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "3")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", uni(self.chanlist.showGenreList[i]))
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", "4")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                        self.myOverlay.setBackgroundStatus("Initializing: Autotuning adding TV Genres",string2=uni(self.chanlist.showGenreList[i]),progress=int(channelNum*100//CHANNEL_LIMIT))
            
            
            if (REAL_SETTINGS.getSetting("autoFindStudios") == "true" or REAL_SETTINGS.getSetting("autoFindMovieGenres") == "true"):
                self.chanlist.fillMovieInfo()

            if REAL_SETTINGS.getSetting("autoFindStudios") == "true":
                self.log("autoTune, adding Movie Studios")
                channelNum = baseNum
                for i in range(len(self.chanlist.studioList)):
                    channelNum = self.chkChannelNum(channelNum)
                    ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "2")
                    ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                    ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", uni(self.chanlist.studioList[i]))
                    ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                    self.myOverlay.setBackgroundStatus("Initializing: Autotuning adding Movie Studios",string2=uni(self.chanlist.studioList[i]),progress=int(channelNum*100//CHANNEL_LIMIT))
                    
            
            if REAL_SETTINGS.getSetting("autoFindMovieGenres") == "true":
                self.log("autoTune, adding Movie Genres")
                channelNum = baseNum
                for i in range(len(self.chanlist.movieGenreList)):
                    if self.chanlist.movieGenreList[i] != '':
                        channelNum = self.chkChannelNum(channelNum)
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "4")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", uni(self.chanlist.movieGenreList[i]))
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                        self.myOverlay.setBackgroundStatus("Initializing: Autotuning adding Movie Genres",string2=uni(self.chanlist.movieGenreList[i]),progress=int(channelNum*100//CHANNEL_LIMIT))
                     
            if REAL_SETTINGS.getSetting("autoFindMixGenres") == "true":
                self.chanlist.fillMixedGenreInfo()
            
            if REAL_SETTINGS.getSetting("autoFindMixGenres") == "true":
                self.log("autoTune, adding Mixed Genres")
                channelNum = baseNum
                for i in range(len(self.chanlist.mixedGenreList)):
                    if self.chanlist.mixedGenreList[i] != '':
                        channelNum = self.chkChannelNum(channelNum)
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "5")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", uni(self.chanlist.mixedGenreList[i]))
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", "4")
                        ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                        self.myOverlay.setBackgroundStatus("Initializing: Autotuning adding Mixed Genres",string2=uni(self.chanlist.mixedGenreList[i]),progress=int(channelNum*100//CHANNEL_LIMIT))
            
            #recent movie/tv
             
            if REAL_SETTINGS.getSetting("autoFindRecent") == "true":
                self.log("autoTune, adding Recent TV/Movies")
                channelNum = baseNum
                channelNum = self.chkChannelNum(channelNum)
                TVflename = self.chanlist.createRecentlyAddedTV()
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", TVflename)
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rulecount", "3")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_id", "1")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_opt_1", "Recent TV")  
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_2_id", "12")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_3_id", "13")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_3_opt_1", "4")  
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                self.myOverlay.setBackgroundStatus("Initializing: Autotuning adding Recent TV",string2=' ')
                channelNum = self.chkChannelNum(channelNum)
                Movieflename = self.chanlist.createRecentlyAddedMovies()     
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", Movieflename)
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rulecount", "2")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_id", "1")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_opt_1", "Recent Movies")  
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_2_id", "13")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_2_opt_1", "4")  
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                self.myOverlay.setBackgroundStatus("Initializing: Autotuning adding Recent Movies",string2=' ')
               
            #3D movies
             
            if REAL_SETTINGS.getSetting("autoFind3DMovies") == "true":
                self.log("autoTune, adding 3D Movies")
                channelNum = baseNum
                if len(self.chanlist.movie3Dlist) >= MEDIA_LIMIT:
                    channelNum = self.chkChannelNum(channelNum)
                    ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "")
                    ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                    ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", "")
                    ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", "0")
                    ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                    self.myOverlay.setBackgroundStatus("Initializing: Autotuning adding 3D Movies",string2=' ')
                    
            #Music Genre
            if REAL_SETTINGS.getSetting("autoFindMusicGenres") == "true":
                self.log("autoTune, adding Music Genres")
                channelNum = baseNum
                self.chanlist.fillMusicInfo()
                for i in range(len(self.chanlist.musicGenreList)):
                    channelNum = self.chkChannelNum(channelNum)
                    ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "12")
                    ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                    ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", uni(self.chanlist.musicGenreList[i]))
                    ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", "4")
                    ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                    self.myOverlay.setBackgroundStatus("Initializing: Autotuning adding Music Genres",string2=uni(self.chanlist.musicGenreList[i]),progress=int(channelNum*100//CHANNEL_LIMIT))
            
            #Local Directory
            if REAL_SETTINGS.getSetting("autoFindVideosLocal") != "":
                self.log("autoTune, adding Local Videos")
                channelNum = baseNum 
                channelNum = self.chkChannelNum(channelNum)
                LocalVideo = str(REAL_SETTINGS.getSetting('autoFindVideosLocal'))  
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "7")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", "" +LocalVideo+ "")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_3", str(MEDIA_LIMIT))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_4", "1")     
                self.myOverlay.setBackgroundStatus("Initializing: Autotuning adding Local Directory",string2=self.chanlist.getChannelName(7, channelNum, LocalVideo))

            #Youtube - PseudoNetwork
            if REAL_SETTINGS.getSetting("autoFindCommunity_PseudoNetworks") == "true" and isCompanionInstalled() == True:
                self.log("autoTune, adding PseudoNetworks")
                channelNum = baseNum
                detail = uni(self.chanlist.requestList('plugin://plugin.video.pseudo.companion/?mode=3000&name=PseudoNetworks&previous=getOnlineMedia&url'))
                show_busy_dialog()
                for i in detail:
                    files = re.search('"file" *: *"(.*?)",', i)
                    filetypes = re.search('"filetype" *: *"(.*?)",', i)
                    labels = re.search('"label" *: *"(.*?)",', i)
                    if filetypes and labels and files:
                        filetype = filetypes.group(1)
                        name = self.chanlist.cleanLabels(labels.group(1))
                        file = (files.group(1).replace("\\\\", "\\"))
                        if filetype == 'directory':
                            channelNum = self.chkChannelNum(channelNum)
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "15")
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", file)
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", "")
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_3", str(MEDIA_LIMIT))
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_4", "0")
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rulecount", "1")
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_id", "1")
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_opt_1", name)  
                            ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                            self.myOverlay.setBackgroundStatus("Initializing: Autotuning adding PseudoNetworks",string2=name)
                    hide_busy_dialog()

            #Youtube - Seasonal
            
            if REAL_SETTINGS.getSetting("autoFindCommunity_Youtube_Seasonal") == "true":
                channelNum = baseNum
                today = datetime.datetime.now()
                month = today.strftime('%B')
                channelNum = self.chkChannelNum(channelNum)
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "10")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", month)
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", "31")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_3", str(MEDIA_LIMIT))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_4", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rulecount", "2")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_id", "1")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_opt_1", "Seasonal Channel")  
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_2_id", "13")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_2_opt_1", "168")  
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                self.myOverlay.setBackgroundStatus("Initializing: Autotuning adding Seasonal Youtube",string2=" ")

            # #Reserve channel clear old            
            if REAL_SETTINGS.getSetting("reserveChannels") == "true":
                self.clearReserved(baseNum)
            
            # reset auto tune settings        
            REAL_SETTINGS.setSetting('Autotune', "false")
            REAL_SETTINGS.setSetting('Warning1', "false") 
            REAL_SETTINGS.setSetting("autoFindCustom","false")
            REAL_SETTINGS.setSetting("autoFindSuperFav","false") 
            REAL_SETTINGS.setSetting('autoFindLivePVR', "false")
            REAL_SETTINGS.setSetting('autoFindLiveHDHR', "0")
            REAL_SETTINGS.setSetting('autoFindUSTVNOW', "false")  
            REAL_SETTINGS.setSetting("autoFindNetworks","false")
            REAL_SETTINGS.setSetting("autoFindStudios","false")
            REAL_SETTINGS.setSetting("autoFindTVGenres","false")
            REAL_SETTINGS.setSetting("autoFindMovieGenres","false")
            REAL_SETTINGS.setSetting("autoFindMixGenres","false")
            REAL_SETTINGS.setSetting("autoFind3DMovies","false")    
            REAL_SETTINGS.setSetting("autoFindRecent","false")      
            REAL_SETTINGS.setSetting("autoFindMusicGenres","false")
            REAL_SETTINGS.setSetting("autoFindVideosLocal","")
            REAL_SETTINGS.setSetting("autoFindCommunity_PseudoNetworks","false")  
            REAL_SETTINGS.setSetting("ForceChannelReset","true")
            ADDON_SETTINGS.setSetting('LastExitTime', str(int(time.time())))
            ADDON_SETTINGS.writeSettings()
            self.log('autoTune, return')
            self.myOverlay.setBackgroundStatus("Initializing: Autotuning Complete",string2=' ')
            return True
예제 #4
0
class ChannelConfig(xbmcgui.WindowXMLDialog):
    def __init__(self, *args, **kwargs):
        self.log("__init__")
        xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs)
        self.setCoordinateResolution(1)
        self.showingList = True
        self.channel = 0
        self.channel_type = 9999
        self.setting1 = ''
        self.setting2 = ''
        self.setting3 = ''
        self.setting4 = ''
        self.setting5 = ''
        self.setting6 = ''
        self.setting7 = ''
        self.setting8 = ''
        self.setting9 = ''
        self.doModal()
        self.log("__init__ return")


    def onInit(self):
        self.log("onInit")

        self.createDirectories()

        self.getControl(105).setVisible(False) # Channel Listing Control Group
        self.getControl(106).setVisible(False) # Channel Settings Control Group

        for i in range(NUMBER_CHANNEL_TYPES):
            self.getControl(120 + i).setVisible(False) # Channel Settings

        #migrate()
        self.prepareConfig()
        self.log("onInit return")


    def onFocus(self, controlId):
        pass


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

        if action == ACTION_PREVIOUS_MENU:
            if self.showingList == False:
                self.cancelChan()
                self.hideChanDetails()
            else:
                self.close()


    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("TV Time", "Preparing Channel Wizard")
        self.dlg.update(0, "Preparing Channel Wizard")
        self.chnlst = ChannelList()
        self.dlg.update(10, "Preparing Channel Wizard", "Loading TV Settings")
        self.chnlst.fillTVInfo()
        self.networkList = self.chnlst.networkList
        self.studioList = self.chnlst.studioList
        self.showGenreList = self.chnlst.showGenreList
        self.dlg.update(20, "Preparing Channel Wizard", "Loading Movie Settings")
        self.chnlst.fillMovieInfo()
        self.movieGenreList = self.chnlst.movieGenreList
        self.dlg.update(40, "Preparing Channel Wizard", "Loading Music Settings")
        self.chnlst.fillMusicInfo()
        self.musicGenreList = self.chnlst.musicGenreList        
        self.dlg.update(60, "Preparing Channel Wizard", "Loading Live Feed Settings")
        self.chnlst.fillFeedInfo()
        self.feedList = self.chnlst.feedList
        self.dlg.update(80, "Preparing Channel Wizard", "Loading Mixed Genre Settings")
        self.mixedGenreList = self.chnlst.makeMixedList(self.showGenreList, self.movieGenreList)

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

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

        self.log("self.networkList " + str(self.networkList))
        self.log("self.studioList " + str(self.studioList))
        self.log("self.showGenreList " + str(self.showGenreList))
        self.log("self.movieGenreList " + str(self.movieGenreList))
        self.log("self.musicGenreList " + str(self.musicGenreList))
        self.log("self.mixedGenreList " + str(self.mixedGenreList))

        self.resolutionList = []
        self.resolutionList.append('All')
        self.resolutionList.append('SD Only')
        self.resolutionList.append('720p or Higher')
        self.resolutionList.append('1080p Only')

        self.showseqList = []
        self.showseqList.append('1 Show')
        self.showseqList.append('2 Shows')
        self.showseqList.append('3 Shows')
        self.showseqList.append('4 Shows')
        self.showseqList.append('5 Shows')
        self.showseqList.append('6 Shows')
        self.showseqList.append('7 Shows')
        self.showseqList.append('8 Shows')
        self.showseqList.append('9 Shows')
        self.showseqList.append('10 Shows')

        self.movieseqList = []
        self.movieseqList.append('1 Movie')
        self.movieseqList.append('2 Movies')
        self.movieseqList.append('3 Movies')
        self.movieseqList.append('4 Movies')
        self.movieseqList.append('5 Movies')
        self.movieseqList.append('6 Movies')
        self.movieseqList.append('7 Movies')
        self.movieseqList.append('8 Movies')
        self.movieseqList.append('9 Movies')
        self.movieseqList.append('10 Movies')

        # check if settings2.xml file exists
        # read in channel playlists in video, music and mixed folders
        channelNum = 0
        for i in range(500):
            if os.path.exists(xbmc.translatePath('special://profile/playlists/video') + '/Channel_' + str(i + 1) + '.xsp'):
                channelNum = channelNum + 1
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", xbmc.translatePath('special://profile/playlists/video/') + 'Channel_' + str(i + 1) + '.xsp')
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_3", ChannelList().cleanString(ChannelList().getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/video') + '/Channel_' + str(i + 1) + '.xsp')))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_4", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_5", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_6", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_7", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_8", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_9", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_playlist", xbmc.translatePath('special://profile/playlists/video/') + 'Channel_' + str(i + 1) + '.xsp')
                #self.updateDialog(progressIndicator,"Auto Tune","Found " + str(self.channelList.getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/video') + '/Channel_' + str(i + 1) + '.xsp')),"")
            elif os.path.exists(xbmc.translatePath('special://profile/playlists/mixed') + '/Channel_' + str(i + 1) + '.xsp'):
                channelNum = channelNum + 1
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", xbmc.translatePath('special://profile/playlists/mixed/') + 'Channel_' + str(i + 1) + '.xsp')
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_3", ChannelList().cleanString(ChannelList().getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/mixed') + '/Channel_' + str(i + 1) + '.xsp')))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_4", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_5", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_6", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_7", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_8", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_9", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_playlist", xbmc.translatePath('special://profile/playlists/mixed/') + 'Channel_' + str(i + 1) + '.xsp')
                #self.updateDialog(progressIndicator,"Auto Tune","Found " + str(self.channelList.getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/mixed') + '/Channel_' + str(i + 1) + '.xsp')),"")
            elif os.path.exists(xbmc.translatePath('special://profile/playlists/music') + '/Channel_' + str(i + 1) + '.xsp'):
                channelNum = channelNum + 1
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", xbmc.translatePath('special://profile/playlists/music/') + 'Channel_' + str(i + 1) + '.xsp')
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_3", ChannelList().cleanString(ChannelList().getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/music') + '/Channel_' + str(i + 1) + '.xsp')))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_4", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_5", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_6", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_7", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_8", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_9", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_playlist", xbmc.translatePath('special://profile/playlists/music/') + 'Channel_' + str(i + 1) + '.xsp')
                #self.updateDialog(progressIndicator,"Auto Tune","Found " + str(self.channelList.getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/music') + '/Channel_' + str(i + 1) + '.xsp')),"")
        ADDON_SETTINGS.writeSettings()
                        
        """
        if not os.path.exists(xbmc.translatePath('special://profile/addon_data/' + ADDON_ID + '/settings2.xml')):
            # if not, load presets based on networklist and studiolist
            ChannelList().autoTune()
        else:
            if (REAL_SETTINGS.getSetting("autoFindNetworks") == "true" or 
                REAL_SETTINGS.getSetting("autoFindStudios") == "true" or 
                REAL_SETTINGS.getSetting("autoFindTVGenres") == "true" or 
                REAL_SETTINGS.getSetting("autoFindMovieGenres") == "true" or 
                REAL_SETTINGS.getSetting("autoFindMixGenres") == "true" or 
                REAL_SETTINGS.getSetting("autoFindTVShows") == "true" or
                REAL_SETTINGS.getSetting("autoFindMusicGenres") == "true"):
                self.log("autoTune")
                ChannelList().autoTune()
        """
        
        self.listcontrol = self.getControl(102)

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


        self.dlg.update(90, "Preparing Channel Wizard", "Loading Channel List")
        self.updateListing()
        self.dlg.close()
        self.getControl(105).setVisible(True) # Channel List
        self.getControl(106).setVisible(False) # Channel Settings
        self.setFocusId(102)
        self.log("prepareConfig return")


    def saveSettings(self):
        chantype = 9999
        chan = str(self.channel)
        
        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"
        setting5 = "Channel_" + chan + "_5"
        setting6 = "Channel_" + chan + "_6"
        setting7 = "Channel_" + chan + "_7"
        setting8 = "Channel_" + chan + "_8"
        setting9 = "Channel_" + chan + "_9"
        settingtime = "Channel_" + chan + "_time"
        playlist = "Channel_" + chan + "_playlist"
        totalDuration = "Channel_" + chan + "_totalDuration"
        
        if chantype == 0:
            ADDON_SETTINGS.setSetting(setting1, self.getControl(130).getLabel2())
            ADDON_SETTINGS.setSetting(setting2, '')
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(130).getLabel()))
            ADDON_SETTINGS.setSetting(setting4, '')
            ADDON_SETTINGS.setSetting(setting5, '')
            ADDON_SETTINGS.setSetting(setting6, '')
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            ADDON_SETTINGS.setSetting(settingtime, 0)
        elif chantype == 1:
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(142).getLabel()))
            if self.getControl(349).isSelected():
                ADDON_SETTINGS.setSetting(setting2, str(MODE_SERIAL))
            else:
                ADDON_SETTINGS.setSetting(setting2, '')                
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(142).getLabel()))
            if self.getControl(346).isSelected():
                ADDON_SETTINGS.setSetting(setting4, str(MODE_UNWATCHED))
            else:
                ADDON_SETTINGS.setSetting(setting4, 0)
            if self.getControl(347).isSelected():
                ADDON_SETTINGS.setSetting(setting5, str(MODE_NOSPECIALS))
            else:
                ADDON_SETTINGS.setSetting(setting5, 0)
            ADDON_SETTINGS.setSetting(setting6, self.getControl(343).getLabel())
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            if self.getControl(348).isSelected():
                ADDON_SETTINGS.setSetting(setting9, str(MODE_RANDOM_FILELISTS))
            else:
                ADDON_SETTINGS.setSetting(setting9, 0)
            ADDON_SETTINGS.setSetting(playlist, '')
            ADDON_SETTINGS.setSetting(totalDuration, '')
        elif chantype == 2:
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(152).getLabel()))
            ADDON_SETTINGS.setSetting(setting2, '')
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(152).getLabel()))
            if self.getControl(356).isSelected():
                ADDON_SETTINGS.setSetting(setting4, str(MODE_UNWATCHED))
            else:
                ADDON_SETTINGS.setSetting(setting4, 0)
            ADDON_SETTINGS.setSetting(setting5, '')
            ADDON_SETTINGS.setSetting(setting6, self.getControl(353).getLabel())
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            ADDON_SETTINGS.setSetting(playlist, '')
            ADDON_SETTINGS.setSetting(totalDuration, '')
        elif chantype == 3:
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(162).getLabel()))
            if self.getControl(369).isSelected():
                ADDON_SETTINGS.setSetting(setting2, str(MODE_SERIAL))
            else:
                ADDON_SETTINGS.setSetting(setting2, '')                
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(162).getLabel()) + ' TV')
            if self.getControl(366).isSelected():
                ADDON_SETTINGS.setSetting(setting4, str(MODE_UNWATCHED))
            else:
                ADDON_SETTINGS.setSetting(setting4, 0)
            if self.getControl(367).isSelected():
                ADDON_SETTINGS.setSetting(setting5, str(MODE_NOSPECIALS))
            else:
                ADDON_SETTINGS.setSetting(setting5, 0)
            ADDON_SETTINGS.setSetting(setting6, self.getControl(363).getLabel())
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            ADDON_SETTINGS.setSetting(playlist, '')
            ADDON_SETTINGS.setSetting(totalDuration, '')
        elif chantype == 4:
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(172).getLabel()))
            ADDON_SETTINGS.setSetting(setting2, '')
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(172).getLabel()) + ' Movies')
            if self.getControl(376).isSelected():
                ADDON_SETTINGS.setSetting(setting4, str(MODE_UNWATCHED))
            else:
                ADDON_SETTINGS.setSetting(setting4, 0)
            ADDON_SETTINGS.setSetting(setting5, self.getControl(373).getLabel())
            ADDON_SETTINGS.setSetting(setting6, '')
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            ADDON_SETTINGS.setSetting(playlist, '')
            ADDON_SETTINGS.setSetting(totalDuration, '')
        elif chantype == 5:
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(182).getLabel()))
            if self.getControl(389).isSelected():
                ADDON_SETTINGS.setSetting(setting2, str(MODE_SERIAL))
            else:
                ADDON_SETTINGS.setSetting(setting2, '')                
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(182).getLabel()) + ' Mix')
            if self.getControl(386).isSelected():
                ADDON_SETTINGS.setSetting(setting4, str(MODE_UNWATCHED))
            else:
                ADDON_SETTINGS.setSetting(setting4, 0)
            if self.getControl(387).isSelected():
                ADDON_SETTINGS.setSetting(setting5, str(MODE_NOSPECIALS))
            else:
                ADDON_SETTINGS.setSetting(setting5, 0)
            ADDON_SETTINGS.setSetting(setting6, self.getControl(383).getLabel())
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            ADDON_SETTINGS.setSetting(playlist, '')
            ADDON_SETTINGS.setSetting(totalDuration, '')
        elif chantype == 6:
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(192).getLabel()))
            if self.getControl(194).isSelected():
                ADDON_SETTINGS.setSetting(setting2, str(MODE_SERIAL))
            else:
                ADDON_SETTINGS.setSetting(setting2, '')                
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(192).getLabel()))
            if self.getControl(396).isSelected():
                ADDON_SETTINGS.setSetting(setting4, str(MODE_UNWATCHED))
            else:
                ADDON_SETTINGS.setSetting(setting4, 0)
            if self.getControl(397).isSelected():
                ADDON_SETTINGS.setSetting(setting5, str(MODE_NOSPECIALS))
            else:
                ADDON_SETTINGS.setSetting(setting5, 0)
            ADDON_SETTINGS.setSetting(setting6, self.getControl(393).getLabel())
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            ADDON_SETTINGS.setSetting(playlist, '')
            ADDON_SETTINGS.setSetting(totalDuration, '')
        if chantype == 7: # folder
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(200).getLabel2()))
            ADDON_SETTINGS.setSetting(setting2, '')
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(200).getLabel()))
            ADDON_SETTINGS.setSetting(setting4, '')
            ADDON_SETTINGS.setSetting(setting5, '')
            ADDON_SETTINGS.setSetting(setting6, '')
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            ADDON_SETTINGS.setSetting(playlist, '')
            ADDON_SETTINGS.setSetting(totalDuration, '')
        if chantype == 8: # music
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(212).getLabel()))
            ADDON_SETTINGS.setSetting(setting2, '')
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(212).getLabel()) + ' Music')
            ADDON_SETTINGS.setSetting(setting4, '')
            ADDON_SETTINGS.setSetting(setting5, '')
            ADDON_SETTINGS.setSetting(setting6, '')
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            ADDON_SETTINGS.setSetting(playlist, '')
            ADDON_SETTINGS.setSetting(totalDuration, '')
        if chantype == 9: # live
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(222).getLabel()))
            ADDON_SETTINGS.setSetting(setting2, '')
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(222).getLabel()))
            ADDON_SETTINGS.setSetting(setting4, '')
            ADDON_SETTINGS.setSetting(setting5, '')
            ADDON_SETTINGS.setSetting(setting6, '')
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            ADDON_SETTINGS.setSetting(playlist, '')
            ADDON_SETTINGS.setSetting(totalDuration, '')
        elif chantype == 9999:
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, '')
            ADDON_SETTINGS.setSetting(setting2, '')
            ADDON_SETTINGS.setSetting(setting3, '')
            ADDON_SETTINGS.setSetting(setting4, '')
            ADDON_SETTINGS.setSetting(setting5, '')
            ADDON_SETTINGS.setSetting(setting6, '')
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            ADDON_SETTINGS.setSetting(playlist, '')
            ADDON_SETTINGS.setSetting(totalDuration, '')

        # Check to see if the user changed anything
        set1 = ''
        set2 = ''
        set3 = ''
        set4 = ''
        set5 = ''
        set6 = ''
        set7 = ''
        set8 = ''
        set9 = ''

        try:
            set1 = ADDON_SETTINGS.getSetting(setting1)
            set2 = ADDON_SETTINGS.getSetting(setting2)
            set3 = ADDON_SETTINGS.getSetting(setting3)
            set4 = ADDON_SETTINGS.getSetting(setting4)
            set5 = ADDON_SETTINGS.getSetting(setting5)
            set6 = ADDON_SETTINGS.getSetting(setting6)
            set7 = ADDON_SETTINGS.getSetting(setting7)
            set8 = ADDON_SETTINGS.getSetting(setting8)
            set9 = ADDON_SETTINGS.getSetting(setting9)
        except:
            pass

        if chantype != self.channel_type or set1 != self.setting1 or set2 != self.setting2 or set3 != self.setting3 or set4 != self.setting4 or set5 != self.setting5 or set6 != self.setting6 or set7 != self.setting7 or set8 != self.setting8 or set9 != self.setting9:
            ADDON_SETTINGS.setSetting('Channel_' + chan + '_changed', 'true')

        ADDON_SETTINGS.writeSettings()
        # save total number of channels to settings.xml so we don't have to keep looping
        # through settings2.xml
        self.chnlst.setMaxChannels()
        
        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)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_5", self.setting5)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_6", self.setting6)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_7", self.setting7)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_8", self.setting8)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_9", self.setting9)


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

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

        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))

        if controlId == 102:
            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
        elif controlId == 110:
            self.changeChanType(self.channel, -1)
        elif controlId == 111:
            self.changeChanType(self.channel, 1)
        elif controlId == 112:
            self.saveSettings()
            self.hideChanDetails()
        elif controlId == 113:
            self.cancelChan()
            self.hideChanDetails()
        elif controlId == 130:
            dlg = xbmcgui.Dialog()
            retval = dlg.browse(1, "Channel " + str(self.channel) + " Playlist", "files", ".xsp", False, False, "special://videoplaylists/")

            if retval != "special://videoplaylists/":
                self.getControl(130).setLabel(self.chnlst.getSmartPlaylistName(retval), label2=retval)
        elif controlId == 140:
            self.changeListData(self.networkList, 142, -1)
        elif controlId == 141:
            self.changeListData(self.networkList, 142, 1)
        elif controlId == 150:
            self.changeListData(self.studioList, 152, -1)
        elif controlId == 151:
            self.changeListData(self.studioList, 152, 1)
        elif controlId == 160:
            self.changeListData(self.showGenreList, 162, -1)
        elif controlId == 161:
            self.changeListData(self.showGenreList, 162, 1)
        elif controlId == 170:
            self.changeListData(self.movieGenreList, 172, -1)
        elif controlId == 171:
            self.changeListData(self.movieGenreList, 172, 1)
        elif controlId == 180:
            self.changeListData(self.mixedGenreList, 182, -1)
        elif controlId == 181:
            self.changeListData(self.mixedGenreList, 182, 1)
        elif controlId == 190:
            self.changeListData(self.showList, 192, -1)
        elif controlId == 191:
            self.changeListData(self.showList, 192, 1)        
        elif controlId == 200: # Folder Channel
            dlg = xbmcgui.Dialog()
            # need to replace this with folder instead of file
            retval = dlg.browse(0, "Channel " + str(self.channel) + " Folder", "files", "*.*", False, False, "")
            if retval != "":
                # smb isn't supported at this time but it is here
                # as a placeholder if a solution can be found
                # for connecting to smb shares from python
                if retval.find("smb://") == -1:
                    ps = retval.split(os.sep)
                else:
                    ps = retval.split('/')
                chanName = ""
                for i in range(len(ps)-1):
                    chanName = ps[i]
                self.getControl(200).setLabel(chanName, label2=retval)        
        elif controlId == 210: # Music Based Channel
            self.changeListData(self.musicGenreList, 212, -1)
        elif controlId == 211:
            self.changeListData(self.musicGenreList, 212, 1)
        elif controlId == 220: # Live Channel
            self.changeListData(self.feedList, 222, -1)
        elif controlId == 221:
            self.changeListData(self.feedList, 222, 1)
        elif controlId == 344:
            self.changeListData(self.resolutionList, 343, -1)
        elif controlId == 345:
            self.changeListData(self.resolutionList, 343, 1)
        elif controlId == 354:
            self.changeListData(self.resolutionList, 353, -1)
        elif controlId == 355:
            self.changeListData(self.resolutionList, 353, 1)
        elif controlId == 364:
            self.changeListData(self.resolutionList, 363, -1)
        elif controlId == 365:
            self.changeListData(self.resolutionList, 363, 1)
        elif controlId == 374:
            self.changeListData(self.resolutionList, 373, -1)
        elif controlId == 375:
            self.changeListData(self.resolutionList, 373, 1)
        elif controlId == 384:
            self.changeListData(self.resolutionList, 383, -1)
        elif controlId == 385:
            self.changeListData(self.resolutionList, 383, 1)
        elif controlId == 394:
            self.changeListData(self.resolutionList, 393, -1)
        elif controlId == 395:
            self.changeListData(self.resolutionList, 393, 1)
        elif controlId == 489:
            self.changeListData(self.showseqList, 488, -1)
        elif controlId == 490:
            self.changeListData(self.showseqList, 488, 1)
        elif controlId == 492:
            self.changeListData(self.movieseqList, 491, -1)
        elif controlId == 493:
            self.changeListData(self.movieseqList, 491, 1)
            
        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(self.chnlst.uncleanString(thelist[index]))
        self.log("changeListData 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 = ''
            self.setting5 = ''
            self.setting6 = ''
            self.setting7 = ''
            self.setting8 = ''
            self.setting9 = ''

            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")
                self.setting5 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_5")
                self.setting6 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_6")
                self.setting7 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_7")
                self.setting8 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_8")
                self.setting9 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_9")
            except:
                pass

        for i in range(NUMBER_CHANNEL_TYPES):
            if i == chantype:
                self.getControl(120 + i).setVisible(True) # show settings
                self.getControl(110).controlDown(self.getControl(120 + ((i + 1) * 10)))

                try:
                    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(120 + i).setVisible(False) # hide settings

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


    def fillInDetails(self, channel):
        self.getControl(104).setLabel("Channel " + str(channel))
        chantype = 9999
        chansetting1 = ''
        chansetting2 = ''
        chansetting3 = ''
        chansetting4 = ''
        chansetting5 = ''
        chansetting6 = ''
        chansetting7 = ''
        chansetting8 = ''

        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")
            chansetting5 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_5")
            chansetting6 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_6")
            chansetting7 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_7")
            chansetting8 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_8")
            chansetting9 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_9")
        except:
            self.log("Unable to get some setting")

        if chansetting2 == "": chansetting2 = 0
        if chansetting4 == "": chansetting4 = 0
        if chansetting5 == "": chansetting5 = 0
        if chansetting6 == "": chansetting6 = "All"
        #if chansetting7 == "": chansetting7 = 0
        #if chansetting8 == "": chansetting8 = 0
        if chansetting9 == "": chansetting9 = 0
        
        self.getControl(109).setLabel(self.getChanTypeLabel(chantype))

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

            if len(plname) == 0:
                chansetting1 = ''

            self.getControl(130).setLabel(self.chnlst.getSmartPlaylistName(chansetting1), label2=chansetting1)
        elif chantype == 1:
            self.getControl(142).setLabel(self.findItemInList(self.networkList, chansetting1))
            self.getControl(343).setLabel(self.findItemInList(self.resolutionList, chansetting6))
            if chansetting2 <> "":
                self.getControl(349).setSelected(int(chansetting2) == int(MODE_SERIAL))
            if chansetting4 <> "":
                self.getControl(346).setSelected(int(chansetting4) == int(MODE_UNWATCHED))
            if chansetting5 <> "":
                self.getControl(347).setSelected(int(chansetting5) == int(MODE_NOSPECIALS))
            if chansetting9 <> "":
                self.getControl(348).setSelected(int(chansetting9) == int(MODE_RANDOM_FILELISTS))
        elif chantype == 2:
            self.getControl(152).setLabel(self.findItemInList(self.studioList, chansetting1))
            self.getControl(353).setLabel(self.findItemInList(self.resolutionList, chansetting6))
            if chansetting4 <> "":
                self.getControl(356).setSelected(int(chansetting4) == int(MODE_UNWATCHED))
        elif chantype == 3:
            self.getControl(162).setLabel(self.findItemInList(self.showGenreList, chansetting1))
            self.getControl(363).setLabel(self.findItemInList(self.resolutionList, chansetting6))
            if chansetting2 <> "":
                self.getControl(369).setSelected(int(chansetting2) == int(MODE_SERIAL))
            if chansetting4 <> "":
                self.getControl(366).setSelected(int(chansetting4) == int(MODE_UNWATCHED))
            if chansetting5 <> "":
                self.getControl(367).setSelected(int(chansetting5) == int(MODE_NOSPECIALS))
        elif chantype == 4:
            self.getControl(172).setLabel(self.findItemInList(self.movieGenreList, chansetting1))
            self.getControl(373).setLabel(self.findItemInList(self.resolutionList, chansetting6))
            if chansetting4 <> "":
                self.getControl(376).setSelected(int(chansetting4) == int(MODE_UNWATCHED))
        elif chantype == 5:
            self.getControl(182).setLabel(self.findItemInList(self.mixedGenreList, chansetting1))
            self.getControl(383).setLabel(self.findItemInList(self.resolutionList, chansetting6))
            if chansetting2 <> "":
                self.getControl(389).setSelected(int(chansetting2) == int(MODE_SERIAL))
            if chansetting4 <> "":
                self.getControl(386).setSelected(int(chansetting4) == int(MODE_UNWATCHED))
            if chansetting5 <> "":
                self.getControl(387).setSelected(int(chansetting5) == int(MODE_NOSPECIALS))
            self.getControl(488).setLabel(self.findItemInList(self.showseqList, chansetting7))
            self.getControl(491).setLabel(self.findItemInList(self.movieseqList, chansetting8))
        elif chantype == 6:
            self.getControl(192).setLabel(self.findItemInList(self.showList, chansetting1))
            self.getControl(393).setLabel(self.findItemInList(self.resolutionList, chansetting6))
            if chansetting4 <> "":
                self.getControl(396).setSelected(int(chansetting4) == int(MODE_UNWATCHED))
            if chansetting5 <> "":
                self.getControl(397).setSelected(int(chansetting5) == int(MODE_NOSPECIALS))
            self.getControl(194).setSelected(chansetting2 == str(MODE_SERIAL))
        elif chantype == 7: # folder
            fldname = chansetting3
            if len(fldname) == 0:
                chansetting1 = ''
            self.getControl(200).setLabel(fldname, label2=self.chnlst.uncleanString(chansetting1))
        elif chantype == 8: # music
            self.getControl(212).setLabel(self.findItemInList(self.musicGenreList, chansetting1))
        elif chantype == 9: # live
            self.getControl(222).setLabel(self.findItemInList(self.feedList, chansetting1))

        self.log("fillInDetails return")


    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 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 "Folder"
        elif chantype == 8:
            return "Music Genre"
        elif chantype == 9:
            return "Live"
        elif chantype == 9999:
            return "None"

        return ''


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

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

        for i in range(start, end):
            theitem = self.listcontrol.getListItem(i)
            chantype = 9999
            chansetting1 = ''
            chansetting2 = ''
            chansetting3 = ''
            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")
            except:
                pass

            if chantype == 0:
                newlabel = self.chnlst.getSmartPlaylistName(chansetting1)
            elif chantype == 1 or chantype == 2 or chantype == 5 or chantype == 6:
                newlabel = chansetting3
            elif chantype == 3:
                newlabel = chansetting3
            elif chantype == 4:
                newlabel = chansetting3
            elif chantype == 7:
                newlabel = self.chnlst.uncleanString(chansetting3)
            elif chantype == 8:
                newlabel = chansetting3
            elif chantype == 9:
                newlabel = self.chnlst.uncleanString(chansetting3)

            theitem.setLabel2(newlabel)

        self.log("updateListing return")


#####################################################
#####################################################
#
# Utility Functions
#
#####################################################
#####################################################

    def log(self, msg, level = xbmc.LOGDEBUG):
        xbmc.log('TV Time-' + msg, level)


    def createDirectories(self):
        self.log("createDirectories")
        # setup directories
        self.createDirectory(CHANNELS_LOC)
        self.createDirectory(GEN_CHAN_LOC)
        self.createDirectory(PRESTAGE_LOC)
        self.createDirectory(TEMP_LOC)
        self.createDirectory(META_LOC)
        self.createDirectory(FEED_LOC)
        

    def createDirectory(self, directory):
        if not os.path.exists(directory):
            try:
                os.makedirs(directory)
            except:
                self.Error('Unable to create the directory - ' + str(directory))
                return
예제 #5
0
class ConfigWindow(xbmcgui.WindowXMLDialog):
    def __init__(self, *args, **kwargs):
        self.log("__init__")
        xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs)
        self.setCoordinateResolution(1)
        self.showingList = True
        self.channel = 0
        self.channel_type = 9999
        self.setting1 = ''
        self.setting2 = ''
        ### TV TIME ###
        self.setting3 = ''
        self.setting4 = ''
        self.setting5 = ''
        self.setting6 = ''
        self.setting7 = ''
        self.setting8 = ''
        self.setting9 = ''        
        ###############
        self.doModal()
        self.log("__init__ return")


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


    def onInit(self):
        self.log("onInit")

        ### TV TIME ###
        self.getControl(105).setVisible(False) # Channel Listing Control Group
        self.getControl(106).setVisible(False) # Channel Settings Control Group        
        ###############

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

        migrate()
        self.prepareConfig()
        self.log("onInit return")


    def onFocus(self, controlId):
        pass


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

        if action == ACTION_PREVIOUS_MENU:
            if self.showingList == False:
                self.cancelChan()
                self.hideChanDetails()
            else:
                self.close()


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

        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"
        ### TV TIME ###
        setting3 = "Channel_" + chan + "_3" # Channel Name
        setting4 = "Channel_" + chan + "_4" # 
        setting5 = "Channel_" + chan + "_5"
        setting6 = "Channel_" + chan + "_6"
        setting7 = "Channel_" + chan + "_7"
        setting8 = "Channel_" + chan + "_8"
        setting9 = "Channel_" + chan + "_9"        
        ###############
        if chantype == 0:
            ADDON_SETTINGS.setSetting(setting1, self.getControl(130).getLabel2())
            ### TV TIME ###
            ADDON_SETTINGS.setSetting(setting2, '')
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(130).getLabel()))
            ADDON_SETTINGS.setSetting(setting4, '')
            ADDON_SETTINGS.setSetting(setting5, '')
            ADDON_SETTINGS.setSetting(setting6, '')
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            #ADDON_SETTINGS.setSetting(settingtime, 0)
            ###############
        elif chantype == 1:
            ADDON_SETTINGS.setSetting(setting1, self.getControl(142).getLabel())
            ### TV TIME ###
            if self.getControl(349).isSelected():
                ADDON_SETTINGS.setSetting(setting2, str(MODE_SERIAL))
            else:
                ADDON_SETTINGS.setSetting(setting2, '')                
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(142).getLabel()))
            if self.getControl(346).isSelected():
                ADDON_SETTINGS.setSetting(setting4, str(MODE_UNWATCHED))
            else:
                ADDON_SETTINGS.setSetting(setting4, 0)
            if self.getControl(347).isSelected():
                ADDON_SETTINGS.setSetting(setting5, str(MODE_NOSPECIALS))
            else:
                ADDON_SETTINGS.setSetting(setting5, 0)
            ADDON_SETTINGS.setSetting(setting6, self.getControl(343).getLabel())
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            if self.getControl(348).isSelected():
                ADDON_SETTINGS.setSetting(setting9, str(MODE_RANDOM_FILELISTS))
            else:
                ADDON_SETTINGS.setSetting(setting9, 0)
            #ADDON_SETTINGS.setSetting(settingtime, 0)
            #ADDON_SETTINGS.setSetting(playlist, '')
            #ADDON_SETTINGS.setSetting(totalDuration, '')
            ###############
        elif chantype == 2:
            ADDON_SETTINGS.setSetting(setting1, self.getControl(152).getLabel())
            ### TV TIME ###
            ADDON_SETTINGS.setSetting(setting2, '')
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(152).getLabel()))
            if self.getControl(356).isSelected():
                ADDON_SETTINGS.setSetting(setting4, str(MODE_UNWATCHED))
            else:
                ADDON_SETTINGS.setSetting(setting4, 0)
            ADDON_SETTINGS.setSetting(setting5, '')
            ADDON_SETTINGS.setSetting(setting6, self.getControl(353).getLabel())
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            #ADDON_SETTINGS.setSetting(settingtime, 0)
            #ADDON_SETTINGS.setSetting(playlist, '')
            #ADDON_SETTINGS.setSetting(totalDuration, '')
            ###############
        elif chantype == 3:
            ADDON_SETTINGS.setSetting(setting1, self.getControl(162).getLabel())
            ### TV TIME ###
            if self.getControl(369).isSelected():
                ADDON_SETTINGS.setSetting(setting2, str(MODE_SERIAL))
            else:
                ADDON_SETTINGS.setSetting(setting2, '')                
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(162).getLabel()) + ' TV')
            if self.getControl(366).isSelected():
                ADDON_SETTINGS.setSetting(setting4, str(MODE_UNWATCHED))
            else:
                ADDON_SETTINGS.setSetting(setting4, 0)
            if self.getControl(367).isSelected():
                ADDON_SETTINGS.setSetting(setting5, str(MODE_NOSPECIALS))
            else:
                ADDON_SETTINGS.setSetting(setting5, 0)
            ADDON_SETTINGS.setSetting(setting6, self.getControl(363).getLabel())
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            #ADDON_SETTINGS.setSetting(settingtime, 0)
            #ADDON_SETTINGS.setSetting(playlist, '')
            #ADDON_SETTINGS.setSetting(totalDuration, '')
            ###############            
        elif chantype == 4:
            ADDON_SETTINGS.setSetting(setting1, self.getControl(172).getLabel())
            ### TV TIME ###
            ADDON_SETTINGS.setSetting(setting2, '')
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(172).getLabel()) + ' Movies')
            if self.getControl(376).isSelected():
                ADDON_SETTINGS.setSetting(setting4, str(MODE_UNWATCHED))
            else:
                ADDON_SETTINGS.setSetting(setting4, 0)
            ADDON_SETTINGS.setSetting(setting5, '')
            ADDON_SETTINGS.setSetting(setting6, self.getControl(373).getLabel())
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            #ADDON_SETTINGS.setSetting(settingtime, 0)
            #ADDON_SETTINGS.setSetting(playlist, '')
            #ADDON_SETTINGS.setSetting(totalDuration, '')
            ###############            
        elif chantype == 5:
            ADDON_SETTINGS.setSetting(setting1, self.getControl(182).getLabel())
            ### TV TIME ###
            if self.getControl(389).isSelected():
                ADDON_SETTINGS.setSetting(setting2, str(MODE_SERIAL))
            else:
                ADDON_SETTINGS.setSetting(setting2, '')                
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(182).getLabel()) + ' Mix')
            if self.getControl(386).isSelected():
                ADDON_SETTINGS.setSetting(setting4, str(MODE_UNWATCHED))
            else:
                ADDON_SETTINGS.setSetting(setting4, 0)
            if self.getControl(387).isSelected():
                ADDON_SETTINGS.setSetting(setting5, str(MODE_NOSPECIALS))
            else:
                ADDON_SETTINGS.setSetting(setting5, 0)
            ADDON_SETTINGS.setSetting(setting6, self.getControl(383).getLabel())
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            #ADDON_SETTINGS.setSetting(settingtime, 0)
            #ADDON_SETTINGS.setSetting(playlist, '')
            #ADDON_SETTINGS.setSetting(totalDuration, '')
            ###############            
        elif chantype == 6:
            ADDON_SETTINGS.setSetting(setting1, self.getControl(192).getLabel())

            ### TV TIME ###
            #if self.getControl(194).isSelected():
            #    ADDON_SETTINGS.setSetting(setting2, str(MODE_SERIAL))
            if self.getControl(194).isSelected():
                ADDON_SETTINGS.setSetting(setting2, str(MODE_SERIAL))
            else:
                ADDON_SETTINGS.setSetting(setting2, '')                
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(192).getLabel()))
            if self.getControl(396).isSelected():
                ADDON_SETTINGS.setSetting(setting4, str(MODE_UNWATCHED))
            else:
                ADDON_SETTINGS.setSetting(setting4, 0)
            if self.getControl(397).isSelected():
                ADDON_SETTINGS.setSetting(setting5, str(MODE_NOSPECIALS))
            else:
                ADDON_SETTINGS.setSetting(setting5, 0)
            ADDON_SETTINGS.setSetting(setting6, self.getControl(393).getLabel())
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            #ADDON_SETTINGS.setSetting(settingtime, 0)
            #ADDON_SETTINGS.setSetting(playlist, '')
            #ADDON_SETTINGS.setSetting(totalDuration, '')
            ###############            
        ### TV TIME ###
        if chantype == 7: # folder
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(200).getLabel2()))
            ADDON_SETTINGS.setSetting(setting2, '')
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(200).getLabel()))
            ADDON_SETTINGS.setSetting(setting4, '')
            ADDON_SETTINGS.setSetting(setting5, '')
            ADDON_SETTINGS.setSetting(setting6, '')
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            #ADDON_SETTINGS.setSetting(settingtime, 0)
            #ADDON_SETTINGS.setSetting(playlist, '')
            #ADDON_SETTINGS.setSetting(totalDuration, '')
        if chantype == 8: # music
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(212).getLabel()))
            ADDON_SETTINGS.setSetting(setting2, '')
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(212).getLabel()) + ' Music')
            ADDON_SETTINGS.setSetting(setting4, '')
            ADDON_SETTINGS.setSetting(setting5, '')
            ADDON_SETTINGS.setSetting(setting6, '')
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            #ADDON_SETTINGS.setSetting(settingtime, 0)
            #ADDON_SETTINGS.setSetting(playlist, '')
            #ADDON_SETTINGS.setSetting(totalDuration, '')
        if chantype == 9: # live
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(222).getLabel()))
            ADDON_SETTINGS.setSetting(setting2, '')
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(222).getLabel()))
            ADDON_SETTINGS.setSetting(setting4, '')
            ADDON_SETTINGS.setSetting(setting5, '')
            ADDON_SETTINGS.setSetting(setting6, '')
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            #ADDON_SETTINGS.setSetting(settingtime, 0)
            #ADDON_SETTINGS.setSetting(playlist, '')
            #ADDON_SETTINGS.setSetting(totalDuration, '')        
        ###############            
        elif chantype == 9999:
            ADDON_SETTINGS.setSetting(setting1, '')
            ADDON_SETTINGS.setSetting(setting2, '')
            ### TV TIME ###
            ADDON_SETTINGS.setSetting(setting3, '')
            ADDON_SETTINGS.setSetting(setting4, '')
            ADDON_SETTINGS.setSetting(setting5, '')
            ADDON_SETTINGS.setSetting(setting6, '')
            ADDON_SETTINGS.setSetting(setting7, '')
            ADDON_SETTINGS.setSetting(setting8, '')
            ADDON_SETTINGS.setSetting(setting9, '')
            #ADDON_SETTINGS.setSetting(settingtime, 0)
            #ADDON_SETTINGS.setSetting(playlist, '')
            #ADDON_SETTINGS.setSetting(totalDuration, '')            
            ###############            

        # Check to see if the user changed anything
        set1 = ''
        set2 = ''
        ### TV TIME ###
        set3 = ''
        set4 = ''
        set5 = ''
        set6 = ''
        set7 = ''
        set8 = ''
        set9 = ''
        ###############            

        try:
            set1 = ADDON_SETTINGS.getSetting(setting1)
            set2 = ADDON_SETTINGS.getSetting(setting2)
            ### TV TIME ###
            set3 = ADDON_SETTINGS.getSetting(setting3)
            set4 = ADDON_SETTINGS.getSetting(setting4)
            set5 = ADDON_SETTINGS.getSetting(setting5)
            set6 = ADDON_SETTINGS.getSetting(setting6)
            set7 = ADDON_SETTINGS.getSetting(setting7)
            set8 = ADDON_SETTINGS.getSetting(setting8)
            set9 = ADDON_SETTINGS.getSetting(setting9)            
            ###############            
        except:
            pass


        ### TV TIME ###
        #if chantype != self.channel_type or set1 != self.setting1 or set2 != self.setting2:
        #    ADDON_SETTINGS.setSetting('Channel_' + chan + '_changed', 'True')
        if ( chantype != self.channel_type or 
            set1 != self.setting1 or 
            set2 != self.setting2 or 
            set3 != self.setting3 or 
            set4 != self.setting4 or 
            set5 != self.setting5 or 
            set6 != self.setting6 or 
            set7 != self.setting7 or 
            set8 != self.setting8 or 
            set9 != self.setting9
            ):
            ADDON_SETTINGS.setSetting('Channel_' + chan + '_changed', 'True')

        ADDON_SETTINGS.writeSettings()
        
        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)
        ### TV TIME ###
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_3", self.setting3)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_4", self.setting4)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_5", self.setting5)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_6", self.setting6)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_7", self.setting7)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_8", self.setting8)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_9", self.setting9)
        ###############
        

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

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

        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))

        if controlId == 102:
            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
        elif controlId == 110:
            self.changeChanType(self.channel, -1)
        elif controlId == 111:
            self.changeChanType(self.channel, 1)
        elif controlId == 112:
            self.saveSettings()
            self.hideChanDetails()
        elif controlId == 113:
            self.cancelChan()
            self.hideChanDetails()
        elif controlId == 130:
            dlg = xbmcgui.Dialog()
            retval = dlg.browse(1, "Channel " + str(self.channel) + " Playlist", "files", ".xsp", False, False, "special://videoplaylists/")

            if retval != "special://videoplaylists/":
                self.getControl(130).setLabel(self.getSmartPlaylistName(retval), label2=retval)
        elif controlId == 140:
            self.changeListData(self.networkList, 142, -1)
        elif controlId == 141:
            self.changeListData(self.networkList, 142, 1)
        elif controlId == 150:
            self.changeListData(self.studioList, 152, -1)
        elif controlId == 151:
            self.changeListData(self.studioList, 152, 1)
        elif controlId == 160:
            self.changeListData(self.showGenreList, 162, -1)
        elif controlId == 161:
            self.changeListData(self.showGenreList, 162, 1)
        elif controlId == 170:
            self.changeListData(self.movieGenreList, 172, -1)
        elif controlId == 171:
            self.changeListData(self.movieGenreList, 172, 1)
        elif controlId == 180:
            self.changeListData(self.mixedGenreList, 182, -1)
        elif controlId == 181:
            self.changeListData(self.mixedGenreList, 182, 1)
        elif controlId == 190:
            self.changeListData(self.showList, 192, -1)
        elif controlId == 191:
            self.changeListData(self.showList, 192, 1)
        ### TV TIME ###
        elif controlId == 200: # Folder Channel
            dlg = xbmcgui.Dialog()
            # need to replace this with folder instead of file
            retval = dlg.browse(0, "Channel " + str(self.channel) + " Folder", "files", "*.*", False, False, "")
            if retval != "":
                # smb isn't supported at this time but it is here
                # as a placeholder if a solution can be found
                # for connecting to smb shares from python
                if retval.find("smb://") == -1:
                    ps = retval.split(os.sep)
                else:
                    ps = retval.split('/')
                chanName = ""
                for i in range(len(ps)-1):
                    chanName = ps[i]
                self.getControl(200).setLabel(chanName, label2=retval)        
        elif controlId == 210: # Music Based Channel
            self.changeListData(self.musicGenreList, 212, -1)
        elif controlId == 211:
            self.changeListData(self.musicGenreList, 212, 1)
        elif controlId == 220: # Live Channel
            self.changeListData(self.feedList, 222, -1)
        elif controlId == 221:
            self.changeListData(self.feedList, 222, 1)
        elif controlId == 344:
            self.changeListData(self.resolutionList, 343, -1)
        elif controlId == 345:
            self.changeListData(self.resolutionList, 343, 1)
        elif controlId == 354:
            self.changeListData(self.resolutionList, 353, -1)
        elif controlId == 355:
            self.changeListData(self.resolutionList, 353, 1)
        elif controlId == 364:
            self.changeListData(self.resolutionList, 363, -1)
        elif controlId == 365:
            self.changeListData(self.resolutionList, 363, 1)
        elif controlId == 374:
            self.changeListData(self.resolutionList, 373, -1)
        elif controlId == 375:
            self.changeListData(self.resolutionList, 373, 1)
        elif controlId == 384:
            self.changeListData(self.resolutionList, 383, -1)
        elif controlId == 385:
            self.changeListData(self.resolutionList, 383, 1)
        elif controlId == 394:
            self.changeListData(self.resolutionList, 393, -1)
        elif controlId == 395:
            self.changeListData(self.resolutionList, 393, 1)
        elif controlId == 489:
            self.changeListData(self.showseqList, 488, -1)
        elif controlId == 490:
            self.changeListData(self.showseqList, 488, 1)
        elif controlId == 492:
            self.changeListData(self.movieseqList, 491, -1)
        elif controlId == 493:
            self.changeListData(self.movieseqList, 491, 1)        
        ###############
        
        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 = 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.playlisy('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 = ''
            ### TV TIME ###
            self.setting3 = ''
            self.setting4 = ''
            self.setting5 = ''
            self.setting6 = ''
            self.setting7 = ''
            self.setting8 = ''
            self.setting9 = ''            
            ###############

            try:
                self.setting1 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_1")
                self.setting2 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_2")
                ### TV TIME ###
                self.setting3 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_3")
                self.setting4 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_4")
                self.setting5 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_5")
                self.setting6 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_6")
                self.setting7 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_7")
                self.setting8 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_8")
                self.setting9 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_9")
                ###############
            except:
                pass

        for i in range(NUMBER_CHANNEL_TYPES):
            if i == chantype:
                self.getControl(120 + i).setVisible(True)
                self.getControl(110).controlDown(self.getControl(120 + ((i + 1) * 10)))

                try:
                    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(120 + i).setVisible(False)

        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 = ''
        ### TV TIME ###
        chansetting3 = ''
        chansetting4 = ''
        chansetting5 = ''
        chansetting6 = ''
        chansetting7 = ''
        chansetting8 = ''
        chansetting9 = ''
        ###############

        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")
            ### TV TIME ###
            chansetting3 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_3")
            chansetting4 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_4")
            chansetting5 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_5")
            chansetting6 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_6")
            chansetting7 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_7")
            chansetting8 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_8")
            chansetting9 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_9")
            ###############
        except:
            self.log("Unable to get some setting")

        ### TV TIME ###
        if chansetting2 == "": chansetting2 = 0
        if chansetting4 == "": chansetting4 = 0
        if chansetting5 == "": chansetting5 = 0
        if chansetting6 == "": chansetting6 = "All"
        #if chansetting7 == "": chansetting7 = 0
        #if chansetting8 == "": chansetting8 = 0
        if chansetting9 == "": chansetting9 = 0
        ###############

        self.getControl(109).setLabel(self.getChanTypeLabel(chantype))

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

            if len(plname) == 0:
                chansetting1 = ''

            self.getControl(130).setLabel(self.getSmartPlaylistName(chansetting1), label2=chansetting1)
        elif chantype == 1:
            self.getControl(142).setLabel(self.findItemInList(self.networkList, chansetting1))
            ### TV TIME ###
            self.getControl(343).setLabel(self.findItemInList(self.resolutionList, chansetting6))
            if chansetting2 <> "":
                self.getControl(349).setSelected(int(chansetting2) == int(MODE_SERIAL))
            if chansetting4 <> "":
                self.getControl(346).setSelected(int(chansetting4) == int(MODE_UNWATCHED))
            if chansetting5 <> "":
                self.getControl(347).setSelected(int(chansetting5) == int(MODE_NOSPECIALS))
            if chansetting9 <> "":
                self.getControl(348).setSelected(int(chansetting9) == int(MODE_RANDOM_FILELISTS))            
            ###############
        elif chantype == 2:
            self.getControl(152).setLabel(self.findItemInList(self.studioList, chansetting1))
            ### TV TIME ###
            self.getControl(353).setLabel(self.findItemInList(self.resolutionList, chansetting6))
            if chansetting4 <> "":
                self.getControl(356).setSelected(int(chansetting4) == int(MODE_UNWATCHED))            
            ###############
        elif chantype == 3:
            self.getControl(162).setLabel(self.findItemInList(self.showGenreList, chansetting1))
            ### TV TIME ###
            self.getControl(363).setLabel(self.findItemInList(self.resolutionList, chansetting6))
            if chansetting2 <> "":
                self.getControl(369).setSelected(int(chansetting2) == int(MODE_SERIAL))
            if chansetting4 <> "":
                self.getControl(366).setSelected(int(chansetting4) == int(MODE_UNWATCHED))
            if chansetting5 <> "":
                self.getControl(367).setSelected(int(chansetting5) == int(MODE_NOSPECIALS))            
            ###############
        elif chantype == 4:
            self.getControl(172).setLabel(self.findItemInList(self.movieGenreList, chansetting1))
            ### TV TIME ###
            self.getControl(373).setLabel(self.findItemInList(self.resolutionList, chansetting6))
            if chansetting4 <> "":
                self.getControl(376).setSelected(int(chansetting4) == int(MODE_UNWATCHED))            
            ###############
        elif chantype == 5:
            self.getControl(182).setLabel(self.findItemInList(self.mixedGenreList, chansetting1))
            ### TV TIME ###
            self.getControl(383).setLabel(self.findItemInList(self.resolutionList, chansetting6))
            if chansetting2 <> "":
                self.getControl(389).setSelected(int(chansetting2) == int(MODE_SERIAL))
            if chansetting4 <> "":
                self.getControl(386).setSelected(int(chansetting4) == int(MODE_UNWATCHED))
            if chansetting5 <> "":
                self.getControl(387).setSelected(int(chansetting5) == int(MODE_NOSPECIALS))
            self.getControl(488).setLabel(self.findItemInList(self.showseqList, chansetting7))
            self.getControl(491).setLabel(self.findItemInList(self.movieseqList, chansetting8))            
            ###############
        elif chantype == 6:
            self.getControl(192).setLabel(self.findItemInList(self.showList, chansetting1))
            self.getControl(194).setSelected(chansetting2 == str(MODE_SERIAL))
            ### TV TIME ###
            self.getControl(393).setLabel(self.findItemInList(self.resolutionList, chansetting6))
            if chansetting4 <> "":
                self.getControl(396).setSelected(int(chansetting4) == int(MODE_UNWATCHED))
            if chansetting5 <> "":
                self.getControl(397).setSelected(int(chansetting5) == int(MODE_NOSPECIALS))            
            ###############
        ### TV TIME ###
        elif chantype == 7: # folder
            fldname = chansetting3
            if len(fldname) == 0:
                chansetting1 = ''
            self.getControl(200).setLabel(fldname, label2=self.chnlst.uncleanString(chansetting1))
        elif chantype == 8: # music
            self.getControl(212).setLabel(self.findItemInList(self.musicGenreList, chansetting1))
        elif chantype == 9: # live
            self.getControl(222).setLabel(self.findItemInList(self.feedList, chansetting1))
        ###############

        self.log("fillInDetails return")


    def findItemInList(self, thelist, item):
        ### TV TIME ###
        #loitem = item.lower()
        item = item.decode('utf-8')
        loitem = item.lower()
        ###############
        
        for i in thelist:
            ### TV TIME ###
            #if loitem == i.lower():
            i = i.decode('utf-8')
            if loitem == i.lower():
            ###############
                return item
                
        if len(thelist) > 0:
            return thelist[0]
            
        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"
        ### TV TIME ###
        elif chantype == 7:
            return "Folder"
        elif chantype == 8:
            return "Music Genre"
        elif chantype == 9:
            return "Live"        
        ###############
        elif chantype == 9999:
            return "None"

        return ''

    def prepareConfig(self):
        self.log("prepareConfig")
        self.showList = []
        self.getControl(105).setVisible(False)
        self.getControl(106).setVisible(False)
        ### TV TIME ###
        #self.dlg = xbmcgui.DialogProgress()
        #self.dlg.create("PseudoTV", "Preparing Configuration")
        #self.dlg.update(1)
        #chnlst = ChannelList()
        #chnlst.fillTVInfo()
        #self.dlg.update(40)
        #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.dlg = xbmcgui.DialogProgress()
        self.dlg.create("TV Time", "Preparing Channel Wizard")
        self.dlg.update(0, "Preparing Channel Wizard")
        self.chnlst = ChannelList()
        self.dlg.update(10, "Preparing Channel Wizard", "Loading TV Settings")
        self.chnlst.fillTVInfo()
        self.networkList = self.chnlst.networkList
        self.studioList = self.chnlst.studioList
        self.showGenreList = self.chnlst.showGenreList
        self.dlg.update(20, "Preparing Channel Wizard", "Loading Movie Settings")
        self.chnlst.fillMovieInfo()
        self.movieGenreList = self.chnlst.movieGenreList
        self.dlg.update(40, "Preparing Channel Wizard", "Loading Music Settings")
        self.chnlst.fillMusicInfo()
        self.musicGenreList = self.chnlst.musicGenreList        
        self.dlg.update(60, "Preparing Channel Wizard", "Loading Live Feed Settings")
        self.chnlst.fillFeedInfo()
        self.feedList = self.chnlst.feedList
        self.dlg.update(80, "Preparing Channel Wizard", "Loading Mixed Genre Settings")
        self.mixedGenreList = self.chnlst.makeMixedList(self.showGenreList, self.movieGenreList)        
        ###############

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

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

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

        ### TV TIME ###
        self.resolutionList = []
        self.resolutionList.append('All')
        self.resolutionList.append('SD Only')
        self.resolutionList.append('720p or Higher')
        self.resolutionList.append('1080p Only')

        self.showseqList = []
        self.showseqList.append('1 Show')
        self.showseqList.append('2 Shows')
        self.showseqList.append('3 Shows')
        self.showseqList.append('4 Shows')
        self.showseqList.append('5 Shows')
        self.showseqList.append('6 Shows')
        self.showseqList.append('7 Shows')
        self.showseqList.append('8 Shows')
        self.showseqList.append('9 Shows')
        self.showseqList.append('10 Shows')

        self.movieseqList = []
        self.movieseqList.append('1 Movie')
        self.movieseqList.append('2 Movies')
        self.movieseqList.append('3 Movies')
        self.movieseqList.append('4 Movies')
        self.movieseqList.append('5 Movies')
        self.movieseqList.append('6 Movies')
        self.movieseqList.append('7 Movies')
        self.movieseqList.append('8 Movies')
        self.movieseqList.append('9 Movies')
        self.movieseqList.append('10 Movies')

        # check if settings2.xml file exists
        # read in channel playlists in video, music and mixed folders
        """
        channelNum = 0
        for i in range(500):
            if os.path.exists(xbmc.translatePath('special://profile/playlists/video') + '/Channel_' + str(i + 1) + '.xsp'):
                channelNum = channelNum + 1
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", xbmc.translatePath('special://profile/playlists/video/') + 'Channel_' + str(i + 1) + '.xsp')
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_3", ChannelList().cleanString(ChannelList().getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/video') + '/Channel_' + str(i + 1) + '.xsp')))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_4", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_5", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_6", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_7", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_8", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_9", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_playlist", xbmc.translatePath('special://profile/playlists/video/') + 'Channel_' + str(i + 1) + '.xsp')
                #self.updateDialog(progressIndicator,"Auto Tune","Found " + str(self.channelList.getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/video') + '/Channel_' + str(i + 1) + '.xsp')),"")
            elif os.path.exists(xbmc.translatePath('special://profile/playlists/mixed') + '/Channel_' + str(i + 1) + '.xsp'):
                channelNum = channelNum + 1
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", xbmc.translatePath('special://profile/playlists/mixed/') + 'Channel_' + str(i + 1) + '.xsp')
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_3", ChannelList().cleanString(ChannelList().getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/mixed') + '/Channel_' + str(i + 1) + '.xsp')))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_4", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_5", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_6", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_7", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_8", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_9", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_playlist", xbmc.translatePath('special://profile/playlists/mixed/') + 'Channel_' + str(i + 1) + '.xsp')
                #self.updateDialog(progressIndicator,"Auto Tune","Found " + str(self.channelList.getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/mixed') + '/Channel_' + str(i + 1) + '.xsp')),"")
            elif os.path.exists(xbmc.translatePath('special://profile/playlists/music') + '/Channel_' + str(i + 1) + '.xsp'):
                channelNum = channelNum + 1
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", xbmc.translatePath('special://profile/playlists/music/') + 'Channel_' + str(i + 1) + '.xsp')
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_3", ChannelList().cleanString(ChannelList().getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/music') + '/Channel_' + str(i + 1) + '.xsp')))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_4", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_5", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_6", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_7", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_8", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_9", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_playlist", xbmc.translatePath('special://profile/playlists/music/') + 'Channel_' + str(i + 1) + '.xsp')
                #self.updateDialog(progressIndicator,"Auto Tune","Found " + str(self.channelList.getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/music') + '/Channel_' + str(i + 1) + '.xsp')),"")
        ADDON_SETTINGS.writeSettings()
        """
        ###############

        ### TV TIME ###
        #self.dlg.update(90)
        self.dlg.update(90, "Preparing Channel Wizard", "Loading Channel List")
        ###############
        self.updateListing()
        self.dlg.close()
        self.getControl(105).setVisible(True)
        self.getControl(106).setVisible(False)
        self.setFocusId(102)
        self.log("prepareConfig return")


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

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

        for i in range(start, end):
            theitem = self.listcontrol.getListItem(i)
            chantype = 9999
            chansetting1 = ''
            chansetting2 = ''
            ### TV TIME ###
            chansetting3 = ''
            ###############
            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")
                ### TV TIME ###
                chansetting3 = ADDON_SETTINGS.getSetting("Channel_" + str(i + 1) + "_3")
                ###############
            except:
                pass

            if chantype == 0:
                newlabel = self.getSmartPlaylistName(chansetting1)
            ### TV TIME ###
            #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 == 1 or 
                chantype == 2 or 
                chantype == 3 or 
                chantype == 4 or 
                chantype == 5 or 
                chantype == 6 or
                chantype == 8
                ):
                newlabel = chansetting3
            elif chantype == 7 or chantype == 9:
                newlabel = self.chnlst.uncleanString(chansetting3)
            ###############
            theitem.setLabel2(newlabel)

        self.log("updateListing return")
예제 #6
0
class ChannelConfig(xbmcgui.WindowXMLDialog):
    def __init__(self, *args, **kwargs):
        self.log("__init__")
        xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs)
        self.setCoordinateResolution(1)
        self.showingList = True
        self.channel = 0
        self.channel_type = 9999
        self.setting1 = ""
        self.setting2 = ""
        self.setting3 = ""
        self.setting4 = ""
        self.setting5 = ""
        self.setting6 = ""
        self.setting7 = ""
        self.setting8 = ""
        self.setting9 = ""
        self.doModal()
        self.log("__init__ return")

    def onInit(self):
        self.log("onInit")

        self.createDirectories()

        self.getControl(105).setVisible(False)  # Channel Listing Control Group
        self.getControl(106).setVisible(False)  # Channel Settings Control Group

        for i in range(NUMBER_CHANNEL_TYPES):
            self.getControl(120 + i).setVisible(False)  # Channel Settings

        # migrate()
        self.prepareConfig()
        self.log("onInit return")

    def onFocus(self, controlId):
        pass

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

        if action == ACTION_PREVIOUS_MENU:
            if self.showingList == False:
                self.cancelChan()
                self.hideChanDetails()
            else:
                self.close()

    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("TV Time", "Preparing Channel Wizard")
        self.dlg.update(0, "Preparing Channel Wizard")
        self.chnlst = ChannelList()
        self.dlg.update(10, "Preparing Channel Wizard", "Loading TV Settings")
        self.chnlst.fillTVInfo()
        self.networkList = self.chnlst.networkList
        self.studioList = self.chnlst.studioList
        self.showGenreList = self.chnlst.showGenreList
        self.dlg.update(20, "Preparing Channel Wizard", "Loading Movie Settings")
        self.chnlst.fillMovieInfo()
        self.movieGenreList = self.chnlst.movieGenreList
        self.dlg.update(40, "Preparing Channel Wizard", "Loading Music Settings")
        self.chnlst.fillMusicInfo()
        self.musicGenreList = self.chnlst.musicGenreList
        self.dlg.update(60, "Preparing Channel Wizard", "Loading Live Feed Settings")
        self.chnlst.fillFeedInfo()
        self.feedList = self.chnlst.feedList
        self.dlg.update(80, "Preparing Channel Wizard", "Loading Mixed Genre Settings")
        self.mixedGenreList = self.chnlst.makeMixedList(self.showGenreList, self.movieGenreList)

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

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

        self.log("self.networkList " + str(self.networkList))
        self.log("self.studioList " + str(self.studioList))
        self.log("self.showGenreList " + str(self.showGenreList))
        self.log("self.movieGenreList " + str(self.movieGenreList))
        self.log("self.musicGenreList " + str(self.musicGenreList))
        self.log("self.mixedGenreList " + str(self.mixedGenreList))

        self.resolutionList = []
        self.resolutionList.append("All")
        self.resolutionList.append("SD Only")
        self.resolutionList.append("720p or Higher")
        self.resolutionList.append("1080p Only")

        self.showseqList = []
        self.showseqList.append("1 Show")
        self.showseqList.append("2 Shows")
        self.showseqList.append("3 Shows")
        self.showseqList.append("4 Shows")
        self.showseqList.append("5 Shows")
        self.showseqList.append("6 Shows")
        self.showseqList.append("7 Shows")
        self.showseqList.append("8 Shows")
        self.showseqList.append("9 Shows")
        self.showseqList.append("10 Shows")

        self.movieseqList = []
        self.movieseqList.append("1 Movie")
        self.movieseqList.append("2 Movies")
        self.movieseqList.append("3 Movies")
        self.movieseqList.append("4 Movies")
        self.movieseqList.append("5 Movies")
        self.movieseqList.append("6 Movies")
        self.movieseqList.append("7 Movies")
        self.movieseqList.append("8 Movies")
        self.movieseqList.append("9 Movies")
        self.movieseqList.append("10 Movies")

        # check if settings2.xml file exists
        # read in channel playlists in video, music and mixed folders
        channelNum = 0
        for i in range(500):
            if os.path.exists(
                xbmc.translatePath("special://profile/playlists/video") + "/Channel_" + str(i + 1) + ".xsp"
            ):
                channelNum = channelNum + 1
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_1",
                    xbmc.translatePath("special://profile/playlists/video/") + "Channel_" + str(i + 1) + ".xsp",
                )
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", str(""))
                ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_3",
                    ChannelList().cleanString(
                        ChannelList().getSmartPlaylistName(
                            xbmc.translatePath("special://profile/playlists/video") + "/Channel_" + str(i + 1) + ".xsp"
                        )
                    ),
                )
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_4", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_5", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_6", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_7", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_8", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_9", str(""))
                ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_playlist",
                    xbmc.translatePath("special://profile/playlists/video/") + "Channel_" + str(i + 1) + ".xsp",
                )
                # self.updateDialog(progressIndicator,"Auto Tune","Found " + str(self.channelList.getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/video') + '/Channel_' + str(i + 1) + '.xsp')),"")
            elif os.path.exists(
                xbmc.translatePath("special://profile/playlists/mixed") + "/Channel_" + str(i + 1) + ".xsp"
            ):
                channelNum = channelNum + 1
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_1",
                    xbmc.translatePath("special://profile/playlists/mixed/") + "Channel_" + str(i + 1) + ".xsp",
                )
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", str(""))
                ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_3",
                    ChannelList().cleanString(
                        ChannelList().getSmartPlaylistName(
                            xbmc.translatePath("special://profile/playlists/mixed") + "/Channel_" + str(i + 1) + ".xsp"
                        )
                    ),
                )
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_4", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_5", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_6", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_7", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_8", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_9", str(""))
                ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_playlist",
                    xbmc.translatePath("special://profile/playlists/mixed/") + "Channel_" + str(i + 1) + ".xsp",
                )
                # self.updateDialog(progressIndicator,"Auto Tune","Found " + str(self.channelList.getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/mixed') + '/Channel_' + str(i + 1) + '.xsp')),"")
            elif os.path.exists(
                xbmc.translatePath("special://profile/playlists/music") + "/Channel_" + str(i + 1) + ".xsp"
            ):
                channelNum = channelNum + 1
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "0")
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_1",
                    xbmc.translatePath("special://profile/playlists/music/") + "Channel_" + str(i + 1) + ".xsp",
                )
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", str(""))
                ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_3",
                    ChannelList().cleanString(
                        ChannelList().getSmartPlaylistName(
                            xbmc.translatePath("special://profile/playlists/music") + "/Channel_" + str(i + 1) + ".xsp"
                        )
                    ),
                )
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_4", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_5", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_6", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_7", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_8", str(""))
                ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_9", str(""))
                ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_playlist",
                    xbmc.translatePath("special://profile/playlists/music/") + "Channel_" + str(i + 1) + ".xsp",
                )
                # self.updateDialog(progressIndicator,"Auto Tune","Found " + str(self.channelList.getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/music') + '/Channel_' + str(i + 1) + '.xsp')),"")
        ADDON_SETTINGS.writeSettings()

        """
        if not os.path.exists(xbmc.translatePath('special://profile/addon_data/' + ADDON_ID + '/settings2.xml')):
            # if not, load presets based on networklist and studiolist
            ChannelList().autoTune()
        else:
            if (REAL_SETTINGS.getSetting("autoFindNetworks") == "true" or 
                REAL_SETTINGS.getSetting("autoFindStudios") == "true" or 
                REAL_SETTINGS.getSetting("autoFindTVGenres") == "true" or 
                REAL_SETTINGS.getSetting("autoFindMovieGenres") == "true" or 
                REAL_SETTINGS.getSetting("autoFindMixGenres") == "true" or 
                REAL_SETTINGS.getSetting("autoFindTVShows") == "true" or
                REAL_SETTINGS.getSetting("autoFindMusicGenres") == "true"):
                self.log("autoTune")
                ChannelList().autoTune()
        """

        self.listcontrol = self.getControl(102)

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

        self.dlg.update(90, "Preparing Channel Wizard", "Loading Channel List")
        self.updateListing()
        self.dlg.close()
        self.getControl(105).setVisible(True)  # Channel List
        self.getControl(106).setVisible(False)  # Channel Settings
        self.setFocusId(102)
        self.log("prepareConfig return")

    def saveSettings(self):
        chantype = 9999
        chan = str(self.channel)

        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"
        setting5 = "Channel_" + chan + "_5"
        setting6 = "Channel_" + chan + "_6"
        setting7 = "Channel_" + chan + "_7"
        setting8 = "Channel_" + chan + "_8"
        setting9 = "Channel_" + chan + "_9"
        settingtime = "Channel_" + chan + "_time"
        playlist = "Channel_" + chan + "_playlist"
        totalDuration = "Channel_" + chan + "_totalDuration"

        if chantype == 0:
            ADDON_SETTINGS.setSetting(setting1, self.getControl(130).getLabel2())
            ADDON_SETTINGS.setSetting(setting2, "")
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(130).getLabel()))
            ADDON_SETTINGS.setSetting(setting4, "")
            ADDON_SETTINGS.setSetting(setting5, "")
            ADDON_SETTINGS.setSetting(setting6, "")
            ADDON_SETTINGS.setSetting(setting7, "")
            ADDON_SETTINGS.setSetting(setting8, "")
            ADDON_SETTINGS.setSetting(setting9, "")
            ADDON_SETTINGS.setSetting(settingtime, 0)
        elif chantype == 1:
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(142).getLabel()))
            if self.getControl(349).isSelected():
                ADDON_SETTINGS.setSetting(setting2, str(MODE_SERIAL))
            else:
                ADDON_SETTINGS.setSetting(setting2, "")
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(142).getLabel()))
            if self.getControl(346).isSelected():
                ADDON_SETTINGS.setSetting(setting4, str(MODE_UNWATCHED))
            else:
                ADDON_SETTINGS.setSetting(setting4, 0)
            if self.getControl(347).isSelected():
                ADDON_SETTINGS.setSetting(setting5, str(MODE_NOSPECIALS))
            else:
                ADDON_SETTINGS.setSetting(setting5, 0)
            ADDON_SETTINGS.setSetting(setting6, self.getControl(343).getLabel())
            ADDON_SETTINGS.setSetting(setting7, "")
            ADDON_SETTINGS.setSetting(setting8, "")
            if self.getControl(348).isSelected():
                ADDON_SETTINGS.setSetting(setting9, str(MODE_RANDOM_FILELISTS))
            else:
                ADDON_SETTINGS.setSetting(setting9, 0)
            ADDON_SETTINGS.setSetting(playlist, "")
            ADDON_SETTINGS.setSetting(totalDuration, "")
        elif chantype == 2:
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(152).getLabel()))
            ADDON_SETTINGS.setSetting(setting2, "")
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(152).getLabel()))
            if self.getControl(356).isSelected():
                ADDON_SETTINGS.setSetting(setting4, str(MODE_UNWATCHED))
            else:
                ADDON_SETTINGS.setSetting(setting4, 0)
            ADDON_SETTINGS.setSetting(setting5, "")
            ADDON_SETTINGS.setSetting(setting6, self.getControl(353).getLabel())
            ADDON_SETTINGS.setSetting(setting7, "")
            ADDON_SETTINGS.setSetting(setting8, "")
            ADDON_SETTINGS.setSetting(setting9, "")
            ADDON_SETTINGS.setSetting(playlist, "")
            ADDON_SETTINGS.setSetting(totalDuration, "")
        elif chantype == 3:
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(162).getLabel()))
            if self.getControl(369).isSelected():
                ADDON_SETTINGS.setSetting(setting2, str(MODE_SERIAL))
            else:
                ADDON_SETTINGS.setSetting(setting2, "")
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(162).getLabel()) + " TV")
            if self.getControl(366).isSelected():
                ADDON_SETTINGS.setSetting(setting4, str(MODE_UNWATCHED))
            else:
                ADDON_SETTINGS.setSetting(setting4, 0)
            if self.getControl(367).isSelected():
                ADDON_SETTINGS.setSetting(setting5, str(MODE_NOSPECIALS))
            else:
                ADDON_SETTINGS.setSetting(setting5, 0)
            ADDON_SETTINGS.setSetting(setting6, self.getControl(363).getLabel())
            ADDON_SETTINGS.setSetting(setting7, "")
            ADDON_SETTINGS.setSetting(setting8, "")
            ADDON_SETTINGS.setSetting(setting9, "")
            ADDON_SETTINGS.setSetting(playlist, "")
            ADDON_SETTINGS.setSetting(totalDuration, "")
        elif chantype == 4:
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(172).getLabel()))
            ADDON_SETTINGS.setSetting(setting2, "")
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(172).getLabel()) + " Movies")
            if self.getControl(376).isSelected():
                ADDON_SETTINGS.setSetting(setting4, str(MODE_UNWATCHED))
            else:
                ADDON_SETTINGS.setSetting(setting4, 0)
            ADDON_SETTINGS.setSetting(setting5, self.getControl(373).getLabel())
            ADDON_SETTINGS.setSetting(setting6, "")
            ADDON_SETTINGS.setSetting(setting7, "")
            ADDON_SETTINGS.setSetting(setting8, "")
            ADDON_SETTINGS.setSetting(setting9, "")
            ADDON_SETTINGS.setSetting(playlist, "")
            ADDON_SETTINGS.setSetting(totalDuration, "")
        elif chantype == 5:
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(182).getLabel()))
            if self.getControl(389).isSelected():
                ADDON_SETTINGS.setSetting(setting2, str(MODE_SERIAL))
            else:
                ADDON_SETTINGS.setSetting(setting2, "")
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(182).getLabel()) + " Mix")
            if self.getControl(386).isSelected():
                ADDON_SETTINGS.setSetting(setting4, str(MODE_UNWATCHED))
            else:
                ADDON_SETTINGS.setSetting(setting4, 0)
            if self.getControl(387).isSelected():
                ADDON_SETTINGS.setSetting(setting5, str(MODE_NOSPECIALS))
            else:
                ADDON_SETTINGS.setSetting(setting5, 0)
            ADDON_SETTINGS.setSetting(setting6, self.getControl(383).getLabel())
            ADDON_SETTINGS.setSetting(setting7, "")
            ADDON_SETTINGS.setSetting(setting8, "")
            ADDON_SETTINGS.setSetting(setting9, "")
            ADDON_SETTINGS.setSetting(playlist, "")
            ADDON_SETTINGS.setSetting(totalDuration, "")
        elif chantype == 6:
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(192).getLabel()))
            if self.getControl(194).isSelected():
                ADDON_SETTINGS.setSetting(setting2, str(MODE_SERIAL))
            else:
                ADDON_SETTINGS.setSetting(setting2, "")
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(192).getLabel()))
            if self.getControl(396).isSelected():
                ADDON_SETTINGS.setSetting(setting4, str(MODE_UNWATCHED))
            else:
                ADDON_SETTINGS.setSetting(setting4, 0)
            if self.getControl(397).isSelected():
                ADDON_SETTINGS.setSetting(setting5, str(MODE_NOSPECIALS))
            else:
                ADDON_SETTINGS.setSetting(setting5, 0)
            ADDON_SETTINGS.setSetting(setting6, self.getControl(393).getLabel())
            ADDON_SETTINGS.setSetting(setting7, "")
            ADDON_SETTINGS.setSetting(setting8, "")
            ADDON_SETTINGS.setSetting(setting9, "")
            ADDON_SETTINGS.setSetting(playlist, "")
            ADDON_SETTINGS.setSetting(totalDuration, "")
        if chantype == 7:  # folder
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(200).getLabel2()))
            ADDON_SETTINGS.setSetting(setting2, "")
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(200).getLabel()))
            ADDON_SETTINGS.setSetting(setting4, "")
            ADDON_SETTINGS.setSetting(setting5, "")
            ADDON_SETTINGS.setSetting(setting6, "")
            ADDON_SETTINGS.setSetting(setting7, "")
            ADDON_SETTINGS.setSetting(setting8, "")
            ADDON_SETTINGS.setSetting(setting9, "")
            ADDON_SETTINGS.setSetting(playlist, "")
            ADDON_SETTINGS.setSetting(totalDuration, "")
        if chantype == 8:  # music
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(212).getLabel()))
            ADDON_SETTINGS.setSetting(setting2, "")
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(212).getLabel()) + " Music")
            ADDON_SETTINGS.setSetting(setting4, "")
            ADDON_SETTINGS.setSetting(setting5, "")
            ADDON_SETTINGS.setSetting(setting6, "")
            ADDON_SETTINGS.setSetting(setting7, "")
            ADDON_SETTINGS.setSetting(setting8, "")
            ADDON_SETTINGS.setSetting(setting9, "")
            ADDON_SETTINGS.setSetting(playlist, "")
            ADDON_SETTINGS.setSetting(totalDuration, "")
        if chantype == 9:  # live
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, self.chnlst.cleanString(self.getControl(222).getLabel()))
            ADDON_SETTINGS.setSetting(setting2, "")
            ADDON_SETTINGS.setSetting(setting3, self.chnlst.cleanString(self.getControl(222).getLabel()))
            ADDON_SETTINGS.setSetting(setting4, "")
            ADDON_SETTINGS.setSetting(setting5, "")
            ADDON_SETTINGS.setSetting(setting6, "")
            ADDON_SETTINGS.setSetting(setting7, "")
            ADDON_SETTINGS.setSetting(setting8, "")
            ADDON_SETTINGS.setSetting(setting9, "")
            ADDON_SETTINGS.setSetting(playlist, "")
            ADDON_SETTINGS.setSetting(totalDuration, "")
        elif chantype == 9999:
            ADDON_SETTINGS.setSetting(settingtime, 0)
            ADDON_SETTINGS.setSetting(setting1, "")
            ADDON_SETTINGS.setSetting(setting2, "")
            ADDON_SETTINGS.setSetting(setting3, "")
            ADDON_SETTINGS.setSetting(setting4, "")
            ADDON_SETTINGS.setSetting(setting5, "")
            ADDON_SETTINGS.setSetting(setting6, "")
            ADDON_SETTINGS.setSetting(setting7, "")
            ADDON_SETTINGS.setSetting(setting8, "")
            ADDON_SETTINGS.setSetting(setting9, "")
            ADDON_SETTINGS.setSetting(playlist, "")
            ADDON_SETTINGS.setSetting(totalDuration, "")

        # Check to see if the user changed anything
        set1 = ""
        set2 = ""
        set3 = ""
        set4 = ""
        set5 = ""
        set6 = ""
        set7 = ""
        set8 = ""
        set9 = ""

        try:
            set1 = ADDON_SETTINGS.getSetting(setting1)
            set2 = ADDON_SETTINGS.getSetting(setting2)
            set3 = ADDON_SETTINGS.getSetting(setting3)
            set4 = ADDON_SETTINGS.getSetting(setting4)
            set5 = ADDON_SETTINGS.getSetting(setting5)
            set6 = ADDON_SETTINGS.getSetting(setting6)
            set7 = ADDON_SETTINGS.getSetting(setting7)
            set8 = ADDON_SETTINGS.getSetting(setting8)
            set9 = ADDON_SETTINGS.getSetting(setting9)
        except:
            pass

        if (
            chantype != self.channel_type
            or set1 != self.setting1
            or set2 != self.setting2
            or set3 != self.setting3
            or set4 != self.setting4
            or set5 != self.setting5
            or set6 != self.setting6
            or set7 != self.setting7
            or set8 != self.setting8
            or set9 != self.setting9
        ):
            ADDON_SETTINGS.setSetting("Channel_" + chan + "_changed", "true")

        ADDON_SETTINGS.writeSettings()
        # save total number of channels to settings.xml so we don't have to keep looping
        # through settings2.xml
        self.chnlst.setMaxChannels()

        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)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_5", self.setting5)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_6", self.setting6)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_7", self.setting7)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_8", self.setting8)
        ADDON_SETTINGS.setSetting("Channel_" + str(self.channel) + "_9", self.setting9)

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

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

        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))

        if controlId == 102:
            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
        elif controlId == 110:
            self.changeChanType(self.channel, -1)
        elif controlId == 111:
            self.changeChanType(self.channel, 1)
        elif controlId == 112:
            self.saveSettings()
            self.hideChanDetails()
        elif controlId == 113:
            self.cancelChan()
            self.hideChanDetails()
        elif controlId == 130:
            dlg = xbmcgui.Dialog()
            retval = dlg.browse(
                1,
                "Channel " + str(self.channel) + " Playlist",
                "files",
                ".xsp",
                False,
                False,
                "special://videoplaylists/",
            )

            if retval != "special://videoplaylists/":
                self.getControl(130).setLabel(self.chnlst.getSmartPlaylistName(retval), label2=retval)
        elif controlId == 140:
            self.changeListData(self.networkList, 142, -1)
        elif controlId == 141:
            self.changeListData(self.networkList, 142, 1)
        elif controlId == 150:
            self.changeListData(self.studioList, 152, -1)
        elif controlId == 151:
            self.changeListData(self.studioList, 152, 1)
        elif controlId == 160:
            self.changeListData(self.showGenreList, 162, -1)
        elif controlId == 161:
            self.changeListData(self.showGenreList, 162, 1)
        elif controlId == 170:
            self.changeListData(self.movieGenreList, 172, -1)
        elif controlId == 171:
            self.changeListData(self.movieGenreList, 172, 1)
        elif controlId == 180:
            self.changeListData(self.mixedGenreList, 182, -1)
        elif controlId == 181:
            self.changeListData(self.mixedGenreList, 182, 1)
        elif controlId == 190:
            self.changeListData(self.showList, 192, -1)
        elif controlId == 191:
            self.changeListData(self.showList, 192, 1)
        elif controlId == 200:  # Folder Channel
            dlg = xbmcgui.Dialog()
            # need to replace this with folder instead of file
            retval = dlg.browse(0, "Channel " + str(self.channel) + " Folder", "files", "*.*", False, False, "")
            if retval != "":
                # smb isn't supported at this time but it is here
                # as a placeholder if a solution can be found
                # for connecting to smb shares from python
                if retval.find("smb://") == -1:
                    ps = retval.split(os.sep)
                else:
                    ps = retval.split("/")
                chanName = ""
                for i in range(len(ps) - 1):
                    chanName = ps[i]
                self.getControl(200).setLabel(chanName, label2=retval)
        elif controlId == 210:  # Music Based Channel
            self.changeListData(self.musicGenreList, 212, -1)
        elif controlId == 211:
            self.changeListData(self.musicGenreList, 212, 1)
        elif controlId == 220:  # Live Channel
            self.changeListData(self.feedList, 222, -1)
        elif controlId == 221:
            self.changeListData(self.feedList, 222, 1)
        elif controlId == 344:
            self.changeListData(self.resolutionList, 343, -1)
        elif controlId == 345:
            self.changeListData(self.resolutionList, 343, 1)
        elif controlId == 354:
            self.changeListData(self.resolutionList, 353, -1)
        elif controlId == 355:
            self.changeListData(self.resolutionList, 353, 1)
        elif controlId == 364:
            self.changeListData(self.resolutionList, 363, -1)
        elif controlId == 365:
            self.changeListData(self.resolutionList, 363, 1)
        elif controlId == 374:
            self.changeListData(self.resolutionList, 373, -1)
        elif controlId == 375:
            self.changeListData(self.resolutionList, 373, 1)
        elif controlId == 384:
            self.changeListData(self.resolutionList, 383, -1)
        elif controlId == 385:
            self.changeListData(self.resolutionList, 383, 1)
        elif controlId == 394:
            self.changeListData(self.resolutionList, 393, -1)
        elif controlId == 395:
            self.changeListData(self.resolutionList, 393, 1)
        elif controlId == 489:
            self.changeListData(self.showseqList, 488, -1)
        elif controlId == 490:
            self.changeListData(self.showseqList, 488, 1)
        elif controlId == 492:
            self.changeListData(self.movieseqList, 491, -1)
        elif controlId == 493:
            self.changeListData(self.movieseqList, 491, 1)

        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(self.chnlst.uncleanString(thelist[index]))
        self.log("changeListData 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 = ""
            self.setting5 = ""
            self.setting6 = ""
            self.setting7 = ""
            self.setting8 = ""
            self.setting9 = ""

            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")
                self.setting5 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_5")
                self.setting6 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_6")
                self.setting7 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_7")
                self.setting8 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_8")
                self.setting9 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_9")
            except:
                pass

        for i in range(NUMBER_CHANNEL_TYPES):
            if i == chantype:
                self.getControl(120 + i).setVisible(True)  # show settings
                self.getControl(110).controlDown(self.getControl(120 + ((i + 1) * 10)))

                try:
                    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(120 + i).setVisible(False)  # hide settings

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

    def fillInDetails(self, channel):
        self.getControl(104).setLabel("Channel " + str(channel))
        chantype = 9999
        chansetting1 = ""
        chansetting2 = ""
        chansetting3 = ""
        chansetting4 = ""
        chansetting5 = ""
        chansetting6 = ""
        chansetting7 = ""
        chansetting8 = ""

        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")
            chansetting5 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_5")
            chansetting6 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_6")
            chansetting7 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_7")
            chansetting8 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_8")
            chansetting9 = ADDON_SETTINGS.getSetting("Channel_" + str(channel) + "_9")
        except:
            self.log("Unable to get some setting")

        if chansetting2 == "":
            chansetting2 = 0
        if chansetting4 == "":
            chansetting4 = 0
        if chansetting5 == "":
            chansetting5 = 0
        if chansetting6 == "":
            chansetting6 = "All"
        # if chansetting7 == "": chansetting7 = 0
        # if chansetting8 == "": chansetting8 = 0
        if chansetting9 == "":
            chansetting9 = 0

        self.getControl(109).setLabel(self.getChanTypeLabel(chantype))

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

            if len(plname) == 0:
                chansetting1 = ""

            self.getControl(130).setLabel(self.chnlst.getSmartPlaylistName(chansetting1), label2=chansetting1)
        elif chantype == 1:
            self.getControl(142).setLabel(self.findItemInList(self.networkList, chansetting1))
            self.getControl(343).setLabel(self.findItemInList(self.resolutionList, chansetting6))
            if chansetting2 <> "":
                self.getControl(349).setSelected(int(chansetting2) == int(MODE_SERIAL))
            if chansetting4 <> "":
                self.getControl(346).setSelected(int(chansetting4) == int(MODE_UNWATCHED))
            if chansetting5 <> "":
                self.getControl(347).setSelected(int(chansetting5) == int(MODE_NOSPECIALS))
            if chansetting9 <> "":
                self.getControl(348).setSelected(int(chansetting9) == int(MODE_RANDOM_FILELISTS))
        elif chantype == 2:
            self.getControl(152).setLabel(self.findItemInList(self.studioList, chansetting1))
            self.getControl(353).setLabel(self.findItemInList(self.resolutionList, chansetting6))
            if chansetting4 <> "":
                self.getControl(356).setSelected(int(chansetting4) == int(MODE_UNWATCHED))
        elif chantype == 3:
            self.getControl(162).setLabel(self.findItemInList(self.showGenreList, chansetting1))
            self.getControl(363).setLabel(self.findItemInList(self.resolutionList, chansetting6))
            if chansetting2 <> "":
                self.getControl(369).setSelected(int(chansetting2) == int(MODE_SERIAL))
            if chansetting4 <> "":
                self.getControl(366).setSelected(int(chansetting4) == int(MODE_UNWATCHED))
            if chansetting5 <> "":
                self.getControl(367).setSelected(int(chansetting5) == int(MODE_NOSPECIALS))
        elif chantype == 4:
            self.getControl(172).setLabel(self.findItemInList(self.movieGenreList, chansetting1))
            self.getControl(373).setLabel(self.findItemInList(self.resolutionList, chansetting6))
            if chansetting4 <> "":
                self.getControl(376).setSelected(int(chansetting4) == int(MODE_UNWATCHED))
        elif chantype == 5:
            self.getControl(182).setLabel(self.findItemInList(self.mixedGenreList, chansetting1))
            self.getControl(383).setLabel(self.findItemInList(self.resolutionList, chansetting6))
            if chansetting2 <> "":
                self.getControl(389).setSelected(int(chansetting2) == int(MODE_SERIAL))
            if chansetting4 <> "":
                self.getControl(386).setSelected(int(chansetting4) == int(MODE_UNWATCHED))
            if chansetting5 <> "":
                self.getControl(387).setSelected(int(chansetting5) == int(MODE_NOSPECIALS))
            self.getControl(488).setLabel(self.findItemInList(self.showseqList, chansetting7))
            self.getControl(491).setLabel(self.findItemInList(self.movieseqList, chansetting8))
        elif chantype == 6:
            self.getControl(192).setLabel(self.findItemInList(self.showList, chansetting1))
            self.getControl(393).setLabel(self.findItemInList(self.resolutionList, chansetting6))
            if chansetting4 <> "":
                self.getControl(396).setSelected(int(chansetting4) == int(MODE_UNWATCHED))
            if chansetting5 <> "":
                self.getControl(397).setSelected(int(chansetting5) == int(MODE_NOSPECIALS))
            self.getControl(194).setSelected(chansetting2 == str(MODE_SERIAL))
        elif chantype == 7:  # folder
            fldname = chansetting3
            if len(fldname) == 0:
                chansetting1 = ""
            self.getControl(200).setLabel(fldname, label2=self.chnlst.uncleanString(chansetting1))
        elif chantype == 8:  # music
            self.getControl(212).setLabel(self.findItemInList(self.musicGenreList, chansetting1))
        elif chantype == 9:  # live
            self.getControl(222).setLabel(self.findItemInList(self.feedList, chansetting1))

        self.log("fillInDetails return")

    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 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 "Folder"
        elif chantype == 8:
            return "Music Genre"
        elif chantype == 9:
            return "Live"
        elif chantype == 9999:
            return "None"

        return ""

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

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

        for i in range(start, end):
            theitem = self.listcontrol.getListItem(i)
            chantype = 9999
            chansetting1 = ""
            chansetting2 = ""
            chansetting3 = ""
            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")
            except:
                pass

            if chantype == 0:
                newlabel = self.chnlst.getSmartPlaylistName(chansetting1)
            elif chantype == 1 or chantype == 2 or chantype == 5 or chantype == 6:
                newlabel = chansetting3
            elif chantype == 3:
                newlabel = chansetting3
            elif chantype == 4:
                newlabel = chansetting3
            elif chantype == 7:
                newlabel = self.chnlst.uncleanString(chansetting3)
            elif chantype == 8:
                newlabel = chansetting3
            elif chantype == 9:
                newlabel = self.chnlst.uncleanString(chansetting3)

            theitem.setLabel2(newlabel)

        self.log("updateListing return")

    #####################################################
    #####################################################
    #
    # Utility Functions
    #
    #####################################################
    #####################################################

    def log(self, msg, level=xbmc.LOGDEBUG):
        xbmc.log("TV Time-" + msg, level)

    def createDirectories(self):
        self.log("createDirectories")
        # setup directories
        self.createDirectory(CHANNELS_LOC)
        self.createDirectory(GEN_CHAN_LOC)
        self.createDirectory(PRESTAGE_LOC)
        self.createDirectory(TEMP_LOC)
        self.createDirectory(META_LOC)
        self.createDirectory(FEED_LOC)

    def createDirectory(self, directory):
        if not os.path.exists(directory):
            try:
                os.makedirs(directory)
            except:
                self.Error("Unable to create the directory - " + str(directory))
                return