def JsonArtwork(self, mediapath, type, arttype, media='video'):
        self.log("JsonArtwork")
        arttype = arttype.replace('folder', 'poster').replace(
            'character', 'characterart').replace('logo', 'clearlogo').replace(
                'disc', 'discart')  #correct search names
        arttype = ((type + '.' + arttype if type == 'tvshow' else arttype))
        fletype = ''
        file_detail = []

        try:
            chanlist = ChannelList()
            json_query = uni(
                '{"jsonrpc":"2.0","method":"Files.GetDirectory","params":{"directory":"%s","media":"%s","properties":["art"]},"id":10}'
                % (chanlist.escapeDirJSON(mediapath), media))
            json_folder_detail = chanlist.sendJSON(json_query)
            file_detail = re.compile("{(.*?)}",
                                     re.DOTALL).findall(json_folder_detail)

            for f in file_detail:
                arttypes = re.search(('"%s" *: *"(.*?)"' % arttype), f)

                if arttypes != None and len(arttypes.group(1)) > 0:
                    fletype = (unquote(
                        (arttypes.group(1).split(','))[0])).replace(
                            'image://',
                            '').replace('.jpg/',
                                        '.jpg').replace('.png/', '.png')
                    break
        except Exception:
            buggalo.onExceptionRaised()
        self.log("JsonArtwork, fletype = " + fletype)
        return fletype
Example #2
0
 def JsonArtwork(self, mpath, media='video'):
     print ('JsonArtwork')
     file_detail = []
     try:
         chanlist = ChannelList()
         json_query = uni('{"jsonrpc":"2.0","method":"Files.GetDirectory","params":{"directory":"%s","media":"%s","properties":["art"]},"id":10}' % (chanlist.escapeDirJSON(mpath), media))
         json_folder_detail = chanlist.sendJSON(json_query)
         file_detail = re.compile( "{(.*?)}", re.DOTALL ).findall(json_folder_detail)
         print ('JsonArtwork - return')
     except:
         pass
     return file_detail
Example #3
0
 def JsonArtwork(self, mpath, media='video'):
     print ('JsonArtwork')
     file_detail = []
     try:
         chanlist = ChannelList()
         json_query = uni('{"jsonrpc":"2.0","method":"Files.GetDirectory","params":{"directory":"%s","media":"%s","properties":["art"]},"id":10}' % (chanlist.escapeDirJSON(mpath), media))
         json_folder_detail = chanlist.sendJSON(json_query)
         file_detail = re.compile( "{(.*?)}", re.DOTALL ).findall(json_folder_detail)
         print ('JsonArtwork - return')
     except:
         pass
     return file_detail
Example #4
0
    def initializeChannels(self):
        chanlist = ChannelList.ChannelList()
        chanlist.background = True
        chanlist.fillTVInfo(True)
        chanlist.fillMovieInfo(True)
        # Now create TV networks, followed by mixed genres, followed by TV genres, and finally movie genres
        currentchan = 1
        mixedlist = []

        for item in chanlist.showGenreList:
            curitem = item[0].lower()

            for a in chanlist.movieGenreList:
                if curitem == a[0].lower():
                    mixedlist.append([item[0], item[1], a[1]])
                    break

        mixedlist.sort(key=lambda x: x[1] + x[2], reverse=True)
        currentchan = self.initialAddChannels(chanlist.networkList, 1,
                                              currentchan)

        # Mixed genres
        if len(mixedlist) > 0:
            added = 0.0

            for item in mixedlist:
                if item[1] > 2 and item[2] > 1:
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(currentchan) + "_type", "5")
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(currentchan) + "_1", item[0])
                    added += 1.0
                    currentchan += 1
                    itemlow = item[0].lower()

                    # Remove that genre from the shows genre list
                    for i in range(len(chanlist.showGenreList)):
                        if itemlow == chanlist.showGenreList[i][0].lower():
                            chanlist.showGenreList.pop(i)
                            break

                    # Remove that genre from the movie genre list
                    for i in range(len(chanlist.movieGenreList)):
                        if itemlow == chanlist.movieGenreList[i][0].lower():
                            chanlist.movieGenreList.pop(i)
                            break

                    if added > 10:
                        break

        currentchan = self.initialAddChannels(chanlist.showGenreList, 3,
                                              currentchan)
        currentchan = self.initialAddChannels(chanlist.movieGenreList, 4,
                                              currentchan)

        if currentchan > 1:
            return True

        return False
class Artdownloader:

    def __init__(self):
        self.chanlist = ChannelList()
        self.fanarttv = fanarttv()
        self.tvdbAPI = tvdb.TVDB()
        self.tmdbAPI = tmdb.TMDB()  
        
        
    def log(self, msg, level = xbmc.LOGDEBUG):
        log('Artdownloader: ' + msg, level)

    
    def logDebug(self, msg, level = xbmc.LOGDEBUG):
        if isDebug() == True:
            log('Artdownloader: ' + msg, level)
    

    def getFallback_Arttype(self, arttype):
        arttype = arttype.lower()
        arttype = arttype.replace('landscape','fanart')
        arttype = arttype.replace('folder','poster')
        arttype = arttype.replace('clearart','logo')
        arttype = arttype.replace('character','logo')
        self.log("getFallback_Arttype = " + arttype)
        return arttype

        
    def searchDetails(self, file_detail, arttype):
        self.log("searchDetails")
        for f in file_detail:
            try:
                arttypes = re.search(('"%s" *: *"(.*?)"' % arttype), f)
                arttypes_fallback = re.search(('"%s" *: *"(.*?)"' % self.getFallback_Arttype(arttype)), f)
                if arttypes != None and len(arttypes.group(1)) > 0:
                    return (unquote(xbmc.translatePath((arttypes.group(1).split(','))[0]))).replace('image://','').replace('.jpg/','.jpg').replace('.png/','.png') 
                elif arttypes_fallback != None and len(arttypes_fallback.group(1)) > 0:
                    if (arttypes_fallback.group(1)).lower() ==  (self.getFallback_Arttype(arttype)).lower():
                        return (unquote(xbmc.translatePath((arttypes_fallback.group(1).split(','))[0]))).replace('image://','').replace('.jpg/','.jpg').replace('.png/','.png')
            except:
                pass
                
    
    def dbidArt(self, type, chname, mpath, dbid, arttypeEXT):
        self.log("dbidArt")
        file_detail = []
        try:
            if type == 'tvshow':
                json_query = ('{"jsonrpc":"2.0","method":"VideoLibrary.GetTVShowDetails","params":{"tvshowid":%s,"properties":["art","thumbnail","fanart"]},"id":1}' % dbid)
            elif type == 'movie':
                json_query = ('{"jsonrpc":"2.0","method":"VideoLibrary.GetMovieDetails","params":{"movieid":%s,"properties":["art","thumbnail","fanart"]},"id":1}' % dbid)
            arttype = (arttypeEXT.split(".")[0])
            json_folder_detail = self.chanlist.sendJSON(json_query)
            file_detail = re.compile( "{(.*?)}", re.DOTALL ).findall(json_folder_detail)
            return self.searchDetails(file_detail, arttype)
        except Exception,e:  
            self.log("dbidArt, Failed" + str(e), xbmc.LOGERROR)
Example #6
0
class Artdownloader:

    def __init__(self):
        self.chanlist = ChannelList()
        self.fanarttv = fanarttv()
        self.tvdbAPI = tvdb.TVDB(TVDB_API_KEY)
        self.tmdbAPI = tmdb.TMDB(TMDB_API_KEY)  
        
        
    def log(self, msg, level = xbmc.LOGDEBUG):
        log('Artdownloader: ' + msg, level)

    
    def logDebug(self, msg, level = xbmc.LOGDEBUG):
        if DEBUG == 'true':
            log('Artdownloader: ' + msg, level)
    

    def getFallback_Arttype(self, arttype):
        arttype = arttype.lower()
        arttype = arttype.replace('landscape','fanart')
        arttype = arttype.replace('folder','poster')
        return arttype

        
    def dbidArt(self, type, chname, mpath, dbid, arttypeEXT):
        self.log("dbidArt")
        file_detail = []
        arttypes = ''
        arttypes_fallback = ''
        try:
            if type == 'tvshow':
                json_query = ('{"jsonrpc":"2.0","method":"VideoLibrary.GetTVShowDetails","params":{"tvshowid":%s,"properties":["art","thumbnail","fanart"]},"id":1}' % dbid)
            elif type == 'movie':
                json_query = ('{"jsonrpc":"2.0","method":"VideoLibrary.GetMovieDetails","params":{"movieid":%s,"properties":["art","thumbnail","fanart"]},"id":1}' % dbid)
            else:
                return self.SetDefaultArt_NEW(chname, mpath, arttypeEXT)
            arttype = (arttypeEXT.split(".")[0])
            arttype_fallback = self.getFallback_Arttype(arttype)
            json_folder_detail = self.chanlist.sendJSON(json_query)
            file_detail = re.compile( "{(.*?)}", re.DOTALL ).findall(json_folder_detail)
            
            for f in file_detail:
                arttypes = re.search(('"%s" *: *"(.*?)"' % arttype), f)
                arttypes_fallback = re.search(('"%s" *: *"(.*?)"' % arttype_fallback), f)
                if arttypes != None and len(arttypes.group(1)) > 0:
                    return (unquote(xbmc.translatePath((arttypes.group(1).split(','))[0]))).replace('image://','').replace('.jpg/','.jpg').replace('.png/','.png') 
                
                elif arttypes_fallback and len(arttypes_fallback.group(1)) > 0:
                    if (arttypes_fallback.group(1)).lower() == arttype_fallback.lower():
                        SetImage_fallback = (unquote(xbmc.translatePath((arttypes_fallback.group(1).split(','))[0]))).replace('image://','').replace('.jpg/','.jpg').replace('.png/','.png')
            
            if not SetImage and SetImage_fallback:
                SetImage = SetImage_fallback
        except Exception,e:  
            self.log("script.pseudotv.live-Artdownloader: dbidArt Failed" + str(e), xbmc.LOGERROR)
Example #7
0
    def migrate(self):
        self.log("migrate")
        settingsFile = xbmc.translatePath(os.path.join(Globals.SETTINGS_LOC, 'settings2.xml'))    
        chanlist = ChannelList.ChannelList()
        chanlist.background = True
        chanlist.forceReset = True
        chanlist.createlist = True

        # If Autotune is enabled direct to autotuning
        if Globals.REAL_SETTINGS.getSetting("Autotune") == "true" and Globals.REAL_SETTINGS.getSetting("Warning1") == "true":
            self.log("autoTune, migrate")
            if self.autoTune():
                return True
    def JsonThumb(self, mediapath, media='video'):
        self.log("JsonThumb")
        file_detail = []
        thumbnail = ''
        try:
            chanlist = ChannelList()
            json_query = (
                '{jsonrpc":"2.0","method":"Files.GetDirectory","params":{"directory":"%s","properties":["thumbnail"]}, "id": 1}'
                % (chanlist.escapeDirJSON(mediapath)))
            json_folder_detail = chanlist.sendJSON(json_query)
            file_detail = re.compile("{(.*?)}",
                                     re.DOTALL).findall(json_folder_detail)

            for f in file_detail:
                thumbnails = re.search('"thumbnail" *: *"(.*?)"', f)
                if thumbnails != None and len(thumbnails.group(1)) > 0:
                    thumbnail = thumbnails.group(1)
                    break
        except Exception:
            buggalo.onExceptionRaised()
        self.log("JsonThumb, thumbnail = " + thumbnail)
        return thumbnail
Example #9
0
class Artdownloader:

    def __init__(self):
        self.chanlist = ChannelList()
        self.fanarttv = fanarttv()
        self.tvdbAPI = tvdb.TVDB()
        self.tmdbAPI = tmdb.TMDB()  
        
        
    def log(self, msg, level = xbmc.LOGDEBUG):
        log('Artdownloader: ' + msg, level)


    def getFallback_Arttype(self, arttype):
        arttype = arttype.lower()
        arttype = arttype.replace('landscape','fanart')
        arttype = arttype.replace('folder','poster')
        arttype = arttype.replace('thumb','poster')
        # arttype = arttype.replace('fanart','landscape')
        # arttype = arttype.replace('clearlogo','clearart')
        arttype = arttype.replace('clearart','clearlogo')
        arttype = arttype.replace('character','clearlogo')
        self.log("getFallback_Arttype = " + arttype)
        return arttype

        
    def FolderArt(self, type, chname, mpath, arttypeEXT):
        self.log("FolderArt, arttypeEXT = " + arttypeEXT)
        file_detail = []
        try:
            json_query = ('{"jsonrpc":"2.0","method":"Files.GetDirectory","params":{"directory":"%s","media":"pictures","properties":[]},"id":1}' % (mpath))
            json_folder_detail = self.chanlist.sendJSON(json_query)
            file_detail = re.compile("{(.*?)}", re.DOTALL ).findall(json_folder_detail)
            
            for f in file_detail:
                files = re.search('"file" *: *"(.*?)",', f)
                if files:
                    labels = re.search('"label" *: *"(.*?)",', f)
                    if len(labels.group(1)) > 0:
                        if (labels.group(1)).lower() == arttypeEXT.lower():
                            return (files.group(1).replace("\\\\", "\\"))
            return 'NA.png'
        except Exception,e:  
            self.log("FolderArt, Failed" + str(e), xbmc.LOGERROR)
            self.log(traceback.format_exc(), xbmc.LOGERROR)
            return 'NA.png'
Example #10
0
class Artdownloader:
    def __init__(self):
        self.chanlist = ChannelList()
        self.fanarttv = fanarttv()
        self.tvdbAPI = tvdb.TVDB()
        self.tmdbAPI = tmdb.TMDB()

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

    def getFallback_Arttype(self, arttype):
        arttype = arttype.lower()
        arttype = arttype.replace('landscape', 'fanart')
        arttype = arttype.replace('folder', 'poster')
        arttype = arttype.replace('thumb', 'poster')
        # arttype = arttype.replace('fanart','landscape')
        # arttype = arttype.replace('clearlogo','clearart')
        arttype = arttype.replace('clearart', 'clearlogo')
        arttype = arttype.replace('character', 'clearlogo')
        self.log("getFallback_Arttype = " + arttype)
        return arttype

    def FolderArt(self, type, chname, mpath, arttypeEXT):
        self.log("FolderArt, arttypeEXT = " + arttypeEXT)
        file_detail = []
        try:
            json_query = (
                '{"jsonrpc":"2.0","method":"Files.GetDirectory","params":{"directory":"%s","media":"pictures","properties":[]},"id":1}'
                % (mpath))
            json_folder_detail = self.chanlist.sendJSON(json_query)
            file_detail = re.compile("{(.*?)}",
                                     re.DOTALL).findall(json_folder_detail)

            for f in file_detail:
                files = re.search('"file" *: *"(.*?)",', f)
                if files:
                    labels = re.search('"label" *: *"(.*?)",', f)
                    if len(labels.group(1)) > 0:
                        if (labels.group(1)).lower() == arttypeEXT.lower():
                            return (files.group(1).replace("\\\\", "\\"))
            return 'NA.png'
        except Exception, e:
            self.log("FolderArt, Failed" + str(e), xbmc.LOGERROR)
            self.log(traceback.format_exc(), xbmc.LOGERROR)
            return 'NA.png'
Example #11
0
class Artdownloader:
    def __init__(self):
        self.chanlist = ChannelList()
        self.fanarttv = fanarttv()
        self.tvdbAPI = tvdb.TVDB()
        self.tmdbAPI = tmdb.TMDB()

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

    def getFallback_Arttype(self, arttype):
        arttype = arttype.lower()
        arttype = arttype.replace('landscape', 'fanart')
        arttype = arttype.replace('folder', 'poster')
        arttype = arttype.replace('thumb', 'poster')
        # arttype = arttype.replace('fanart','landscape')
        # arttype = arttype.replace('clearlogo','clearart')
        arttype = arttype.replace('clearart', 'clearlogo')
        arttype = arttype.replace('character', 'clearlogo')
        self.log("getFallback_Arttype = " + arttype)
        return arttype

    def dbidArt(self, type, chname, mpath, dbid, arttypeEXT):
        self.log("dbidArt")
        file_detail = []
        try:
            if type == 'tvshow':
                json_query = (
                    '{"jsonrpc":"2.0","method":"VideoLibrary.GetTVShowDetails","params":{"tvshowid":%s,"properties":["art","thumbnail","fanart"]},"id":1}'
                    % dbid)
            elif type == 'movie':
                json_query = (
                    '{"jsonrpc":"2.0","method":"VideoLibrary.GetMovieDetails","params":{"movieid":%s,"properties":["art","thumbnail","fanart"]},"id":1}'
                    % dbid)
            else:
                return 'NA.png'
            arttype = (arttypeEXT.split(".")[0])
            json_folder_detail = self.chanlist.sendJSON(json_query)
            file_detail = re.compile("{(.*?)}",
                                     re.DOTALL).findall(json_folder_detail)
            return self.searchDetails(file_detail, arttype)
        except Exception, e:
            self.log("dbidArt, Failed" + str(e), xbmc.LOGERROR)
            self.log(traceback.format_exc(), xbmc.LOGERROR)
Example #12
0
class Artdownloader:

    def __init__(self):
        self.chanlist = ChannelList()
        self.fanarttv = fanarttv()
        self.tvdbAPI = tvdb.TVDB()
        self.tmdbAPI = tmdb.TMDB()  
        
        
    def log(self, msg, level = xbmc.LOGDEBUG):
        log('Artdownloader: ' + msg, level)


    def getFallback_Arttype(self, arttype):
        arttype = arttype.lower()
        arttype = arttype.replace('landscape','fanart')
        arttype = arttype.replace('folder','poster')
        arttype = arttype.replace('thumb','poster')
        # arttype = arttype.replace('fanart','landscape')
        # arttype = arttype.replace('clearlogo','clearart')
        arttype = arttype.replace('clearart','clearlogo')
        arttype = arttype.replace('character','clearlogo')
        self.log("getFallback_Arttype = " + arttype)
        return arttype

        
    def dbidArt(self, type, chname, mpath, dbid, arttypeEXT):
        self.log("dbidArt")
        file_detail = []
        try:
            if type == 'tvshow':
                json_query = ('{"jsonrpc":"2.0","method":"VideoLibrary.GetTVShowDetails","params":{"tvshowid":%s,"properties":["art","thumbnail","fanart"]},"id":1}' % dbid)
            elif type == 'movie':
                json_query = ('{"jsonrpc":"2.0","method":"VideoLibrary.GetMovieDetails","params":{"movieid":%s,"properties":["art","thumbnail","fanart"]},"id":1}' % dbid)
            else:
                return 'NA.png'
            arttype = (arttypeEXT.split(".")[0])
            json_folder_detail = self.chanlist.sendJSON(json_query)
            file_detail = re.compile( "{(.*?)}", re.DOTALL ).findall(json_folder_detail)
            return self.searchDetails(file_detail, arttype)
        except Exception,e:  
            self.log("dbidArt, Failed" + str(e), xbmc.LOGERROR)
            self.log(traceback.format_exc(), xbmc.LOGERROR)
Example #13
0
    def migrate(self):
        self.log("migrate")
        settingsFile = xbmc.translatePath(
            os.path.join(Globals.SETTINGS_LOC, 'settings2.xml'))
        chanlist = ChannelList.ChannelList()
        chanlist.background = True
        chanlist.forceReset = True
        chanlist.createlist = True

        # If Autotune is enabled direct to autotuning
        if Globals.REAL_SETTINGS.getSetting(
                "Autotune") == "true" and Globals.REAL_SETTINGS.getSetting(
                    "Warning1") == "true":
            self.log("autoTune, migrate")
            if self.autoTune():
                return True
        else:
            if FileAccess.exists(settingsFile):
                return False
            else:
                currentpreset = 0

            for i in range(Globals.TOTAL_FILL_CHANNELS):
                chantype = 9999

                try:
                    chantype = int(
                        Globals.ADDON_SETTINGS.getSetting("Channel_" +
                                                          str(i + 1) +
                                                          "_type"))
                except:
                    pass

                if chantype == 9999:
                    self.log("addPreset")
                    self.addPreset(i + 1, currentpreset)
                    currentpreset += 1

        return True
Example #14
0
 def __init__(self):
     self.chanlist = ChannelList()
Example #15
0
class Artdownloader:
    def __init__(self):
        self.chanlist = ChannelList()

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

    def logDebug(self, msg, level=xbmc.LOGDEBUG):
        if DEBUG == 'true':
            log('Artdownloader: ' + msg, level)

    def dbidArt(self, type, chname, mpath, dbid, arttypeEXT):
        self.log("dbidArt")
        # Set image place-holder
        thumbnail = self.SetDefaultArt(chname, mpath, arttypeEXT)

        if type == 'tvshow':
            json_query = (
                '{"jsonrpc":"2.0","method":"VideoLibrary.GetTVShowDetails","params":{"tvshowid":%s,"properties":["art"]},"id":1}'
                % dbid)
        elif type == 'movie':
            json_query = (
                '{"jsonrpc":"2.0","method":"VideoLibrary.GetMovieDetails","params":{"movieid":%s,"properties":["art"]},"id":1}'
                % dbid)
        else:
            return thumbnail

        arttype = (arttypeEXT.split(".")[0]).replace('landscape', 'fanart')
        json_folder_detail = self.chanlist.sendJSON(json_query)
        file_detail = re.compile("{(.*?)}",
                                 re.DOTALL).findall(json_folder_detail)

        for f in file_detail:
            arttypes = re.search(('"%s" *: *"(.*?)"' % arttype), f)
            if arttypes != None and len(arttypes.group(1)) > 0:
                thumbnail = (unquote(
                    xbmc.translatePath(
                        (arttypes.group(1).split(','))[0]))).replace(
                            'image://',
                            '').replace('.jpg/',
                                        '.jpg').replace('.png/', '.png')
                break
        self.log("dbidArt, thumbnail = " + thumbnail)
        return thumbnail

    def JsonThumb(self, chname, arttypeEXT, mediapath, media='video'):
        self.log("JsonThumb")
        file_detail = []
        # Set image place-holder
        thumbnail = self.SetDefaultArt(chname, mpath, arttypeEXT)
        json_query = (
            '{jsonrpc":"2.0","method":"Files.GetDirectory","params":{"directory":"%s","properties":["thumbnail"]}, "id": 1}'
            % (self.chanlist.escapeDirJSON(mediapath)))
        json_folder_detail = self.chanlist.sendJSON(json_query)
        file_detail = re.compile("{(.*?)}",
                                 re.DOTALL).findall(json_folder_detail)

        for f in file_detail:
            thumbnails = re.search('"thumbnail" *: *"(.*?)"', f)
            if thumbnails != None and len(thumbnails.group(1)) > 0:
                thumbnail = (unquote(
                    xbmc.translatePath(
                        (thumbnails.group(1).split(','))[0]))).replace(
                            'image://',
                            '').replace('.jpg/',
                                        '.jpg').replace('.png/', '.png')
                break

        self.log("JsonThumb, thumbnail = " + thumbnail)
        return thumbnail

    def AlphaLogo(self, org, mod):
        self.log("AlphaLogo")
        img = Image.open(org)
        img = img.convert("RGBA")
        datas = img.getdata()
        newData = []
        for item in datas:
            if item[0] == 255 and item[1] == 255 and item[2] == 255:
                newData.append((255, 255, 255, 0))
            else:
                newData.append(item)
        img.putdata(newData)
        img.save(mod, "PNG")

    #Covert to transparent logo
    def ConvertBug(self, org, mod):
        self.log("ConvertBug")
        drive, path = os.path.splitdrive(mod)
        path, filename = os.path.split(path)
        try:
            if not FileAccess.exists(path):
                FileAccess.makedirs(path)
            org = xbmc.translatePath(org)
            original = Image.open(org)
            converted_img = original.convert('LA')
            img_bright = ImageEnhance.Brightness(converted_img)
            converted_img = img_bright.enhance(1.0)
            converted_img.save(mod)
            return mod
        except Exception, e:
            self.log("ConvertBug Failed! " + str(e))
            pass
Example #16
0
 def __init__(self):
     self.chanlist = ChannelList()
     self.fanarttv = fanarttv()
     self.tvdbAPI = tvdb.TVDB()
     self.tmdbAPI = tmdb.TMDB()  
Example #17
0
    def autoTune(self):
        self.log('autoTune, Init')
        curtime = time.time()
        chanlist = ChannelList.ChannelList()
        chanlist.background = True
        # chanlist.needsreset = True
        chanlist.makenewlists = True
        try:
            self.Donor = Donor()
        except:
            pass
        settingsFile = xbmc.translatePath(
            os.path.join(Globals.SETTINGS_LOC, 'settings2.xml'))

        if FileAccess.exists(settingsFile):
            try:
                os.remove(settingsFile)
            except:
                self.log("autoTune, Unable to delete " + str(settingsFile))

        channelNum = 0
        updateDialogProgress = 0

        self.updateDialog = xbmcgui.DialogProgress()
        self.updateDialog.create("PseudoTV Live", "Auto Tune")

        # LiveTV - PVR
        self.updateDialogProgress = 5
        if Globals.REAL_SETTINGS.getSetting(
                "autoFindLivePVR"
        ) == "true" and Globals.REAL_SETTINGS.getSetting('xmltvLOC') != '':
            self.log("autoTune, Adding Live PVR Channels")
            self.updateDialog.update(self.updateDialogProgress, "Auto Tune",
                                     "Adding Live PVR Channels", "")
            CHnum = 0
            RCHnum = 0
            CHid = 0
            CHlst = ''
            CHname = ''
            CHzapit = ''
            if channelNum == 0:
                channelNum = 1
            try:
                json_query = '{"jsonrpc":"2.0","method":"PVR.GetChannels","params":{"channelgroupid":2}, "id":1}'
                json_folder_detail = chanlist.sendJSON(json_query)
                file_detail = re.compile("{(.*?)}",
                                         re.DOTALL).findall(json_folder_detail)
                self.logDebug('autoFindLivePVR, file_detail = ' +
                              str(file_detail))
                self.xmlTvFile = xbmc.translatePath(
                    os.path.join(Globals.REAL_SETTINGS.getSetting('xmltvLOC'),
                                 'xmltv.xml'))

                f = FileAccess.open(self.xmlTvFile, "rb")
                tree = ET.parse(f)
                root = tree.getroot()

                file_detail = str(file_detail)
                CHnameLST = re.findall('"label" *: *(.*?),', file_detail)
                CHidLST = re.findall('"channelid" *: *(.*?),', file_detail)
                self.logDebug('autoFindLivePVR, CHnameLST = ' + str(CHnameLST))
                self.logDebug('autoFindLivePVR, CHidLST = ' + str(CHidLST))

                for CHnum in range(len(file_detail)):
                    CHname = CHnameLST[CHnum]
                    CHname = str(CHname)
                    CHname = CHname.split('"', 1)[-1]
                    CHname = CHname.split('"')[0]
                    CHlst = (CHname + ',' + CHidLST[CHnum])
                    inSet = False
                    self.logDebug('autoFindLivePVR, CHlst.1 = ' + str(CHlst))
                    # search xmltv for channel name, then find its id
                    for elem in root.getiterator():
                        if elem.tag == ("channel"):
                            name = elem.findall('display-name')
                            for i in name:
                                RCHnum = (CHnum + 1)
                                if CHname == i.text:
                                    CHzapit = elem.attrib
                                    CHzapit = str(CHzapit)
                                    CHzapit = CHzapit.split(": '", 1)[-1]
                                    CHzapit = CHzapit.split("'")[0]
                                    CHlst = (CHlst + ',' + str(CHzapit))
                                    self.logDebug(
                                        'autoFindLivePVR, CHlst.2 = ' +
                                        str(CHlst))
                                    inSet = True

                    self.log('autoFindLivePVR, inSet = ' + str(inSet) + ' , ' +
                             str(CHlst))
                    if inSet == True:
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_type", "8")
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_time", "0")
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_1", CHzapit)
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_2",
                            "pvr://channels/tv/All TV channels/" + str(CHnum) +
                            ".pvr")
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_3", "xmltv")
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_4", "")
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_rulecount", "1")
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_rule_1_id", "1")
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_rule_1_opt_1",
                            CHname + ' LiveTV')
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_changed", "true")
                        channelNum = channelNum + 1

                    if inSet == False:
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_type", "9")
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_time", "0")
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_1", "5400")
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_2",
                            "pvr://channels/tv/All TV channels/" + str(CHnum) +
                            ".pvr")
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_3", CHname)
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_4",
                            "XMLTV DATA NOT FOUND")
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_rulecount", "1")
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_rule_1_id", "1")
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_rule_1_opt_1",
                            CHname + ' LiveTV')
                        Globals.ADDON_SETTINGS.setSetting(
                            "Channel_" + str(channelNum) + "_changed", "true")
                        channelNum = channelNum + 1
            except:
                pass
            channelNum = channelNum
            self.logDebug('channelNum = ' + str(channelNum))

        # Custom Channels
        self.updateDialogProgress = 15
        if Globals.REAL_SETTINGS.getSetting("autoFindCustom") == "true":
            self.log("autoTune, Adding Custom Channel")
            self.updateDialog.update(self.updateDialogProgress, "Auto Tune",
                                     "Adding Custom Channel", "")
            i = 1
            for i in range(500):
                if os.path.exists(
                        xbmc.translatePath('special://profile/playlists/video')
                        + '/Channel_' + str(i + 1) + '.xsp'):
                    self.log("autoTune, Adding Custom Video Playlist Channel")
                    channelNum = channelNum + 1
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_type", "0")
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_time", "0")
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_1",
                        str(
                            xbmc.translatePath(
                                'special://profile/playlists/video/') +
                            "Channel_" + str(i + 1) + '.xsp'))
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_rulecount", "1")
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_rule_1_id", "1")
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_rule_1_opt_1",
                        Globals.uni(
                            chanlist.cleanString(
                                chanlist.getSmartPlaylistName(
                                    xbmc.translatePath(
                                        'special://profile/playlists/video') +
                                    '/Channel_' + str(i + 1) + '.xsp'))))
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_changed", "true")
                    self.updateDialog.update(
                        self.updateDialogProgress, "PseudoTV Live",
                        "Found " + Globals.uni(
                            chanlist.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'):
                    self.log("autoTune, Adding Custom Mixed Playlist Channel")
                    channelNum = channelNum + 1
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_type", "0")
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_time", "0")
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_1",
                        str(
                            xbmc.translatePath(
                                'special://profile/playlists/mixed/') +
                            "Channel_" + str(i + 1) + '.xsp'))
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_rulecount", "1")
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_rule_1_id", "1")
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_rule_1_opt_1",
                        Globals.uni(
                            chanlist.cleanString(
                                chanlist.getSmartPlaylistName(
                                    xbmc.translatePath(
                                        'special://profile/playlists/mixed') +
                                    '/Channel_' + str(i + 1) + '.xsp'))))
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_changed", "true")
                    self.updateDialog.update(
                        self.updateDialogProgress, "PseudoTV Live",
                        "Found " + Globals.uni(
                            chanlist.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'):
                    self.log("autoTune, Adding Custom Music Playlist Channel")
                    channelNum = channelNum + 1
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_type", "0")
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_time", "0")
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_1",
                        str(
                            xbmc.translatePath(
                                'special://profile/playlists/music/') +
                            "Channel_" + str(i + 1) + '.xsp'))
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_rulecount", "1")
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_rule_1_id", "1")
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_rule_1_opt_1",
                        Globals.uni(
                            chanlist.cleanString(
                                chanlist.getSmartPlaylistName(
                                    xbmc.translatePath(
                                        'special://profile/playlists/music') +
                                    '/Channel_' + str(i + 1) + '.xsp'))))
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_changed", "true")
                    self.updateDialog.update(
                        self.updateDialogProgress, "PseudoTV Live",
                        "Found " + Globals.uni(
                            chanlist.getSmartPlaylistName(
                                xbmc.translatePath(
                                    'special://profile/playlists/music') +
                                '/Channel_' + str(i + 1) + '.xsp')), "")

            channelNum = channelNum
            self.logDebug('channelNum = ' + str(channelNum))

        #TV - Networks/Genres
        self.updateDialogProgress = 20
        self.log("autoTune, autoFindNetworks " +
                 str(Globals.REAL_SETTINGS.getSetting("autoFindNetworks")))
        self.log("autoTune, autoFindTVGenres " +
                 str(Globals.REAL_SETTINGS.getSetting("autoFindTVGenres")))
        if (Globals.REAL_SETTINGS.getSetting("autoFindNetworks") == "true"
                or Globals.REAL_SETTINGS.getSetting("autoFindTVGenres")
                == "true"):
            self.log("autoTune, Searching for TV Channels")
            self.updateDialog.update(self.updateDialogProgress, "Auto Tune",
                                     "Searching for TV Channels", "")
            chanlist.fillTVInfo()

        # need to add check for auto find network channels
        self.updateDialogProgress = 21
        if Globals.REAL_SETTINGS.getSetting("autoFindNetworks") == "true":
            self.log("autoTune, Adding TV Networks")
            self.updateDialog.update(self.updateDialogProgress, "Auto Tune",
                                     "Adding TV Networks", "")
            i = 1
            for i in range(len(chanlist.networkList)):
                channelNum = channelNum + 1
                # add network presets
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_type", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_time", "0")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_1",
                    Globals.uni(chanlist.networkList[i]))
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_changed", "true")
                self.updateDialog.update(self.updateDialogProgress,
                                         "Auto Tune", "Adding TV Network",
                                         Globals.uni(chanlist.networkList[i]))

            channelNum = channelNum
            self.logDebug('channelNum = ' + str(channelNum))

        self.updateDialogProgress = 22
        if Globals.REAL_SETTINGS.getSetting("autoFindTVGenres") == "true":
            self.log("autoTune, Adding TV Genres")
            self.updateDialog.update(self.updateDialogProgress, "Auto Tune",
                                     "Adding TV Genres", "")
            channelNum = channelNum - 1
            for i in range(len(chanlist.showGenreList)):
                channelNum = channelNum + 1
                # add network presets
                if chanlist.showGenreList[i] != '':
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_type", "3")
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_time", "0")
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_1",
                        Globals.uni(chanlist.showGenreList[i]))
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_changed", "true")
                    self.updateDialog.update(
                        self.updateDialogProgress, "Auto Tune",
                        "Adding TV Genres",
                        Globals.uni(chanlist.showGenreList[i]) + " TV")
            channelNum = channelNum
            self.logDebug('channelNum = ' + str(channelNum))

        self.updateDialogProgress = 23
        self.log("autoTune, autoFindStudios " +
                 str(Globals.REAL_SETTINGS.getSetting("autoFindStudios")))
        self.log("autoTune, autoFindMovieGenres " +
                 str(Globals.REAL_SETTINGS.getSetting("autoFindMovieGenres")))
        if (Globals.REAL_SETTINGS.getSetting("autoFindStudios") == "true"
                or Globals.REAL_SETTINGS.getSetting("autoFindMovieGenres")
                == "true"):
            self.updateDialog.update(self.updateDialogProgress, "Auto Tune",
                                     "Searching for Movie Channels", "")
            chanlist.fillMovieInfo()

        self.updateDialogProgress = 24
        if Globals.REAL_SETTINGS.getSetting("autoFindStudios") == "true":
            self.log("autoTune, Adding Movie Studios")
            self.updateDialog.update(self.updateDialogProgress, "Auto Tune",
                                     "Adding Movie Studios", "")
            i = 1
            for i in range(len(chanlist.studioList)):
                channelNum = channelNum + 1
                self.updateDialogProgress = self.updateDialogProgress + (
                    10 / len(chanlist.studioList))
                # add network presets
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_type", "2")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_time", "0")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_1",
                    Globals.uni(chanlist.studioList[i]))
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_changed", "true")
                self.updateDialog.update(self.updateDialogProgress,
                                         "Auto Tune", "Adding Movie Studios",
                                         Globals.uni(chanlist.studioList[i]))

            channelNum = channelNum
            self.logDebug('channelNum = ' + str(channelNum))

        self.updateDialogProgress = 25
        if Globals.REAL_SETTINGS.getSetting("autoFindMovieGenres") == "true":
            self.log("autoTune, Adding Movie Genres")
            self.updateDialog.update(self.updateDialogProgress, "Auto Tune",
                                     "Adding Movie Genres", "")
            channelNum = channelNum - 1
            for i in range(len(chanlist.movieGenreList)):
                channelNum = channelNum + 1
                self.updateDialogProgress = self.updateDialogProgress + (
                    10 / len(chanlist.movieGenreList))
                # add network presets
                if chanlist.movieGenreList[i] != '':
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_type", "4")
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_time", "0")
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_1",
                        Globals.uni(chanlist.movieGenreList[i]))
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_changed", "true")
                    self.updateDialog.update(
                        self.updateDialogProgress, "Auto Tune",
                        "Adding Movie Genres", "Found " +
                        Globals.uni(chanlist.movieGenreList[i]) + " Movies")
            channelNum = channelNum
            self.logDebug('channelNum = ' + str(channelNum))

        self.updateDialogProgress = 26
        self.log("autoTune, autoFindMixGenres " +
                 str(Globals.REAL_SETTINGS.getSetting("autoFindMixGenres")))
        if Globals.REAL_SETTINGS.getSetting("autoFindMixGenres") == "true":
            self.updateDialog.update(self.updateDialogProgress, "Auto Tune",
                                     "Searching for Mixed Channels", "")
            chanlist.fillMixedGenreInfo()

        self.updateDialogProgress = 27
        if Globals.REAL_SETTINGS.getSetting("autoFindMixGenres") == "true":
            self.log("autoTune, Adding Mixed Genres")
            self.updateDialog.update(self.updateDialogProgress, "Auto Tune",
                                     "Adding Mixed Genres", "")
            channelNum = channelNum - 1
            for i in range(len(chanlist.mixedGenreList)):
                channelNum = channelNum + 1
                # add network presets
                if chanlist.mixedGenreList[i] != '':
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_type", "5")
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_time", "0")
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_1",
                        Globals.uni(chanlist.mixedGenreList[i]))
                    Globals.ADDON_SETTINGS.setSetting(
                        "Channel_" + str(channelNum) + "_changed", "true")
                    self.updateDialog.update(
                        self.updateDialogProgress, "Auto Tune",
                        "Adding Mixed Genres",
                        Globals.uni(chanlist.mixedGenreList[i]) + " Mix")

            channelNum = channelNum
            self.logDebug('channelNum = ' + str(channelNum))

        self.updateDialogProgress = 28
        self.log("autoTune, autoFindMusicGenres " +
                 str(Globals.REAL_SETTINGS.getSetting("autoFindMusicGenres")))
        if Globals.REAL_SETTINGS.getSetting("autoFindMusicGenres") == "true":
            self.updateDialog.update(self.updateDialogProgress, "Auto Tune",
                                     "Searching for Music Channels", "")
            chanlist.fillMusicInfo()

        self.updateDialogProgress = 29
        #Music Genre
        if Globals.REAL_SETTINGS.getSetting("autoFindMusicGenres") == "true":
            self.log("autoTune, Adding Music Genres")
            self.updateDialog.update(self.updateDialogProgress, "Auto Tune",
                                     "Adding Music Genres", "")
            i = 1
            for i in range(len(chanlist.musicGenreList)):
                channelNum = channelNum + 1
                # add network presets
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_type", "12")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_time", "0")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_1",
                    Globals.uni(chanlist.musicGenreList[i]))
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_2", "0")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_changed", "true")
                self.updateDialog.update(
                    self.updateDialogProgress, "Auto Tune",
                    "Adding Music Genres",
                    Globals.uni(chanlist.musicGenreList[i]) + " Music")

            channelNum = channelNum
            self.logDebug('channelNum = ' + str(channelNum))

        #Music Videos - Last.fm user
        self.updateDialogProgress = 30
        if Globals.REAL_SETTINGS.getSetting(
                "autoFindMusicVideosLastFM") == "true":
            self.log("autoTune, Adding Last.FM Music Videos")
            self.updateDialog.update(self.updateDialogProgress, "Auto Tune",
                                     "Adding Last.FM Music Videos", "")
            if channelNum == 0:
                channelNum = 1
            user = Globals.REAL_SETTINGS.getSetting(
                "autoFindMusicVideosLastFMuser")
            lastapi = "http://api.tv.timbormans.com/user/" + user + "/topartists.xml"
            for i in range(1):
                # add Last.fm user presets
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_type", "13")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_time", "0")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_1", lastapi)
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_2", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_3", "10")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_rulecount", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_rule_1_id", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_rule_1_opt_1", "Last.FM")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_changed", "true")

            channelNum = channelNum
            self.logDebug('channelNum = ' + str(channelNum))

        #Music Videos - Youtube
        self.updateDialogProgress = 35
        if Globals.REAL_SETTINGS.getSetting(
                "autoFindMusicVideosYoutube") == "true":
            self.log("autoTune, Adding Youtube Music Videos")
            self.updateDialog.update(self.updateDialogProgress, "Auto Tune",
                                     "Adding Youtube Music Videos", "")
            if channelNum == 0:
                channelNum = 1
            for i in range(1):
                # add HungaryRChart presets
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_type", "10")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_time", "0")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_1", "HungaryRChart")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_2", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_3", "50")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_rulecount", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_rule_1_id", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_rule_1_opt_1", "HRChart")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_changed", "true")
                # add BillbostdHot100 presets
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_type", "10")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_time", "0")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_1", "BillbostdHot100")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_2", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_3", "50")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_rulecount", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_rule_1_id", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_rule_1_opt_1",
                    "BillbostdHot100")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_changed", "true")
                # add TheTesteeTop50Charts presets
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 2) + "_type", "10")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 2) + "_time", "0")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 2) + "_1",
                    "TheTesteeTop50Charts")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 2) + "_2", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 2) + "_3", "50")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 2) + "_rulecount", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 2) + "_rule_1_id", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 2) + "_rule_1_opt_1",
                    "TheTesteeTop50Charts")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 2) + "_changed", "true")

            channelNum = channelNum + 3
            self.logDebug('channelNum = ' + str(channelNum))

        #Music Videos - VevoTV
        self.updateDialogProgress = 40
        if Globals.REAL_SETTINGS.getSetting(
                "autoFindMusicVideosVevoTV") == "true":
            self.log("autoTune, Adding VevoTV Music Videos")
            self.updateDialog.update(self.updateDialogProgress, "Auto Tune",
                                     "Adding VevoTV Music Videos", "")
            if channelNum == 0:
                channelNum = 1

            for i in range(1):
                # add VevoTV presets
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_type", "9")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_time", "0")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_1", "5400")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_2",
                    "http://vevoplaylist-live.hls.adaptive.level3.net/vevo/ch1/06/prog_index.m3u8"
                )
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_3", "VEVO TV (US: Hits)")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_4",
                    "Sit back and enjoy a 24/7 stream of music videos on VEVO TV."
                )
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_rulecount", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_rule_1_id", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_rule_1_opt_1",
                    "VevoTV - Hits")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_changed", "true")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_type", "9")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_time", "0")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_1", "5400")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_2",
                    "http://vevoplaylist-live.hls.adaptive.level3.net/vevo/ch2/06/prog_index.m3u8"
                )
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_3",
                    "VEVO TV (US: Flow)")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_4",
                    "Sit back and enjoy a 24/7 stream of music videos on VEVO TV."
                )
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_rulecount", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_rule_1_id", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_rule_1_opt_1",
                    "VevoTV - Flow")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_changed", "true")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 2) + "_type", "9")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 2) + "_time", "0")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 2) + "_1", "5400")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 2) + "_2",
                    "http://vevoplaylist-live.hls.adaptive.level3.net/vevo/ch3/06/prog_index.m3u8"
                )
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 2) + "_3",
                    "VEVO TV (Nashville)")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 2) + "_4",
                    "Sit back and enjoy a 24/7 stream of music videos on VEVO TV."
                )
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 2) + "_rulecount", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 2) + "_rule_1_id", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 2) + "_rule_1_opt_1",
                    "VevoTV - Nashville")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 2) + "_changed", "true")

            channelNum = channelNum + 3
            self.logDebug('channelNum = ' + str(channelNum))

        #Music Videos - Local
        self.updateDialogProgress = 45
        if Globals.REAL_SETTINGS.getSetting("autoFindMusicVideosLocal") != "":
            self.log("autoTune, Adding Local Music Videos")
            self.updateDialog.update(self.updateDialogProgress, "Auto Tune",
                                     "Adding Local Music Videos", "")
            if channelNum == 0:
                channelNum = 1
            LocalVideo = str(
                Globals.REAL_SETTINGS.getSetting('autoFindMusicVideosLocal'))
            for i in range(1):
                # add Local presets
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_type", "7")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_time", "0")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_1",
                    "" + LocalVideo + "")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_rulecount", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_rule_1_id", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_rule_1_opt_1",
                    "Music Videos")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_changed", "true")

            channelNum = channelNum + 1
            self.logDebug('channelNum = ' + str(channelNum))

        #InternetTV - Strms
        self.updateDialogProgress = 50
        if Globals.REAL_SETTINGS.getSetting("autoFindInternetStrms") == "true":
            self.log("autoTune, Adding InternetTV Strms")
            self.updateDialog.update(self.updateDialogProgress, "Auto Tune",
                                     "Adding InternetTV Strms", "")
            if channelNum == 0:
                channelNum = 1

            for i in range(1):
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_type", "10")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_time", "0")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_1", "BBCWorldwide")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_2", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_3", "50")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_4", "")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_rulecount", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_rule_1_id", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_rule_1_opt_1",
                    "BBC World News")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum) + "_changed", "true")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_type", "11")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_time", "0")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_1",
                    "http://revision3.com/hdnation/feed/Quicktime-High-Definition"
                )
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_2", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_3", "50")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_rulecount", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_rule_1_id", "1")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_rule_1_opt_1",
                    "HD Nation")
                Globals.ADDON_SETTINGS.setSetting(
                    "Channel_" + str(channelNum + 1) + "_changed", "true")

            channelNum = channelNum + 3
            self.logDebug('channelNum = ' + str(channelNum))

            if Globals.REAL_SETTINGS.getSetting("Donor_Enabled") == "true":
                try:
                    self.Donor.migrateDonor(channelNum)
                except:
                    pass

        Globals.ADDON_SETTINGS.writeSettings()

        #set max channels
        # chanlist.setMaxChannels()

        self.updateDialogProgress = 100
        # reset auto tune settings
        Globals.REAL_SETTINGS.setSetting('Autotune', "false")
        Globals.REAL_SETTINGS.setSetting('Warning1', "false")
        Globals.REAL_SETTINGS.setSetting('autoFindLivePVR', "false")
        Globals.REAL_SETTINGS.setSetting("autoFindCustom", "false")
        Globals.REAL_SETTINGS.setSetting("autoFindNetworks", "false")
        Globals.REAL_SETTINGS.setSetting("autoFindStudios", "false")
        Globals.REAL_SETTINGS.setSetting("autoFindTVGenres", "false")
        Globals.REAL_SETTINGS.setSetting("autoFindMovieGenres", "false")
        Globals.REAL_SETTINGS.setSetting("autoFindMixGenres", "false")
        Globals.REAL_SETTINGS.setSetting("autoFindTVShows", "false")
        Globals.REAL_SETTINGS.setSetting("autoFindMusicGenres", "false")
        Globals.REAL_SETTINGS.setSetting("autoFindMusicVideosYoutube", "false")
        Globals.REAL_SETTINGS.setSetting("autoFindMusicVideosVevoTV", "false")
        Globals.REAL_SETTINGS.setSetting("autoFindMusicVideosLastFM", "false")
        Globals.REAL_SETTINGS.setSetting("autoFindMusicVideosLocal", "")
        Globals.REAL_SETTINGS.setSetting("autoFindInternetStrms", "false")
        Globals.REAL_SETTINGS.setSetting("ForceChannelReset", "true")

        Globals.ADDON_SETTINGS.setSetting('LastExitTime', str(int(curtime)))
        self.updateDialog.close()
Example #18
0
    with youtube_dl.YoutubeDL(yld_opts) as ydl:
        ydl.download([videoId])

    return videoId


def checkChannelFolder(folderName):
    return os.path.isdir(folderName)


def createChannelFolder(folderName):
    print(">> Creating folder")
    os.mkdir(folderName)


connection = ChannelList.pgConnection()

for channel in ChannelList.sqliteChannelFindAll(connection):
    print(channel["name"] + " --> " + channel["id"])

    os.chdir(downloadsPath)

    if not checkChannelFolder(channel["name"]):
        createChannelFolder(channel["name"])
    else:
        print("Already exists")

    os.chdir(downloadsPath + "/" + channel["name"])

    r = requests.get(channel["thumbnail"])
    thumbnailName = channel["id"] + "_thumbnail.jpg"
Example #19
0
 def __init__(self):
     self.chanlist = ChannelList()
     self.fanarttv = fanarttv()
     self.tvdbAPI = tvdb.TVDB()
     self.tmdbAPI = tmdb.TMDB()
Example #20
0
    def autoTune(self):
        self.log('autoTune, Init')
        curtime = time.time()
        chanlist = ChannelList.ChannelList()
        chanlist.background = True
        chanlist.makenewlists = True
        chanlist.forceReset = True
        
        settingsFile = xbmc.translatePath(os.path.join(Globals.SETTINGS_LOC, 'settings2.xml'))   
        self.log("autoTune, autoFindCustom " + str(Globals.REAL_SETTINGS.getSetting("autoFindCustom")))
        self.log("autoTune, autoFindLivePVR " + str(Globals.REAL_SETTINGS.getSetting("autoFindLivePVR")))
        self.log("autoTune, autoFindNetworks " + str(Globals.REAL_SETTINGS.getSetting("autoFindNetworks")))
        self.log("autoTune, autoFindTVGenres " + str(Globals.REAL_SETTINGS.getSetting("autoFindTVGenres")))
        self.log("autoTune, autoFindStudios " + str(Globals.REAL_SETTINGS.getSetting("autoFindStudios")))
        self.log("autoTune, autoFindMovieGenres " + str(Globals.REAL_SETTINGS.getSetting("autoFindMovieGenres")))
        self.log("autoTune, autoFindMixGenres " + str(Globals.REAL_SETTINGS.getSetting("autoFindMixGenres")))
        self.log("autoTune, autoFindRecent " + str(Globals.REAL_SETTINGS.getSetting("autoFindRecent")))
     
        #Reserve channel check            
        if Globals.REAL_SETTINGS.getSetting("reserveChannels") == "true":
            print 'Reserved for Autotune'
            channelNum = 501
        else:
            channelNum = 1
        
        self.log('autoTune, Starting channelNum = ' + str(channelNum))
               
        updateDialogProgress = 0
        self.updateDialog = xbmcgui.DialogProgress()
        self.updateDialog.create("PseudoTV Lite", "Auto Tune")
        
        self.limit = MEDIA_LIMIT[int(Globals.REAL_SETTINGS.getSetting('MEDIA_LIMIT'))]
        if self.limit == 0 or self.limit > 200:
            self.limit = 200
        elif self.limit < 25:
            self.limit = 25
            
        # Custom Playlists
        self.updateDialogProgress = 1
        if Globals.REAL_SETTINGS.getSetting("autoFindCustom") == "true" :
            self.log("autoTune, adding Custom Channel")
            self.updateDialog.update(self.updateDialogProgress,"AutoTuning","adding Custom Channels"," ")
            CChan = 0
            
            for CChan in range(999):
                if xbmcvfs.exists(xbmc.translatePath('special://profile/playlists/music') + '/Channel_' + str(CChan + 1) + '.xsp'):
                    self.log("autoTune, adding Custom Music Playlist Channel")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "12")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", str(xbmc.translatePath('special://profile/playlists/music/') + "Channel_" + str(CChan + 1) + '.xsp'))
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rulecount", "1")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_id", "1")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_opt_1", Globals.uni(chanlist.cleanString(chanlist.getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/music') + '/Channel_' + str(CChan + 1) + '.xsp'))))
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                    self.updateDialog.update(self.updateDialogProgress,"PseudoTV Lite","Found " + Globals.uni(chanlist.getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/music') + '/Channel_' + str(CChan + 1) + '.xsp')),"")
                    channelNum += 1
                elif xbmcvfs.exists(xbmc.translatePath('special://profile/playlists/mixed') + '/Channel_' + str(CChan + 1) + '.xsp'):
                    self.log("autoTune, adding Custom Mixed Playlist Channel")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "0")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", str(xbmc.translatePath('special://profile/playlists/mixed/') + "Channel_" + str(CChan + 1) + '.xsp'))
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rulecount", "1")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_id", "1")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_opt_1", Globals.uni(chanlist.cleanString(chanlist.getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/mixed') + '/Channel_' + str(CChan + 1) + '.xsp'))))
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                    self.updateDialog.update(self.updateDialogProgress,"PseudoTV Lite","Found " + Globals.uni(chanlist.getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/mixed') + '/Channel_' + str(CChan + 1) + '.xsp')),"")
                    channelNum += 1
                elif xbmcvfs.exists(xbmc.translatePath('special://profile/playlists/video') + '/Channel_' + str(CChan + 1) + '.xsp'):
                    self.log("autoTune, adding Custom Video Playlist Channel")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "0")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", str(xbmc.translatePath('special://profile/playlists/video/') + "Channel_" + str(CChan + 1) + '.xsp'))
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rulecount", "1")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_id", "1")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_opt_1", Globals.uni(chanlist.cleanString(chanlist.getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/video') + '/Channel_' + str(CChan + 1) + '.xsp'))))
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                    self.updateDialog.update(self.updateDialogProgress,"PseudoTV Lite","Found " + Globals.uni(chanlist.getSmartPlaylistName(xbmc.translatePath('special://profile/playlists/video') + '/Channel_' + str(CChan + 1) + '.xsp')),"")
                    channelNum += 1
             
        # LiveTV - PVR
        self.updateDialogProgress = 10
        if Globals.REAL_SETTINGS.getSetting("autoFindLivePVR") == "true":
            self.log("autoTune, adding Live PVR Channels")
            self.updateDialog.update(self.updateDialogProgress,"AutoTuning","adding PVR Channels"," ")
            
            #PVR Path by XBMC Version, no json paths?
            XBMCver = chanlist.XBMCversion()
            if XBMCver == 'Gotham':
                PVRverPath = "pvr://channels/tv/All TV channels/"
            else:
                PVRverPath = "pvr://channels/tv/All channels/"
                
            try:
                json_query = uni('{"jsonrpc":"2.0","method":"PVR.GetChannels","params":{"channelgroupid":2,"properties":["thumbnail"]},"id": 1 }')
                json_detail = chanlist.sendJSON(json_query)
                file_detail = re.compile( "{(.*?)}", re.DOTALL ).findall(json_detail)
                chanlist.cached_json_detailed_xmltvChannels_pvr = []
                PVRnum = 0
                
                for PVRnum in file_detail:
                    CHids = re.search('"channelid" *: *(.*?),', PVRnum)
                    CHnames = re.search('"label" *: *"(.*?)"', PVRnum)
                    thumbs = re.search('"thumbnail" *: *"(.*?)"', PVRnum)
                    
                    if CHids and CHnames:
                        CHid = int(CHids.group(1))
                        CHname = CHnames.group(1)
                         
                        CHSetName, CHzapit = chanlist.findZap2itID(CHname, 'pvr')
                            
                        Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "8")
                        Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                        Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", CHzapit)
                        Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_2", PVRverPath + str(CHid - 1) + ".pvr")
                        Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_3", 'pvr')
                        Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rulecount", "2")
                        Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_id", "1")
                        Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_opt_1", CHname + ' PVR')  
                        Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_2_id", "13")
                        Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_2_opt_1", "24")  
                        Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")                        
                        self.updateDialog.update(self.updateDialogProgress,"AutoTuning","adding PVR Channels",CHname)  
                        channelNum += 1 
            except:
                pass
        
      
        #TV - Networks/Genres
        self.updateDialogProgress = 20
        if (Globals.REAL_SETTINGS.getSetting("autoFindNetworks") == "true" or Globals.REAL_SETTINGS.getSetting("autoFindTVGenres") == "true"):
            self.log("autoTune, Searching for TV Channels")
            self.updateDialog.update(self.updateDialogProgress,"AutoTuning","Searching for TV Channels"," ")
            chanlist.fillTVInfo()

        # need to add check for auto find network channels
        self.updateDialogProgress = 21
        if Globals.REAL_SETTINGS.getSetting("autoFindNetworks") == "true":
            self.log("autoTune, adding TV Networks")
            self.updateDialog.update(self.updateDialogProgress,"AutoTuning","adding TV Networks"," ")

            for i in range(len(chanlist.networkList)):
                # channelNum = self.initialAddChannels(chanlist.networkList, 1, channelNum)
                # add network presets
                Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "1")
                Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1",Globals.uni(chanlist.networkList[i]))
                Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rulecount", "1")
                Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_id", "12")
                Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                self.updateDialog.update(self.updateDialogProgress,"AutoTuning","adding TV Network",Globals.uni(chanlist.networkList[i]))
                channelNum += 1
        
        self.updateDialogProgress = 22
        if Globals.REAL_SETTINGS.getSetting("autoFindTVGenres") == "true":
            self.log("autoTune, adding TV Genres")
            self.updateDialog.update(self.updateDialogProgress,"AutoTuning","adding TV Genres","")

            # channelNum = self.initialAddChannels(chanlist.showGenreList, 3, channelNum)
            for i in range(len(chanlist.showGenreList)):
                # add network presets
                if chanlist.showGenreList[i] != '':
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "3")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", Globals.uni(chanlist.showGenreList[i]))
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                    self.updateDialog.update(self.updateDialogProgress,"AutoTuning","adding TV Genres",Globals.uni(chanlist.showGenreList[i]) + " TV")
                    channelNum += 1
        
        self.updateDialogProgress = 23
        if (Globals.REAL_SETTINGS.getSetting("autoFindStudios") == "true" or Globals.REAL_SETTINGS.getSetting("autoFindMovieGenres") == "true"):
            self.updateDialog.update(self.updateDialogProgress,"AutoTuning","Searching for Movie Channels","")
            chanlist.fillMovieInfo()

        self.updateDialogProgress = 24
        if Globals.REAL_SETTINGS.getSetting("autoFindStudios") == "true":
            self.log("autoTune, adding Movie Studios")
            self.updateDialog.update(self.updateDialogProgress,"AutoTuning","adding Movie Studios"," ")

            for i in range(len(chanlist.studioList)):
                self.updateDialogProgress = self.updateDialogProgress + (10/len(chanlist.studioList))
                # add network presets
                Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "2")
                Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", Globals.uni(chanlist.studioList[i]))
                Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                self.updateDialog.update(self.updateDialogProgress,"AutoTuning","adding Movie Studios",Globals.uni(chanlist.studioList[i]))
                channelNum += 1
                
        self.updateDialogProgress = 25
        if Globals.REAL_SETTINGS.getSetting("autoFindMovieGenres") == "true":
            self.log("autoTune, adding Movie Genres")
            self.updateDialog.update(self.updateDialogProgress,"AutoTuning","adding Movie Genres"," ")

            # channelNum = self.initialAddChannels(chanlist.movieGenreList, 4, channelNum)
            for i in range(len(chanlist.movieGenreList)):
                self.updateDialogProgress = self.updateDialogProgress + (10/len(chanlist.movieGenreList))
                # add network presets
                if chanlist.movieGenreList[i] != '':
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "4")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", Globals.uni(chanlist.movieGenreList[i]))
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                    self.updateDialog.update(self.updateDialogProgress,"AutoTuning","adding Movie Genres","Found " + Globals.uni(chanlist.movieGenreList[i]) + " Movies")
                    channelNum += 1
                
        self.updateDialogProgress = 26
        if Globals.REAL_SETTINGS.getSetting("autoFindMixGenres") == "true":
            self.updateDialog.update(self.updateDialogProgress,"AutoTuning","Searching for Mixed Channels"," ")
            chanlist.fillMixedGenreInfo()
        
        self.updateDialogProgress = 27
        if Globals.REAL_SETTINGS.getSetting("autoFindMixGenres") == "true":
            self.log("autoTune, adding Mixed Genres")
            self.updateDialog.update(self.updateDialogProgress,"AutoTuning","adding Mixed Genres","")

            for i in range(len(chanlist.mixedGenreList)):
                # add network presets
                if chanlist.mixedGenreList[i] != '':
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "5")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", Globals.uni(chanlist.mixedGenreList[i]))
                    Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
                    self.updateDialog.update(self.updateDialogProgress,"AutoTuning","adding Mixed Genres",Globals.uni(chanlist.mixedGenreList[i]) + " Mix")
                    channelNum += 1
        
        #recent movie/tv
        self.updateDialogProgress = 28  
        if Globals.REAL_SETTINGS.getSetting("autoFindRecent") == "true":
            self.log("autoTune, adding Recent TV/Movies")
            
            self.updateDialog.update(self.updateDialogProgress,"AutoTuning","adding Recent TV"," ")
            TVflename = chanlist.createRecentlyAddedTV()
            Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "0")
            Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
            Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", TVflename)
            Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rulecount", "3")
            Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_id", "1")
            Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_opt_1", "Recent TV")  
            Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_2_id", "12")
            Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_3_id", "13")
            Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_3_opt_1", "4")  
            Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
            channelNum += 1
            
            self.updateDialog.update(self.updateDialogProgress,"AutoTuning","adding Recent Movies"," ")
            Movieflename = chanlist.createRecentlyAddedMovies()     
            Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_type", "0")
            Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_time", "0")
            Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_1", Movieflename)
            Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rulecount", "2")
            Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_id", "1")
            Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_1_opt_1", "Recent Movies")  
            Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_2_id", "13")
            Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_rule_2_opt_1", "4")  
            Globals.ADDON_SETTINGS.setSetting("Channel_" + str(channelNum) + "_changed", "true")
            channelNum += 1
            
        Globals.ADDON_SETTINGS.writeSettings()
        self.updateDialogProgress = 100
        
        # reset auto tune settings        
        Globals.REAL_SETTINGS.setSetting('Autotune', "false")
        Globals.REAL_SETTINGS.setSetting('Warning1', "false") 
        Globals.REAL_SETTINGS.setSetting("autoFindCustom","false")
        Globals.REAL_SETTINGS.setSetting('autoFindLivePVR', "false")
        Globals.REAL_SETTINGS.setSetting("autoFindNetworks","false")
        Globals.REAL_SETTINGS.setSetting("autoFindStudios","false")
        Globals.REAL_SETTINGS.setSetting("autoFindTVGenres","false")
        Globals.REAL_SETTINGS.setSetting("autoFindMovieGenres","false")
        Globals.REAL_SETTINGS.setSetting("autoFindMixGenres","false") 
        Globals.REAL_SETTINGS.setSetting("autoFindRecent","false")
        Globals.REAL_SETTINGS.setSetting("ForceChannelReset","true")
        Globals.ADDON_SETTINGS.setSetting('LastExitTime', str(int(curtime)))
        self.updateDialog.close()
Example #21
0
class Artdownloader:
    def __init__(self):
        self.chanlist = ChannelList()
        self.fanarttv = fanarttv()
        self.tvdbAPI = tvdb.TVDB()
        self.tmdbAPI = tmdb.TMDB()

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

    def logDebug(self, msg, level=xbmc.LOGDEBUG):
        if isDebug() == True:
            log('Artdownloader: ' + msg, level)

    def getFallback_Arttype(self, arttype):
        arttype = arttype.lower()
        arttype = arttype.replace('landscape', 'fanart')
        arttype = arttype.replace('folder', 'poster')
        arttype = arttype.replace('clearart', 'logo')
        arttype = arttype.replace('character', 'logo')
        self.log("getFallback_Arttype = " + arttype)
        return arttype

    def searchDetails(self, file_detail, arttype):
        self.log("searchDetails")
        for f in file_detail:
            try:
                arttypes = re.search(('"%s" *: *"(.*?)"' % arttype), f)
                arttypes_fallback = re.search(
                    ('"%s" *: *"(.*?)"' % self.getFallback_Arttype(arttype)),
                    f)
                if arttypes != None and len(arttypes.group(1)) > 0:
                    return (unquote(
                        xbmc.translatePath(
                            (arttypes.group(1).split(','))[0]))).replace(
                                'image://',
                                '').replace('.jpg/',
                                            '.jpg').replace('.png/', '.png')
                elif arttypes_fallback != None and len(
                        arttypes_fallback.group(1)) > 0:
                    if (arttypes_fallback.group(1)).lower() == (
                            self.getFallback_Arttype(arttype)).lower():
                        return (unquote(
                            xbmc.translatePath(
                                (arttypes_fallback.group(1).split(','))[0]))
                                ).replace('image://', '').replace(
                                    '.jpg/', '.jpg').replace('.png/', '.png')
            except:
                pass

    def dbidArt(self, type, chname, mpath, dbid, arttypeEXT):
        self.log("dbidArt")
        file_detail = []
        try:
            if type == 'tvshow':
                json_query = (
                    '{"jsonrpc":"2.0","method":"VideoLibrary.GetTVShowDetails","params":{"tvshowid":%s,"properties":["art","thumbnail","fanart"]},"id":1}'
                    % dbid)
            elif type == 'movie':
                json_query = (
                    '{"jsonrpc":"2.0","method":"VideoLibrary.GetMovieDetails","params":{"movieid":%s,"properties":["art","thumbnail","fanart"]},"id":1}'
                    % dbid)
            arttype = (arttypeEXT.split(".")[0])
            json_folder_detail = self.chanlist.sendJSON(json_query)
            file_detail = re.compile("{(.*?)}",
                                     re.DOTALL).findall(json_folder_detail)
            return self.searchDetails(file_detail, arttype)
        except Exception, e:
            self.log("dbidArt, Failed" + str(e), xbmc.LOGERROR)
class Artdownloader:

    def __init__(self):
        self.chanlist = ChannelList()
        self.fanarttv = fanarttv()
        self.tvdbAPI = tvdb.TVDB(TVDB_API_KEY)
        self.tmdbAPI = tmdb.TMDB(TMDB_API_KEY)  
        
        
    def log(self, msg, level = xbmc.LOGDEBUG):
        log('Artdownloader: ' + msg, level)

    
    def logDebug(self, msg, level = xbmc.LOGDEBUG):
        if DEBUG == 'true':
            log('Artdownloader: ' + msg, level)
    
    
    def dbidArt(self, type, chname, mpath, dbid, arttypeEXT):
        self.log("dbidArt")
        # Set image place-holder
        thumbnail = self.SetDefaultArt(chname, mpath, arttypeEXT)
 
        if type == 'tvshow':
            json_query = ('{"jsonrpc":"2.0","method":"VideoLibrary.GetTVShowDetails","params":{"tvshowid":%s,"properties":["art"]},"id":1}' % dbid)
        elif type == 'movie':
            json_query = ('{"jsonrpc":"2.0","method":"VideoLibrary.GetMovieDetails","params":{"movieid":%s,"properties":["art"]},"id":1}' % dbid)
        else:
            return thumbnail
            
        arttype = (arttypeEXT.split(".")[0]).replace('landscape','fanart')
        json_folder_detail = self.chanlist.sendJSON(json_query)
        file_detail = re.compile( "{(.*?)}", re.DOTALL ).findall(json_folder_detail)
        
        for f in file_detail:
            arttypes = re.search(('"%s" *: *"(.*?)"' % arttype), f)
            if arttypes != None and len(arttypes.group(1)) > 0:
                thumbnail = (unquote(xbmc.translatePath((arttypes.group(1).split(','))[0]))).replace('image://','').replace('.jpg/','.jpg').replace('.png/','.png')
                break   
        self.log("dbidArt, thumbnail = " + thumbnail)    
        return thumbnail

        
    def JsonThumb(self, chname, arttypeEXT, mediapath, media='video'):
        self.log("JsonThumb")
        file_detail = []
        # Set image place-holder
        thumbnail = self.SetDefaultArt(chname, mpath, arttypeEXT)
        json_query = ('{jsonrpc":"2.0","method":"Files.GetDirectory","params":{"directory":"%s","properties":["thumbnail"]}, "id": 1}' % (self.chanlist.escapeDirJSON(mediapath)))
        json_folder_detail = self.chanlist.sendJSON(json_query)
        file_detail = re.compile( "{(.*?)}", re.DOTALL ).findall(json_folder_detail)
        
        for f in file_detail:      
            thumbnails = re.search('"thumbnail" *: *"(.*?)"', f)                               
            if thumbnails != None and len(thumbnails.group(1)) > 0:
                thumbnail = (unquote(xbmc.translatePath((thumbnails.group(1).split(','))[0]))).replace('image://','').replace('.jpg/','.jpg').replace('.png/','.png')
                break

        self.log("JsonThumb, thumbnail = " + thumbnail)
        return thumbnail
    
    
    def AlphaLogo(self, org, mod):
        self.log("AlphaLogo")
        img = Image.open(org)
        img = img.convert("RGBA")
        datas = img.getdata()
        newData = []
        for item in datas:
            if item[0] == 255 and item[1] == 255 and item[2] == 255:
                newData.append((255, 255, 255, 0))
            else:
                newData.append(item)
        img.putdata(newData)
        img.save(mod, "PNG")
                
        
    #Covert to transparent logo
    def ConvertBug(self, org, mod):
        self.log("ConvertBug")
        drive, path = os.path.splitdrive(mod)
        path, filename = os.path.split(path)
        try:
            if not FileAccess.exists(path):
                FileAccess.makedirs(path)
            org =  xbmc.translatePath(org)
            original = Image.open(org)                  
            converted_img = original.convert('LA')  
            img_bright = ImageEnhance.Brightness(converted_img)
            converted_img = img_bright.enhance(1.0)     
            converted_img.save(mod)
            return mod
        except Exception,e:
            self.log("ConvertBug Failed! " + str(e))
            pass