def DownloadArt_Thread(self, data):
        self.log('DownloadArt_Thread')
        type = data[0]
        id = data[1]
        arttype = data[2]
        arttype_fallback = data[3]
        cachefile = data[4]
        print cachefile
        drive, Dpath = os.path.splitdrive(cachefile)
        path, filename = os.path.split(Dpath)
        print drive, Dpath, path, filename

        if not FileAccess.exists(os.path.join(drive,path)):
            FileAccess.makedirs(os.path.join(drive,path))   
                
        if type == 'tvshow':
            self.logDebug('DownloadArt_Thread, tvshow')
            FanTVDownload = True
            TVFilePath = cachefile
            tvdb_Types = ['banner', 'fanart', 'folder', 'poster']
                
            try:
                if arttype in tvdb_Types:
                    self.logDebug('DownloadArt_Thread, TVDB')
                    arttype = arttype.replace('banner', 'graphical').replace('folder', 'poster')
                    tvdb = str(self.tvdbAPI.getBannerByID(id, arttype))
                    tvdbPath = tvdb.split(', ')[0].replace("[('", "").replace("'", "") 
                    if tvdbPath.startswith('http'):
                        requestDownload(tvdbPath,TVFilePath)
                        FanTVDownload = False
            except Exception,e:
                self.log('DownloadArt_Thread, self.tvdbAPI Failed!')
                pass
                
            if FanTVDownload == True:
                self.logDebug('DownloadArt_Thread, Fanart.TV')
                try:
                    arttype = arttype.replace('graphical', 'banner').replace('folder', 'poster').replace('fanart', 'landscape')
                    fan = str(self.fanarttv.get_image_list_TV(id))
                    file_detail = re.compile( "{(.*?)}", re.DOTALL ).findall(fan)
                    pref_language = self.fanarttv.get_abbrev(REAL_SETTINGS.getSetting('limit_preferred_language'))
                    
                    for f in file_detail:
                        languages = re.search("'language' *: *(.*?),", f)
                        art_types = re.search("'art_type' *: *(.*?),", f)
                        fanPaths = re.search("'url' *: *(.*?),", f)       
                        if languages and len(languages.group(1)) > 0:
                            language = (languages.group(1)).replace("u'",'').replace("'",'')
                            if language == pref_language:
                                if art_types and len(art_types.group(1)) > 0:
                                    art_type = art_types.group(1).replace("u'",'').replace("'",'').replace("[",'').replace("]",'')
                                    if art_type.lower() == arttype.lower():
                                        if fanPaths and len(fanPaths.group(1)) > 0:
                                            fanPath = fanPaths.group(1).replace("u'",'').replace("'",'')
                                            if fanPath.startswith('http'):
                                                requestDownload(fanPath,TVFilePath)
                                                break 
                except:
                    pass
Example #2
0
    def DownloadArt(self, type, id, fle, typeEXT, ART_LOC):
        print ('DownloadArt')
        tvdbAPI = TVDB(TVDB_API_KEY)
        tmdbAPI = TMDB(TMDB_API_KEY)     
        
        if not FileAccess.exists(ART_LOC):
            FileAccess.makedirs(ART_LOC)

        ArtType = typeEXT.split('.')[0]        
        setImage = ''
        
        if type.lower() == 'tvshow':
            FanTVDownload = False
            TVFilePath = os.path.join(ART_LOC, fle) 
            tvdb_Types = ['banner', 'fanart', 'folder', 'poster']
            
            if ArtType in tvdb_Types:
                ArtType = ArtType.replace('banner', 'graphical').replace('folder', 'poster')
                tvdb = str(tvdbAPI.getBannerByID(id, ArtType))
                try:
                    tvdbPath = tvdb.split(', ')[0].replace("[('", "").replace("'", "") 
                    resource = urllib.urlopen(tvdbPath)
                    output = FileAccess.open(TVFilePath, 'w')
                    output.write(resource.read())
                    output.close()
                    return TVFilePath
                except Exception,e:
                    FanTVDownload = True
                    print ('tvdbAPI Failed!') 
                    pass
            else:
                FanTVDownload = True

            if FanTVDownload == True:
                ArtType = ArtType.replace('graphical', 'banner').replace('folder', 'poster').replace('fanart', 'tvfanart')
                fan = fanarttv.get_image_list_TV(id)
                try:
                    data = str(fan).replace("[", "").replace("]", "").replace("'", "")
                    data = data.split('}, {')
                    fanPath = str([s for s in data if ArtType in s]).split("', 'art_type: ")[0]
                    match = re.search("url *: *(.*?),", fanPath)
                    fanPath = match.group().replace(",", "").replace("url: u", "").replace("url: ", "")
                    resource = urllib.urlopen(fanPath)
                    output = FileAccess.open(TVFilePath, 'w')
                    output.write(resource.read())
                    output.close()
                    return TVFilePath
                except Exception,e:
                    print ('FanTVDownload Failed!') 
                    return ''   
Example #3
0
 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
 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 #5
0
 def ConvertBug(self, org, mod):
     self.log("ConvertBug")
     try:
         drive, path = os.path.splitdrive(mod)
         path, filename = os.path.split(path)
         if FileAccess.exists(path) == False:
             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), xbmc.LOGERROR)
         return os.path.join(IMAGES_LOC,'icon_mono.png')
 def ConvertBug(self, org, mod):
     self.log("ConvertBug")
     try:
         drive, path = os.path.splitdrive(mod)
         path, filename = os.path.split(path)
         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("script.pseudotv.live-Artdownloader: ConvertBug Failed " + str(e), xbmc.LOGERROR)
         return org
Example #7
0
    def ConvertBug(self, org, mod):
        self.log("ConvertBug")
        try:
            drive, path = os.path.splitdrive(mod)
            path, filename = os.path.split(path)
            if FileAccess.exists(path) == False:
                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), xbmc.LOGERROR)
            return os.path.join(IMAGES_LOC, 'icon_mono.png')
    def findMissingArt(self, type, id, arttype, cachefile, chname, mpath,
                       arttypeEXT):
        url = ''
        drive, Dpath = os.path.splitdrive(cachefile)
        path, filename = os.path.split(Dpath)

        if FileAccess.exists(os.path.join(drive, path)) == False:
            FileAccess.makedirs(os.path.join(drive, path))

        if type == 'tvshow':
            self.log('findMissingArt, tvshow')
            tvdb_Types = ['banner', 'fanart', 'folder', 'poster']

            if arttype in tvdb_Types:
                # correct database naming schema
                arttype = arttype.replace('banner', 'graphical').replace(
                    'folder', 'poster')
                url = self.findTVDBArt(type, id, arttype, arttypeEXT)
            if not url:
                # correct database naming schema
                arttype = arttype.replace('graphical', 'banner').replace(
                    'folder', 'poster')
                url = self.findFANTVArt(type, id, arttype, arttypeEXT)
            if url:
                return url

        elif type == 'movie':
            self.log('findMissingArt, movie')
            tmdb_Types = ['banner', 'fanart', 'folder', 'poster']

            if arttype in tmdb_Types:
                # correct database naming schema
                arttype = arttype.replace('folder', 'poster')
                url = self.findTMDBArt(type, id, arttype, arttypeEXT)
            if not url:
                # correct database naming schema
                arttype = arttype.replace('folder', 'poster')
                url = self.findFANTVArt(type, id, arttype, arttypeEXT)
            if url:
                return url
        # todo music artwork support
        # todo google image search, obdb, metahandler search
        return False
Example #9
0
    def ConvertBug(self, org, mod):
        self.log("ConvertBug")
        try:
            drive, path = os.path.splitdrive(mod)
            path, filename = os.path.split(path)
            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(
                "script.pseudotv.live-Artdownloader: ConvertBug Failed" +
                str(e), xbmc.LOGERROR)
            return 'NA.png'
Example #10
0
    def findMissingArt(self, type, id, arttype, cachefile, chname, mpath, arttypeEXT):
        url = ''
        drive, Dpath = os.path.splitdrive(cachefile)
        path, filename = os.path.split(Dpath)
        
        if FileAccess.exists(os.path.join(drive,path)) == False:
            FileAccess.makedirs(os.path.join(drive,path))   
                    
        if type == 'tvshow':
            self.log('findMissingArt, tvshow')
            tvdb_Types = ['banner', 'fanart', 'folder', 'poster']
                
            if arttype in tvdb_Types:
                # correct database naming schema
                arttype = arttype.replace('banner', 'graphical').replace('folder', 'poster')
                url = self.findTVDBArt(type, id, arttype, arttypeEXT)
            if not url:
                # correct database naming schema
                arttype = arttype.replace('graphical', 'banner').replace('folder', 'poster')
                url = self.findFANTVArt(type, id, arttype, arttypeEXT)
            if url:
                return url

        elif type == 'movie':
            self.log('findMissingArt, movie')
            tmdb_Types = ['banner', 'fanart', 'folder', 'poster']

            if arttype in tmdb_Types:
                # correct database naming schema
                arttype = arttype.replace('folder', 'poster')
                url = self.findTMDBArt(type, id, arttype, arttypeEXT)
            if not url:
                # correct database naming schema
                arttype = arttype.replace('folder', 'poster')
                url = self.findFANTVArt(type, id, arttype, arttypeEXT)
            if url:
                return url
        # todo music artwork support
        # todo google image search, obdb, metahandler search
        return False
Example #11
0
    def DownloadArt_Thread(self, type, id, arttype, cachefile, chname, mpath, arttypeEXT):
        self.log('DownloadArt_Thread')
        try:
            drive, Dpath = os.path.splitdrive(cachefile)
            path, filename = os.path.split(Dpath)

            if not FileAccess.exists(os.path.join(drive,path)):
                FileAccess.makedirs(os.path.join(drive,path))   
                    
            if type == 'tvshow':
                self.log('DownloadArt, tvshow')
                tvdb_Types = ['banner', 'fanart', 'folder', 'poster']
                    
                if arttype in tvdb_Types:
                    self.log('DownloadArt, TVDB')
                    arttype = arttype.replace('banner', 'graphical').replace('folder', 'poster')
                    tvdb = str(self.tvdbAPI.getBannerByID(id, arttype))
                    tvdbPath = tvdb.split(', ')[0].replace("[('", "").replace("'", "") 
                    if tvdbPath.startswith('http'):
                        self.log('DownloadArt, return TV TVDB')
                        return download_silent(tvdbPath,cachefile)
                
                self.log('DownloadArt, Fanart.TV')
                arttype = arttype.replace('graphical', 'banner').replace('folder', 'poster')
                fan = str(self.fanarttv.get_image_list_TV(id))
                file_detail = re.compile( "{(.*?)}", re.DOTALL ).findall(fan)
                pref_language = get_abbrev(REAL_SETTINGS.getSetting('limit_preferred_language'))
                print file_detail
                for f in file_detail:
                    try:
                        languages = re.search("'language' *: *(.*?),", f)
                        art_types = re.search("'art_type' *: *(.*?),", f)
                        fanPaths = re.search("'url' *: *(.*?),", f)       
                        if languages and len(languages.group(1)) > 0:
                            language = (languages.group(1)).replace("u'",'').replace("'",'')
                            if language.lower() == pref_language.lower():
                                if art_types and len(art_types.group(1)) > 0:
                                    art_type = art_types.group(1).replace("u'",'').replace("'",'').replace("[",'').replace("]",'')
                                    if art_type.lower() == arttype.lower():
                                        if fanPaths and len(fanPaths.group(1)) > 0:
                                            fanPath = fanPaths.group(1).replace("u'",'').replace("'",'')
                                            if fanPath.startswith('http'):
                                                self.log('DownloadArt, return TV Fanart.tv')
                                                return download_silent(fanPath,cachefile)
                    except:
                        pass

            elif type == 'movie':
                self.log('DownloadArt, movie')
                tmdb_Types = ['banner', 'fanart', 'folder', 'poster']

                if arttype in tmdb_Types:
                    self.log('DownloadArt, TMDB')
                    arttype = arttype.replace('folder', 'poster')
                    tmdb = self.tmdbAPI.get_image_list(id)
                    data = str(tmdb).replace("[", "").replace("]", "").replace("'", "")
                    data = data.split('}, {')
                    tmdbPath = str([s for s in data if arttype in s]).split("', 'width: ")[0]
                    match = re.search('url *: *(.*?),', tmdbPath)
                    if match:
                        tmdbPath = match.group().replace(",", "").replace("url: u", "").replace("url: ", "")
                        if tmdbPath.startswith('http'):
                            FanMovieDownload = False 
                            self.log('DownloadArt, return Movie TMDB')
                            return download_silent(tmdbPath,cachefile)

                self.log('DownloadArt, Fanart.TV')
                arttype = arttype.replace('folder', 'poster')
                fan = str(self.fanarttv.get_image_list_Movie(id))
                file_detail = re.compile( "{(.*?)}", re.DOTALL ).findall(fan)
                # print file_detail
                pref_language = get_abbrev(REAL_SETTINGS.getSetting('limit_preferred_language'))
                
                for f in file_detail:
                    try:
                        languages = re.search("'language' *: *(.*?),", f)
                        art_types = re.search("'art_type' *: *(.*?),", f)
                        fanPaths = re.search("'url' *: *(.*?),", f)    
                        if languages and len(languages.group(1)) > 0:
                            language = (languages.group(1)).replace("u'",'').replace("'",'')
                            if language.lower() == pref_language.lower():
                                if art_types and len(art_types.group(1)) > 0:
                                    art_type = art_types.group(1).replace("u'",'').replace("'",'').replace("[",'').replace("]",'')
                                    if art_type.lower() == arttype.lower():
                                        if fanPaths and len(fanPaths.group(1)) > 0:
                                            fanPath = fanPaths.group(1).replace("u'",'').replace("'",'')
                                            if fanPath.startswith('http'):
                                                self.log('DownloadArt, return Movie Fanart.tv')
                                                return download_silent(fanPath,cachefile)
                    except:
                        pass
            self.log('DownloadArt, Trying Fallback Download')
            self.DownloadArt(type, id, self.getFallback_Arttype(arttype), cachefile, chname, mpath, self.getFallback_Arttype(arttype))                
        except Exception,e:  
            self.log("DownloadArt, Failed!" + str(e), xbmc.LOGERROR)
            self.log(traceback.format_exc(), xbmc.LOGERROR)
Example #12
0
    def onInit(self):
        self.log('onInit')

        if FileAccess.exists(GEN_CHAN_LOC) == False:
            try:
                FileAccess.makedirs(GEN_CHAN_LOC)
            except:
                self.Error('Unable to create the cache directory')
                return

        if FileAccess.exists(MADE_CHAN_LOC) == False:
            try:
                FileAccess.makedirs(MADE_CHAN_LOC)
            except:
                self.Error('Unable to create the storage directory')
                return

        self.background = self.getControl(101)
        self.getControl(102).setVisible(False)
        self.background.setVisible(True)
        updateDialog = xbmcgui.DialogProgress()
        updateDialog.create("PseudoTV", "Initializing")
        updateDialog.update(5, "Initializing", "Grabbing Lock File")
        ADDON_SETTINGS.loadSettings()
        updateDialog.update(70, "Initializing", "Checking Other Instances")
        self.isMaster = GlobalFileLock.lockFile("MasterLock", False)
        updateDialog.update(95, "Initializing", "Migrating")

        if self.isMaster:
            migratemaster = Migrate()
            migratemaster.migrate()

        self.channelLabelTimer = threading.Timer(5.0, self.hideChannelLabel)
        self.playerTimer = threading.Timer(2.0, self.playerTimerAction)
        self.playerTimer.name = "PlayerTimer"
        self.infoTimer = threading.Timer(5.0, self.hideInfo)
        self.masterTimer = threading.Timer(5.0, self.becomeMaster)
        self.myEPG = EPGWindow("script.pseudotv.EPG.xml", ADDON_INFO, "default")
        self.myEPG.MyOverlayWindow = self
        # Don't allow any actions during initialization
        self.actionSemaphore.acquire()
        updateDialog.close()
        self.timeStarted = time.time()

        if self.readConfig() == False:
            return

        self.myEPG.channelLogos = self.channelLogos
        self.maxChannels = len(self.channels)

        if self.maxChannels == 0:
            self.Error('Unable to find any channels. Please configure the addon.')
            return

        found = False

        for i in range(self.maxChannels):
            if self.channels[i].isValid:
                found = True
                break

        if found == False:
            self.Error("Unable to populate channels. Please verify that you", "have scraped media in your library and that you have", "properly configured channels.")
            return

        if self.sleepTimeValue > 0:
            self.sleepTimer = threading.Timer(self.sleepTimeValue, self.sleepAction)

        self.notificationTimer = threading.Timer(NOTIFICATION_CHECK_TIME, self.notificationAction)

        try:
            if self.forceReset == False:
                self.currentChannel = self.fixChannel(int(REAL_SETTINGS.getSetting("CurrentChannel")))
            else:
                self.currentChannel = self.fixChannel(1)
        except:
            self.currentChannel = self.fixChannel(1)

        self.resetChannelTimes()
        self.setChannel(self.currentChannel)
        self.background.setVisible(False)
        self.startSleepTimer()
        self.startNotificationTimer()
        self.playerTimer.start()

        if self.backgroundUpdating < 2 or self.isMaster == False:
            self.channelThread.name = "ChannelThread"
            self.channelThread.start()

        if self.isMaster == False:
            self.masterTimer.name = "MasterTimer"
            self.masterTimer.start()

        self.actionSemaphore.release()
        self.log('onInit return')
Example #13
0
    def onInit(self):
        self.log('onInit')

        if FileAccess.exists(GEN_CHAN_LOC) == False:
            try:
                FileAccess.makedirs(GEN_CHAN_LOC)
            except:
                self.Error(LANGUAGE(30035))
                return

        if FileAccess.exists(MADE_CHAN_LOC) == False:
            try:
                FileAccess.makedirs(MADE_CHAN_LOC)
            except:
                self.Error(LANGUAGE(30036))
                return

        if FileAccess.exists(CHANNELBUG_LOC) == False:
                try:
                    FileAccess.makedirs(CHANNELBUG_LOC)
                except:
                    self.Error(LANGUAGE(30036))
                    return

        self.getControl(102).setVisible(False)
        self.backupFiles()
        ADDON_SETTINGS.loadSettings()

        if CHANNEL_SHARING:
            updateDialog = xbmcgui.DialogProgressBG()
            updateDialog.create(ADDON_NAME, '')
            updateDialog.update(1, message='Initializing Channel Sharing')
            FileAccess.makedirs(LOCK_LOC)
            updateDialog.update(50, message='Initializing Channel Sharing')
            self.isMaster = GlobalFileLock.lockFile("MasterLock", False)
            updateDialog.update(100, message='Initializing Channel Sharing')
            xbmc.sleep(200)
            updateDialog.close()
        else:
            self.isMaster = True

        if self.isMaster:
            migratemaster = Migrate()
            migratemaster.migrate()

        self.channelLabelTimer = threading.Timer(3.0, self.hideChannelLabel)
        self.playerTimer = threading.Timer(2.0, self.playerTimerAction)
        self.playerTimer.name = "PlayerTimer"
        self.infoTimer = threading.Timer(5.0, self.hideInfo)
        self.myEPG = EPGWindow("script.pseudotv.EPG.xml", CWD, "default")
        self.myEPG.MyOverlayWindow = self
        # Don't allow any actions during initialization
        self.actionSemaphore.acquire()
        self.timeStarted = time.time()

        if self.readConfig() == False:
            return

        self.myEPG.channelLogos = self.channelLogos
        self.maxChannels = len(self.channels)

        if self.maxChannels == 0:
            self.Error(LANGUAGE(30037))
            return

        found = False

        for i in range(self.maxChannels):
            if self.channels[i].isValid:
                found = True
                break

        if found == False:
            self.Error(LANGUAGE(30038))
            return

        if self.sleepTimeValue > 0:
            self.sleepTimer = threading.Timer(self.sleepTimeValue, self.sleepAction)

        self.notificationTimer = threading.Timer(NOTIFICATION_CHECK_TIME, self.notificationAction)

        try:
            if self.forceReset == False:
                self.currentChannel = self.fixChannel(int(ADDON.getSetting("CurrentChannel")))
            else:
                self.currentChannel = self.fixChannel(1)
        except:
            self.currentChannel = self.fixChannel(1)

        self.resetChannelTimes()
        self.setChannel(self.currentChannel)
        self.startSleepTimer()
        self.startNotificationTimer()
        self.playerTimer.start()

        if self.backgroundUpdating < 2 or self.isMaster == False:
            self.channelThread.name = "ChannelThread"
            self.channelThread.start()

        self.actionSemaphore.release()
        self.log('onInit return')
    def DownloadArt(self, type, id, fle, typeEXT, ART_LOC):
        self.log('DownloadArt')
        tvdbAPI = TVDB(TVDB_API_KEY)
        tmdbAPI = TMDB(TMDB_API_KEY)

        if not FileAccess.exists(ART_LOC):
            FileAccess.makedirs(ART_LOC)

        ArtType = typeEXT.split('.')[0]
        setImage = ''

        if type.lower() == 'tvshow':
            self.log('DownloadArt, tvshow')
            FanTVDownload = False
            TVFilePath = os.path.join(ART_LOC, fle)
            tvdb_Types = ['banner', 'fanart', 'folder', 'poster']

            if ArtType in tvdb_Types:
                self.log('DownloadArt, TVDB')
                ArtType = ArtType.replace('banner', 'graphical').replace(
                    'folder', 'poster')
                tvdb = str(tvdbAPI.getBannerByID(id, ArtType))
                try:
                    tvdbPath = tvdb.split(', ')[0].replace("[('", "").replace(
                        "'", "")
                    resource = urllib.urlopen(tvdbPath)
                    output = FileAccess.open(TVFilePath, 'w')
                    output.write(resource.read())
                    output.close()
                    return TVFilePath
                except Exception, e:
                    FanTVDownload = True
                    print('tvdbAPI Failed!')
                    pass
            else:
                FanTVDownload = True

            if FanTVDownload == True:
                self.log('DownloadArt, Fanart.TV')
                TVFilePath = ''
                ArtType = ArtType.replace('graphical', 'banner').replace(
                    'folder', 'poster').replace('fanart', 'landscape')
                fan = str(fanarttv.get_image_list_TV(id))
                file_detail = re.compile("{(.*?)}", re.DOTALL).findall(fan)
                pref_language = fanarttv.get_abbrev(
                    REAL_SETTINGS.getSetting('limit_preferred_language'))

                for f in file_detail:
                    languages = re.search("'language' *: *(.*?),", f)
                    art_types = re.search("'art_type' *: *(.*?),", f)
                    fanPaths = re.search("'url' *: *(.*?),", f)

                    if languages and len(languages.group(1)) > 0:
                        language = (languages.group(1)).replace("u'",
                                                                '').replace(
                                                                    "'", '')

                        if language == pref_language:
                            print language

                            if art_types and len(art_types.group(1)) > 0:
                                art_type = art_types.group(1).replace(
                                    "u'", '').replace("'", '').replace(
                                        "[", '').replace("]", '')

                                if art_type.lower() == ArtType.lower():
                                    print art_type

                                    if fanPaths and len(fanPaths.group(1)) > 0:
                                        fanPath = fanPaths.group(1).replace(
                                            "u'", '').replace("'", '')
                                        print fanPath

                                        if fanPath.startswith('http'):
                                            resource = urllib.urlopen(fanPath)
                                            output = FileAccess.open(
                                                TVFilePath, 'w')
                                            output.write(resource.read())
                                            output.close()
                                            break
                return TVFilePath
Example #15
0
    def DownloadArt_Thread(self, data):
        self.logDebug('DownloadArt_Thread, data = ' + str(data))
        type = data[0]
        id = data[1]
        arttype = data[2]
        cachefile = data[3]
        chname = data[4]
        mpath = data[5]
        arttypeEXT = data[6]
        try:
            drive, Dpath = os.path.splitdrive(cachefile)
            path, filename = os.path.split(Dpath)

            if not FileAccess.exists(os.path.join(drive, path)):
                FileAccess.makedirs(os.path.join(drive, path))

            if type == 'tvshow':
                self.logDebug('DownloadArt_Thread, tvshow')
                tvdb_Types = ['banner', 'fanart', 'folder', 'poster']

                if arttype in tvdb_Types:
                    self.logDebug('DownloadArt_Thread, TVDB')
                    arttype = arttype.replace('banner', 'graphical').replace(
                        'folder', 'poster')
                    tvdb = str(self.tvdbAPI.getBannerByID(id, arttype))
                    tvdbPath = tvdb.split(', ')[0].replace("[('", "").replace(
                        "'", "")
                    if tvdbPath.startswith('http'):
                        self.logDebug('DownloadArt_Thread, return TV TVDB')
                        return download_silent(tvdbPath, cachefile)

                self.logDebug('DownloadArt_Thread, Fanart.TV')
                arttype = arttype.replace('graphical', 'banner').replace(
                    'folder', 'poster')
                fan = str(self.fanarttv.get_image_list_TV(id))
                file_detail = re.compile("{(.*?)}", re.DOTALL).findall(fan)
                pref_language = get_abbrev(
                    REAL_SETTINGS.getSetting('limit_preferred_language'))

                for f in file_detail:
                    try:
                        languages = re.search("'language' *: *(.*?),", f)
                        art_types = re.search("'art_type' *: *(.*?),", f)
                        fanPaths = re.search("'url' *: *(.*?),", f)
                        if languages and len(languages.group(1)) > 0:
                            language = (languages.group(1)).replace(
                                "u'", '').replace("'", '')
                            if language.lower() == pref_language.lower():
                                if art_types and len(art_types.group(1)) > 0:
                                    art_type = art_types.group(1).replace(
                                        "u'", '').replace("'", '').replace(
                                            "[", '').replace("]", '')
                                    if art_type.lower() == arttype.lower():
                                        if fanPaths and len(
                                                fanPaths.group(1)) > 0:
                                            fanPath = fanPaths.group(
                                                1).replace("u'", '').replace(
                                                    "'", '')
                                            if fanPath.startswith('http'):
                                                self.logDebug(
                                                    'DownloadArt_Thread, return TV Fanart.tv'
                                                )
                                                return download_silent(
                                                    fanPath, cachefile)
                    except:
                        pass

            elif type == 'movie':
                self.logDebug('DownloadArt_Thread, movie')
                tmdb_Types = ['banner', 'fanart', 'folder', 'poster']

                if arttype in tmdb_Types:
                    self.logDebug('DownloadArt_Thread, TMDB')
                    arttype = arttype.replace('folder', 'poster')
                    tmdb = self.tmdbAPI.get_image_list(id)
                    data = str(tmdb).replace("[",
                                             "").replace("]",
                                                         "").replace("'", "")
                    data = data.split('}, {')
                    tmdbPath = str([s for s in data
                                    if arttype in s]).split("', 'width: ")[0]
                    match = re.search('url *: *(.*?),', tmdbPath)
                    if match:
                        tmdbPath = match.group().replace(",", "").replace(
                            "url: u", "").replace("url: ", "")
                        if tmdbPath.startswith('http'):
                            FanMovieDownload = False
                            self.logDebug(
                                'DownloadArt_Thread, return Movie TMDB')
                            return download_silent(tmdbPath, cachefile)

                self.logDebug('DownloadArt_Thread, Fanart.TV')
                arttype = arttype.replace('folder', 'poster')
                fan = str(self.fanarttv.get_image_list_Movie(id))
                file_detail = re.compile("{(.*?)}", re.DOTALL).findall(fan)
                # print file_detail
                pref_language = get_abbrev(
                    REAL_SETTINGS.getSetting('limit_preferred_language'))

                for f in file_detail:
                    try:
                        languages = re.search("'language' *: *(.*?),", f)
                        art_types = re.search("'art_type' *: *(.*?),", f)
                        fanPaths = re.search("'url' *: *(.*?),", f)
                        if languages and len(languages.group(1)) > 0:
                            language = (languages.group(1)).replace(
                                "u'", '').replace("'", '')
                            if language.lower() == pref_language.lower():
                                if art_types and len(art_types.group(1)) > 0:
                                    art_type = art_types.group(1).replace(
                                        "u'", '').replace("'", '').replace(
                                            "[", '').replace("]", '')
                                    if art_type.lower() == arttype.lower():
                                        if fanPaths and len(
                                                fanPaths.group(1)) > 0:
                                            fanPath = fanPaths.group(
                                                1).replace("u'", '').replace(
                                                    "'", '')
                                            if fanPath.startswith('http'):
                                                self.logDebug(
                                                    'DownloadArt_Thread, return Movie Fanart.tv'
                                                )
                                                return download_silent(
                                                    fanPath, cachefile)
                    except:
                        pass
            self.logDebug('DownloadArt_Thread, Trying Fallback Download')
            self.DownloadArt(type, id, self.getFallback_Arttype(arttype),
                             cachefile, chname, mpath,
                             self.getFallback_Arttype(arttype))
        except Exception, e:
            self.log("DownloadArt_Thread, Failed!" + str(e), xbmc.LOGERROR)
Example #16
0
    def onInit(self):
        self.log('onInit')

        if FileAccess.exists(GEN_CHAN_LOC) == False:
            try:
                FileAccess.makedirs(GEN_CHAN_LOC)
            except:
                self.Error('Unable to create the cache directory')
                return

        if FileAccess.exists(MADE_CHAN_LOC) == False:
            try:
                FileAccess.makedirs(MADE_CHAN_LOC)
            except:
                self.Error('Unable to create the storage directory')
                return

        self.background = self.getControl(101)
        self.getControl(102).setVisible(False)
        self.background.setVisible(True)
        updateDialog = xbmcgui.DialogProgress()
        updateDialog.create("PseudoTV", "Initializing")
        updateDialog.update(5, "Initializing", "Grabbing Lock File")
        ADDON_SETTINGS.loadSettings()
        updateDialog.update(70, "Initializing", "Checking Other Instances")
        self.isMaster = GlobalFileLock.lockFile("MasterLock", False)
        updateDialog.update(95, "Initializing", "Migrating")

        if self.isMaster:
            migratemaster = Migrate()
            migratemaster.migrate()

        self.channelLabelTimer = threading.Timer(5.0, self.hideChannelLabel)
        self.playerTimer = threading.Timer(2.0, self.playerTimerAction)
        self.playerTimer.name = "PlayerTimer"
        self.infoTimer = threading.Timer(5.0, self.hideInfo)
        self.masterTimer = threading.Timer(5.0, self.becomeMaster)
        self.myEPG = EPGWindow("script.pseudotv.EPG.xml", ADDON_INFO,
                               "default")
        self.myEPG.MyOverlayWindow = self
        # Don't allow any actions during initialization
        self.actionSemaphore.acquire()
        updateDialog.close()
        self.timeStarted = time.time()

        if self.readConfig() == False:
            return

        self.myEPG.channelLogos = self.channelLogos
        self.maxChannels = len(self.channels)

        if self.maxChannels == 0:
            self.Error(
                'Unable to find any channels. Please configure the addon.')
            return

        found = False

        for i in range(self.maxChannels):
            if self.channels[i].isValid:
                found = True
                break

        if found == False:
            self.Error("Unable to populate channels. Please verify that you",
                       "have scraped media in your library and that you have",
                       "properly configured channels.")
            return

        if self.sleepTimeValue > 0:
            self.sleepTimer = threading.Timer(self.sleepTimeValue,
                                              self.sleepAction)

        self.notificationTimer = threading.Timer(NOTIFICATION_CHECK_TIME,
                                                 self.notificationAction)

        try:
            if self.forceReset == False:
                self.currentChannel = self.fixChannel(
                    int(REAL_SETTINGS.getSetting("CurrentChannel")))
            else:
                self.currentChannel = self.fixChannel(1)
        except:
            self.currentChannel = self.fixChannel(1)

        self.resetChannelTimes()
        self.setChannel(self.currentChannel)
        self.background.setVisible(False)
        self.startSleepTimer()
        self.startNotificationTimer()
        self.playerTimer.start()

        if self.backgroundUpdating < 2 or self.isMaster == False:
            self.channelThread.name = "ChannelThread"
            self.channelThread.start()

        if self.isMaster == False:
            self.masterTimer.name = "MasterTimer"
            self.masterTimer.start()

        self.actionSemaphore.release()
        self.log('onInit return')
    def FindBug(self, chtype, chname, mediapath):
        print 'FindBug' 
        print chtype, chname, mediapath
        setImage = ''
        BugName = (chname + '.png')
        BugCache = os.path.join(LOGO_CACHE_LOC,BugName)
        BugFolder = os.path.join(LOGO_LOC,BugName)
        BugDefault = os.path.join(IMAGES_LOC,'Default.png')
        BugDefault_YT = os.path.join(IMAGES_LOC,'Youtube.png')

        if REAL_SETTINGS.getSetting('UNAlter_ChanBug') == 'false':
                    
            if not FileAccess.exists(LOGO_CACHE_LOC):
                FileAccess.makedirs(LOGO_CACHE_LOC)
        
            if FileAccess.exists(BugCache):
                print ('Find Local Cache Bug')
                setImage = BugCache
                
            elif FileAccess.exists(BugFolder):
                print ('Find Local Logo Bug')
                BugCache = self.ConvertBug(BugFolder, BugCache)
                setImage = BugCache
                
            # elif mediapath.startswith('plugin://'):
                # ###########################
                # print ('Find Plugin Bug')
                # try:
                    # plugin = (os.path.split(mediapath)[0]).replace('plugin://','')
                    # icon = 'special://home/addons/'+plugin+ '/icon.png'
                    # fanart = 'special://home/addons/'+plugin+ '/fanart.jpg'
                    # youtube = ['plugin.video.bromix.youtube', 'plugin.video.youtube']
                    
                    # if plugin in youtube:
                        # ###########################
                        # print ('Find Plugin Bug - Youtube')
                        # setImage = BugDefault_YT

                    # else:
                        # ###########################
                        # print ('Find Plugin Bug - Icon')
                        # print icon
                        # print BugCache
                        # if FileAccess.exists(xbmc.translatePath(icon)):
                            # print 'aa'
                            # BugCache = self.ConvertBug(icon, BugCache)
                            # setImage = BugCache
                # except:
                    # print 'Find Plugin Bug, Error'
                    # setImage = BugDefault
                    # pass     

            else:
                setImage = BugDefault
        else:
            if FileAccess.exists(BugFolder):
                setImage = BugFolder
            else:
                setImage = BugDefault

        print 'FindBug return', setImage
        return setImage
Example #18
0
    def onInit(self):
        self.log('onInit')

        if FileAccess.exists(GEN_CHAN_LOC) == False:
            try:
                FileAccess.makedirs(GEN_CHAN_LOC)
            except:
                self.Error(REAL_SETTINGS.getLocalizedString(30035))
                return

        if FileAccess.exists(MADE_CHAN_LOC) == False:
            try:
                FileAccess.makedirs(MADE_CHAN_LOC)
            except:
                self.Error(REAL_SETTINGS.getLocalizedString(30036))
                return
                
        if FileAccess.exists(CHANNELBUG_LOC) == False:
                try:
                    FileAccess.makedirs(CHANNELBUG_LOC)
                except:
                    self.Error(REAL_SETTINGS.getLocalizedString(30036))
                    return

        self.background = self.getControl(101)
        self.getControl(102).setVisible(False)
        self.background.setVisible(True)
        updateDialog = xbmcgui.DialogProgress()
        updateDialog.create("PseudoTV", "Initializing")
        self.backupFiles(updateDialog)
        ADDON_SETTINGS.loadSettings()
        
        if CHANNEL_SHARING:
            FileAccess.makedirs(LOCK_LOC)
            updateDialog.update(70, "Initializing", "Checking Other Instances")
            self.isMaster = GlobalFileLock.lockFile("MasterLock", False)
        else:
            self.isMaster = True

        updateDialog.update(95, "Initializing", "Migrating")

        if self.isMaster:
            migratemaster = Migrate()
            migratemaster.migrate()

        self.channelLabelTimer = threading.Timer(5.0, self.hideChannelLabel)
        self.playerTimer = threading.Timer(2.0, self.playerTimerAction)
        self.playerTimer.name = "PlayerTimer"
        self.infoTimer = threading.Timer(5.0, self.hideInfo)
        self.myEPG = EPGWindow("script.pseudotv.EPG.xml", ADDON_INFO, "default")
        self.myEPG.MyOverlayWindow = self
        # Don't allow any actions during initialization
        self.actionSemaphore.acquire()
        updateDialog.close()
        self.timeStarted = time.time()

        if self.readConfig() == False:
            return

        self.myEPG.channelLogos = self.channelLogos
        self.maxChannels = len(self.channels)

        if self.maxChannels == 0:
            self.Error(REAL_SETTINGS.getLocalizedString(30037))
            return

        found = False

        for i in range(self.maxChannels):
            if self.channels[i].isValid:
                found = True
                break

        if found == False:
            self.Error(REAL_SETTINGS.getLocalizedString(30038))
            return

        if self.sleepTimeValue > 0:
            self.sleepTimer = threading.Timer(self.sleepTimeValue, self.sleepAction)

        self.notificationTimer = threading.Timer(NOTIFICATION_CHECK_TIME, self.notificationAction)

        try:
            if self.forceReset == False:
                self.currentChannel = self.fixChannel(int(REAL_SETTINGS.getSetting("CurrentChannel")))
            else:
                self.currentChannel = self.fixChannel(1)
        except:
            self.currentChannel = self.fixChannel(1)

        self.resetChannelTimes()
        self.setChannel(self.currentChannel)
        self.background.setVisible(False)
        self.startSleepTimer()
        self.startNotificationTimer()
        self.playerTimer.start()

        if self.backgroundUpdating < 2 or self.isMaster == False:
            self.channelThread.name = "ChannelThread"
            self.channelThread.start()

        self.actionSemaphore.release()
        self.log('onInit return')
Example #19
0
    def DownloadArt(self, type, id, arttype, cachefile):
        self.log('DownloadArt')
        setImage = ''
        tvdbAPI = TVDB(TVDB_API_KEY)
        tmdbAPI = TMDB(TMDB_API_KEY)
        drive, Dpath = os.path.splitdrive(cachefile)
        path, filename = os.path.split(Dpath)

        if not FileAccess.exists(os.path.join(drive, path)):
            FileAccess.makedirs(os.path.join(drive, path))

        if type == 'tvshow':
            self.logDebug('DownloadArt, tvshow')
            FanTVDownload = True
            TVFilePath = cachefile
            tvdb_Types = ['banner', 'fanart', 'folder', 'poster']

            try:
                if arttype in tvdb_Types:
                    self.logDebug('DownloadArt, TVDB')
                    arttype = arttype.replace('banner', 'graphical').replace(
                        'folder', 'poster')
                    tvdb = str(tvdbAPI.getBannerByID(id, arttype))
                    tvdbPath = tvdb.split(', ')[0].replace("[('", "").replace(
                        "'", "")
                    if tvdbPath.startswith('http'):
                        requestDownload(tvdbPath, TVFilePath)
                        FanTVDownload = False
            except Exception, e:
                self.log('DownloadArt, tvdbAPI Failed!')
                pass

            if FanTVDownload == True:
                self.logDebug('DownloadArt, Fanart.TV')
                try:
                    arttype = arttype.replace('graphical', 'banner').replace(
                        'folder', 'poster').replace('fanart', 'landscape')
                    fan = str(fanarttv.get_image_list_TV(id))
                    file_detail = re.compile("{(.*?)}", re.DOTALL).findall(fan)
                    pref_language = fanarttv.get_abbrev(
                        REAL_SETTINGS.getSetting('limit_preferred_language'))

                    for f in file_detail:
                        languages = re.search("'language' *: *(.*?),", f)
                        art_types = re.search("'art_type' *: *(.*?),", f)
                        fanPaths = re.search("'url' *: *(.*?),", f)
                        if languages and len(languages.group(1)) > 0:
                            language = (languages.group(1)).replace(
                                "u'", '').replace("'", '')
                            if language == pref_language:
                                if art_types and len(art_types.group(1)) > 0:
                                    art_type = art_types.group(1).replace(
                                        "u'", '').replace("'", '').replace(
                                            "[", '').replace("]", '')
                                    if art_type.lower() == arttype.lower():
                                        if fanPaths and len(
                                                fanPaths.group(1)) > 0:
                                            fanPath = fanPaths.group(
                                                1).replace("u'", '').replace(
                                                    "'", '')
                                            if fanPath.startswith('http'):
                                                requestDownload(
                                                    fanPath, TVFilePath)
                                                break
                except:
                    pass

            # self.DownloadThread = threading.Timer(5.0, requestDownload,(url,TVFilePath))
            # self.DownloadThread.name = "DownloadThread"

            # if self.DownloadThread.isAlive():
            # self.DownloadThread.join()
            # else:
            # self.DownloadThread.start()
            return TVFilePath
Example #20
0
    def DownloadArt_Thread(self, data):
        self.log('DownloadArt_Thread')
        try:
            if getProperty("PseudoTVRunning") == "True":   
                type = data[0]
                id = data[1]
                arttype = data[2]
                arttype_fallback = data[3]
                cachefile = data[4]
                chname = data[5]
                mpath = data[6]
                arttypeEXT = data[7]
                
                # print cachefile
                drive, Dpath = os.path.splitdrive(cachefile)
                path, filename = os.path.split(Dpath)
                # print drive, Dpath, path, filename

                if not FileAccess.exists(os.path.join(drive,path)):
                    FileAccess.makedirs(os.path.join(drive,path))   
                        
                if type == 'tvshow':
                    self.logDebug('DownloadArt_Thread, tvshow')
                    FanTVDownload = True
                    TVFilePath = cachefile
                    tvdb_Types = ['banner', 'fanart', 'folder', 'poster']
                        
                    try:
                        if arttype in tvdb_Types:
                            self.logDebug('DownloadArt_Thread, TVDB')
                            arttype = arttype.replace('banner', 'graphical').replace('folder', 'poster')
                            tvdb = str(self.tvdbAPI.getBannerByID(id, arttype))
                            tvdbPath = tvdb.split(', ')[0].replace("[('", "").replace("'", "") 
                            if tvdbPath.startswith('http'):
                                download_silent(tvdbPath,TVFilePath)
                                FanTVDownload = False
                    except Exception,e:
                        self.log("script.pseudotv.live-Artdownloader: DownloadArt_Thread, TVDB Failed" + str(e), xbmc.LOGERROR)
                        buggalo.onExceptionRaised() 
                        
                    if FanTVDownload == True:
                        self.logDebug('DownloadArt_Thread, Fanart.TV')
                        try:
                            arttype = arttype.replace('graphical', 'banner').replace('folder', 'poster').replace('fanart', 'landscape')
                            fan = str(self.fanarttv.get_image_list_TV(id))
                            file_detail = re.compile( "{(.*?)}", re.DOTALL ).findall(fan)
                            pref_language = self.fanarttv.get_abbrev(REAL_SETTINGS.getSetting('limit_preferred_language'))
                            
                            for f in file_detail:
                                languages = re.search("'language' *: *(.*?),", f)
                                art_types = re.search("'art_type' *: *(.*?),", f)
                                fanPaths = re.search("'url' *: *(.*?),", f)       
                                if languages and len(languages.group(1)) > 0:
                                    language = (languages.group(1)).replace("u'",'').replace("'",'')
                                    if language == pref_language:
                                        if art_types and len(art_types.group(1)) > 0:
                                            art_type = art_types.group(1).replace("u'",'').replace("'",'').replace("[",'').replace("]",'')
                                            if art_type.lower() == arttype.lower():
                                                if fanPaths and len(fanPaths.group(1)) > 0:
                                                    fanPath = fanPaths.group(1).replace("u'",'').replace("'",'')
                                                    if fanPath.startswith('http'):
                                                        download_silent(fanPath,TVFilePath)
                                                        break 
                        except Exception,e:  
                            self.log("script.pseudotv.live-Artdownloader: DownloadArt_Thread, Fanart.TV Failed" + str(e), xbmc.LOGERROR)
                            buggalo.onExceptionRaised() 
                        
                elif type == 'movie':
                    self.logDebug('DownloadArt_Thread, movie')
                    FanMovieDownload = True
                    MovieFilePath = cachefile
                    tmdb_Types = ['fanart', 'folder', 'poster']
                    
                    try:
                        if arttype in tmdb_Types:
                            self.logDebug('DownloadArt_Thread, TMDB')
                            arttype = arttype.replace('folder', 'poster')
                            tmdb = self.tmdbAPI.get_image_list(id)
                            data = str(tmdb).replace("[", "").replace("]", "").replace("'", "")
                            data = data.split('}, {')
                            tmdbPath = str([s for s in data if arttype in s]).split("', 'width: ")[0]
                            match = re.search('url *: *(.*?),', tmdbPath)
                            if match:
                                tmdbPath = match.group().replace(",", "").replace("url: u", "").replace("url: ", "")
                                if tmdbPath.startswith('http'):
                                    download_silent(tmdbPath,MovieFilePath)
                                    FanMovieDownload = False
                    except Exception,e:  
                        self.log("script.pseudotv.live-Artdownloader: DownloadArt_Thread, movie Failed" + str(e), xbmc.LOGERROR)
                        buggalo.onExceptionRaised()