def SetDefaultArt(self, chname, mpath, arttypeEXT): self.log('SetDefaultArt, chname = ' + chname + ', arttypeEXT = ' + arttypeEXT) try: setImage = '' arttype = arttypeEXT.split(".")[0] MediaImage = os.path.join(MEDIA_LOC, (arttype + '.png')) StockImage = os.path.join(IMAGES_LOC, (arttype + '.png')) ChannelLogo = os.path.join(LOGO_LOC,chname[0:18] + '.png') if FileAccess.exists(ChannelLogo): self.log('SetDefaultArt, Channel Logo') return ChannelLogo elif mpath[0:6] == 'plugin': self.log('SetDefaultArt, Plugin Icon') icon = 'special://home/addons/'+(mpath.replace('plugin://',''))+ '/icon.png' return icon elif FileAccess.exists(MediaImage): self.log('SetDefaultArt, Media Image') return MediaImage elif FileAccess.exists(StockImage): self.log('SetDefaultArt, Stock Image') return StockImage else: self.log('SetDefaultArt, THUMB') return THUMB except Exception,e: self.log("script.pseudotv.live-Artdownloader: SetDefaultArt Failed" + str(e), xbmc.LOGERROR) self.log(traceback.format_exc(), xbmc.LOGERROR)
def SetDefaultArt(self, chname, mpath, arttypeEXT): self.log('SetDefaultArt') try: setImage = '' arttype = arttypeEXT.split(".")[0] MediaImage = os.path.join(MEDIA_LOC, (arttype + '.png')) StockImage = os.path.join(IMAGES_LOC, (arttype + '.png')) ChannelLogo = os.path.join(LOGO_LOC,chname + '.png') # Selected Skin Fallback ie (poster.jpg, landscape.jpg, logo.png, etc...) if FileAccess.exists(MediaImage) == True: self.log('SetDefaultArt, return MediaImage') return MediaImage # Channel Logo elif FileAccess.exists(ChannelLogo) == True: self.log('SetDefaultArt, return ChannelLogo') return ChannelLogo # Plugin Icon elif mpath[0:6] == 'plugin': icon = 'special://home/addons/'+(mpath.replace('plugin://',''))+ '/icon.png' self.log('SetDefaultArt, return plugin icon') return icon # Default Skin Fallback ie (poster.jpg, landscape.jpg, logo.png, etc...) elif FileAccess.exists(StockImage) == True: self.log('SetDefaultArt, return StockImage') return StockImage # PTVL Icon else: self.log('SetDefaultArt, return THUMB') return THUMB except Exception,e: self.log("script.pseudotv.live-Artdownloader: SetDefaultArt Failed" + str(e), xbmc.LOGERROR) return THUMB
def FindBug(self, chtype, chname): self.log("FindBug, chname = " + chname) try: FindBug_Type = int(REAL_SETTINGS.getSetting('Enable_ChannelBug')) OEMBugFLE_ANI = xbmc.translatePath(os.path.join(LOGO_LOC,(chname + '.gif'))) OEMBugFLE = xbmc.translatePath(os.path.join(LOGO_LOC,(chname + '.png'))) NEWBugFLE = xbmc.translatePath(os.path.join(LOGO_LOC,(chname + '_mono.png'))) OEMDefaultBugFLE = os.path.join(IMAGES_LOC,'logo.png') NEWDefaultBugFLE = os.path.join(IMAGES_LOC,'icon_mono.png') # no channel bug for livetv/internettv if chtype in [8,9]: return 'NA.png' if FindBug_Type > 0: if FindBug_Type == 3: if FileAccess.exists(OEMBugFLE_ANI) == True: return OEMBugFLE_ANI if FindBug_Type == 2: if FileAccess.exists(NEWBugFLE) == True: return NEWBugFLE if FileAccess.exists(NEWBugFLE) == False and FileAccess.exists(OEMBugFLE) == True: return self.ConvertBug(OEMBugFLE, NEWBugFLE) return NEWDefaultBugFLE if FileAccess.exists(OEMBugFLE) == True: return OEMBugFLE return OEMDefaultBugFLE except Exception,e: self.log("FindBug, Failed" + str(e), xbmc.LOGERROR) return 'NA.png'
def FindArtwork(self, type, chtype, chname, id, dbid, mpath, arttypeEXT): self.log("FindArtwork, type = " + type + ' :chtype = ' + str(chtype) + ' :chname = ' + chname + ' :id = ' + str(id) + ' :dbid = ' + str(dbid) + ' :mpath = ' + mpath + ' :arttypeEXT = ' + arttypeEXT) setImage = '' CacheArt = False DefaultArt = False arttype = arttypeEXT.split(".")[0] arttypeEXT_fallback = arttypeEXT.replace('landscape','fanart').replace('clearart','logo').replace('character','logo').replace('folder','poster') arttype_fallback = arttypeEXT_fallback.split(".")[0] if int(chtype) <= 7: self.logDebug('FindArtwork, Infolder Artwork') smpath = mpath.rsplit('/',2)[0] #Path Above mpath ie Series folder artSeries = xbmc.translatePath(os.path.join(smpath, arttypeEXT)) artSeason = xbmc.translatePath(os.path.join(mpath, arttypeEXT)) artSeries_fallback = xbmc.translatePath(os.path.join(smpath, arttypeEXT_fallback)) artSeason_fallback = xbmc.translatePath(os.path.join(mpath, arttypeEXT_fallback)) if FileAccess.exists(artSeries): return artSeries elif FileAccess.exists(artSeason): return artSeason elif FileAccess.exists(artSeries_fallback): return artSeries_fallback elif FileAccess.exists(artSeason_fallback): return artSeason_fallback else: return self.SetDefaultArt(chname, mpath, arttypeEXT)
def FindBug(self, chtype, chname): self.log("FindBug, chname = " + chname) try: setImage = '' BugFLE = xbmc.translatePath(os.path.join(LOGO_LOC,(chname + '.png'))) cachedthumb = xbmc.getCacheThumbName(BugFLE) cachefile = xbmc.translatePath(os.path.join(ART_LOC, cachedthumb[0], cachedthumb[:-4] + ".png")).replace("\\", "/") DefaultBug = self.getDefaultBug(chname) # no channel bug for livetv/internettv if chtype in [8,9]: return 'NA.png' else: if REAL_SETTINGS.getSetting('UNAlter_ChanBug') == 'true': if FileAccess.exists(BugFLE) == False: BugFLE = DefaultBug return BugFLE else: if FileAccess.exists(cachefile) == True: return cachefile elif FileAccess.exists(BugFLE) == False: return DefaultBug return self.ConvertBug(BugFLE, cachefile) except Exception,e: self.log("FindBug, Failed" + str(e), xbmc.LOGERROR) return 'NA.png'
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 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 else: setImage = BugDefault else: if FileAccess.exists(BugFolder): setImage = BugFolder else: setImage = BugDefault print 'FindBug return', setImage return setImage
def FindLogo(self, chtype, chname, mpath): self.logDebug("FindLogo") found = False setImage = '' LogoName = (chname[0:18] + '.png') LogoFolder = os.path.join(LOGO_LOC,LogoName) self.logoParser = lsHTMLParser() if FileAccess.exists(LogoFolder): return LogoFolder else: # if chtype == 1: # setImage = self.logoParser.retrieve_icon(chname) if chtype == 6 or chtype == 7: smpath = mpath.rsplit('/',2)[0] #Path Above mpath ie Series folder artSeries = xbmc.translatePath(os.path.join(smpath, 'logo.png')) artSeason = xbmc.translatePath(os.path.join(mpath, 'logo.png')) if FileAccess.exists(artSeries): setImage = artSeries elif FileAccess.exists(artSeason): setImage = artSeason # else: # if REAL_SETTINGS.getSetting('EnhancedGuideData') == 'true': # self.Fanart_Download('tvshow', 'logo', id, LogoFolder) if setImage.startswith('http'): requestDownload(setImage, LogoFolder) else: FileAccess.copy(setImage, LogoFolder) return LogoFolder
def FindArtwork_NEW(self, type, chtype, chname, id, dbid, mpath, arttypeEXT): self.logDebug("FindArtwork_NEW, type = " + type + ', chtype = ' + str(chtype) + ', chname = ' + chname + ', id = ' + str(id) + ', dbid = ' + str(dbid) + ', arttypeEXT = ' + arttypeEXT) setImage = THUMB CacheArt = False DefaultArt = False arttype = arttypeEXT.split(".")[0] arttypeEXT_fallback = arttypeEXT.replace('landscape','fanart').replace('clearart','logo').replace('character','logo').replace('folder','poster') arttype_fallback = arttypeEXT_fallback.split(".")[0] if chtype <= 7: self.logDebug('FindArtwork_NEW, Infolder Artwork') smpath = mpath.rsplit('/',2)[0] #Path Above mpath ie Series folder artSeries = xbmc.translatePath(os.path.join(smpath, arttypeEXT)) artSeason = xbmc.translatePath(os.path.join(mpath, arttypeEXT)) artSeries_fallback = xbmc.translatePath(os.path.join(smpath, arttypeEXT_fallback)) artSeason_fallback = xbmc.translatePath(os.path.join(mpath, arttypeEXT_fallback)) if FileAccess.exists(artSeries): return artSeries elif FileAccess.exists(artSeason): return artSeason elif FileAccess.exists(artSeries_fallback): return artSeries_fallback elif FileAccess.exists(artSeason_fallback): return artSeason_fallback elif dbid != '0': return self.dbidArt(type, chname, mpath, dbid, arttypeEXT) else: if id == '0': if type == 'youtube': self.logDebug('FindArtwork_NEW, Youtube') return "http://i.ytimg.com/vi/"+dbid+"/mqdefault.jpg" # return "http://img.youtube.com/vi/"+dbid+"/0.jpg" elif type == 'rss': self.logDebug('FindArtwork_NEW, RSS') if dbid != '0': return dbid.decode('base64') else: return self.SetDefaultArt_NEW(chname, mpath, arttypeEXT) # elif mpath[0:4] == 'upnp': # self.logDebug('FindArtwork_NEW, UPNP Thumb') # return self.JsonThumb(chname, arttypeEXT, mediapath) else: return self.SetDefaultArt_NEW(chname, mpath, arttypeEXT) else: self.logDebug('FindArtwork_NEW, Artwork Cache') fle = id + '-' + arttypeEXT ext = arttypeEXT.split('.')[1] url = os.path.join(mpath, fle) cachedthumb = xbmc.getCacheThumbName(url) cachefile = xbmc.translatePath(os.path.join(ART_LOC, cachedthumb[0], cachedthumb[:-4] + "." + ext)).replace("\\", "/") if FileAccess.exists(cachefile) == True: return cachefile else: if REAL_SETTINGS.getSetting('EnhancedGuideData') == 'true': self.logDebug('FindArtwork_NEW, Artwork Download') self.DownloadArt(type, id, arttype, arttype_fallback, cachefile) return cachefile
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): os.makedirs(ART_LOC) ArtType = typeEXT.split('.')[0] MediaImage = os.path.join(MEDIA_LOC, (ArtType + '.png')) DefaultImage = os.path.join(DEFAULT_MEDIA_LOC, (ArtType + '.png')) if FileAccess.exists(MediaImage): setImage = MediaImage elif FileAccess.exists(DefaultImage): setImage = DefaultImage else: setImage = '' if type == '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!') pass
def showChannelLabel(self, channel): self.log('showChannelLabel ' + str(channel)) if self.channelLabelTimer.isAlive(): self.channelLabelTimer.cancel() self.channelLabelTimer = threading.Timer(5.0, self.hideChannelLabel) tmp = self.inputChannel self.hideChannelLabel() self.inputChannel = tmp curlabel = 0 if channel > 99: self.channelLabel[curlabel].setImage(IMAGES_LOC + 'label_' + str(channel // 100) + '.png') self.channelLabel[curlabel].setVisible(True) curlabel += 1 if channel > 9: self.channelLabel[curlabel].setImage(IMAGES_LOC + 'label_' + str((channel % 100) // 10) + '.png') self.channelLabel[curlabel].setVisible(True) curlabel += 1 self.channelLabel[curlabel].setImage(IMAGES_LOC + 'label_' + str(channel % 10) + '.png') self.channelLabel[curlabel].setVisible(True) if self.inputChannel == -1 and self.infoOnChange == True: self.infoOffset = 0 self.showInfo(5.0) if self.showChannelBug == True: try: if not FileAccess.exists(self.channelLogos + ascii(self.channels[self.currentChannel - 1].name) + '.png'): self.getControl(103).setImage(IMAGES_LOC + 'Default2.png') original = Image.open(self.channelLogos + ascii(self.channels[self.currentChannel - 1].name) + '.png') converted_img = original.convert('LA') if not FileAccess.exists(CHANNELBUG_LOC + ascii(self.channels[self.currentChannel - 1].name) + '.png'): converted_img.save(CHANNELBUG_LOC + ascii(self.channels[self.currentChannel - 1].name) + '.png') self.getControl(103).setImage(CHANNELBUG_LOC + ascii(self.channels[self.currentChannel - 1].name) + '.png') except: pass else: try: self.getControl(103).setImage('') except: pass if xbmc.getCondVisibility('Player.ShowInfo'): json_query = '{"jsonrpc": "2.0", "method": "Input.Info", "id": 1}' self.ignoreInfoAction = True self.channelList.sendJSON(json_query); self.channelLabelTimer.name = "ChannelLabel" self.channelLabelTimer.start() self.startNotificationTimer(10.0) self.log('showChannelLabel return')
def Backup(org, bak): log("Backup " + str(org) + " - " + str(bak)) if FileAccess.exists(org): if FileAccess.exists(bak): try: xbmcvfs.delete(bak) except: pass FileAccess.copy(org, bak) if DEBUG == "true": xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % ("PseudoTV Lite", "Backup Complete", 1000, THUMB))
def Restore(bak, org): log("Restore " + str(bak) + " - " + str(org)) if FileAccess.exists(bak): if FileAccess.exists(org): try: xbmcvfs.delete(org) except: pass FileAccess.rename(bak, org) xbmc.executebuiltin( "Notification( %s, %s, %d, %s)" % ("PseudoTV Lite", "Restore Complete, Restarting...", 1000, THUMB) )
def setShowInfo(self): self.log('setShowInfo') if self.infoOffset > 0: self.getControl(502).setLabel(REAL_SETTINGS.getLocalizedString(30041)) elif self.infoOffset < 0: self.getControl(502).setLabel(REAL_SETTINGS.getLocalizedString(30042)) elif self.infoOffset == 0: self.getControl(502).setLabel(REAL_SETTINGS.getLocalizedString(30043)) if self.hideShortItems and self.infoOffset != 0: position = xbmc.PlayList(xbmc.PLAYLIST_MUSIC).getposition() curoffset = 0 modifier = 1 if self.infoOffset < 0: modifier = -1 while curoffset != abs(self.infoOffset): position = self.channels[self.currentChannel - 1].fixPlaylistIndex(position + modifier) if self.channels[self.currentChannel - 1].getItemDuration(position) >= self.shortItemLength: curoffset += 1 else: position = xbmc.PlayList(xbmc.PLAYLIST_MUSIC).getposition() + self.infoOffset self.getControl(503).setLabel(self.channels[self.currentChannel - 1].getItemTitle(position)) self.getControl(504).setLabel(self.channels[self.currentChannel - 1].getItemEpisodeTitle(position)) self.getControl(505).setLabel(self.channels[self.currentChannel - 1].getItemDescription(position)) self.getControl(506).setImage(self.channelLogos + ascii(self.channels[self.currentChannel - 1].name) + '.png') if not FileAccess.exists(self.channelLogos + ascii(self.channels[self.currentChannel - 1].name) + '.png'): self.getControl(506).setImage(IMAGES_LOC + 'Default.png') self.log('setShowInfo return')
def setShowInfo(self): self.log('setShowInfo') if self.infoOffset > 0: self.getControl(502).setLabel(LANGUAGE(30041)) elif self.infoOffset < 0: self.getControl(502).setLabel(LANGUAGE(30042)) elif self.infoOffset == 0: self.getControl(502).setLabel(LANGUAGE(30043)) if self.hideShortItems and self.infoOffset != 0: position = xbmc.PlayList(xbmc.PLAYLIST_MUSIC).getposition() curoffset = 0 modifier = 1 if self.infoOffset < 0: modifier = -1 while curoffset != abs(self.infoOffset): position = self.channels[self.currentChannel - 1].fixPlaylistIndex(position + modifier) if self.channels[self.currentChannel - 1].getItemDuration(position) >= self.shortItemLength: curoffset += 1 else: position = xbmc.PlayList(xbmc.PLAYLIST_MUSIC).getposition() + self.infoOffset self.getControl(503).setLabel(self.channels[self.currentChannel - 1].getItemTitle(position)) self.getControl(504).setLabel(self.channels[self.currentChannel - 1].getItemEpisodeTitle(position)) self.getControl(505).setText(self.channels[self.currentChannel - 1].getItemDescription(position)) self.getControl(506).setImage(self.channelLogos + ascii(self.channels[self.currentChannel - 1].name) + '.png') if not FileAccess.exists(self.channelLogos + ascii(self.channels[self.currentChannel - 1].name) + '.png'): self.getControl(506).setImage(IMAGES_LOC + 'Default.png') self.log('setShowInfo return')
def setShowInfo(self): self.log('setShowInfo') basex, basey = self.getControl(111 + self.focusRow).getPosition() baseh = self.getControl(111 + self.focusRow).getHeight() basew = self.getControl(111 + self.focusRow).getWidth() # use the selected time to set the video left, top = self.channelButtons[self.focusRow][self.focusIndex].getPosition() width = self.channelButtons[self.focusRow][self.focusIndex].getWidth() left = left - basex + (width / 2) starttime = self.shownTime + (left / (basew / 5400.0)) chnoffset = self.focusRow - 2 newchan = self.centerChannel while chnoffset != 0: if chnoffset > 0: newchan = self.MyOverlayWindow.fixChannel(newchan + 1, True) chnoffset -= 1 else: newchan = self.MyOverlayWindow.fixChannel(newchan - 1, False) chnoffset += 1 plpos = self.determinePlaylistPosAtTime(starttime, newchan) if plpos == -1: self.log('Unable to find the proper playlist to set from EPG') return self.getControl(500).setLabel(self.MyOverlayWindow.channels[newchan - 1].getItemTitle(plpos)) self.getControl(501).setLabel(self.MyOverlayWindow.channels[newchan - 1].getItemEpisodeTitle(plpos)) self.getControl(502).setText(self.MyOverlayWindow.channels[newchan - 1].getItemDescription(plpos)) self.getControl(503).setImage(self.channelLogos + ascii(self.MyOverlayWindow.channels[newchan - 1].name) + '.png') if not FileAccess.exists(self.channelLogos + ascii(self.MyOverlayWindow.channels[newchan - 1].name) + '.png'): self.getControl(503).setImage(IMAGES_LOC + 'Default.png') self.log('setShowInfo return')
def buildMixedFileList(self, dom1, channel): fileList = [] self.log('buildMixedFileList') try: rules = dom1.getElementsByTagName('rule') order = dom1.getElementsByTagName('order') except: self.log('buildMixedFileList Problem parsing playlist ' + filename, xbmc.LOGERROR) xml.close() return fileList for rule in rules: rulename = rule.childNodes[0].nodeValue if FileAccess.exists( xbmc.translatePath('special://profile/playlists/video/') + rulename): FileAccess.copy( xbmc.translatePath('special://profile/playlists/video/') + rulename, MADE_CHAN_LOC + rulename) fileList.extend( self.buildFileList(MADE_CHAN_LOC + rulename, channel)) else: fileList.extend( self.buildFileList(GEN_CHAN_LOC + rulename, channel)) self.log("buildMixedFileList returning") return fileList
def findMaxChannels(self): self.log('findMaxChannels') self.maxChannels = 0 self.enteredChannelCount = 0 for i in range(999): chtype = 9999 chsetting1 = '' chsetting2 = '' try: chtype = int( ADDON_SETTINGS.getSetting('Channel_' + str(i + 1) + '_type')) chsetting1 = ADDON_SETTINGS.getSetting('Channel_' + str(i + 1) + '_1') chsetting2 = ADDON_SETTINGS.getSetting('Channel_' + str(i + 1) + '_2') except: pass if chtype == 0: if FileAccess.exists(xbmc.translatePath(chsetting1)): self.maxChannels = i + 1 self.enteredChannelCount += 1 elif chtype < 8: if len(chsetting1) > 0: self.maxChannels = i + 1 self.enteredChannelCount += 1 if self.forceReset and (chtype != 9999): ADDON_SETTINGS.setSetting('Channel_' + str(i + 1) + '_changed', "True") self.log('findMaxChannels return ' + str(self.maxChannels))
def getVideoLength(self, filename): self.log("getVideoLength, " + filename) if len(filename) == 0: self.log("getVideoLength, No file name specified") return 0 if FileAccess.exists(filename) == False: if filename[0:6].lower() == 'smb://': self.log("getVideoLength, Unknown SMB file found, Trying to mount drive") filename = FileAccess._openSMB(filename) else: self.log("getVideoLength, Unable to find the file") return 0 base, ext = os.path.splitext(filename) ext = ext.lower() if ext in self.AVIExts: self.parser = AVIParser.AVIParser() elif ext in self.MP4Exts: self.parser = MP4Parser.MP4Parser() elif ext in self.MKVExts: self.parser = MKVParser.MKVParser() elif ext in self.FLVExts: self.parser = FLVParser.FLVParser() elif ext in self.TSExts: self.parser = TSParser.TSParser() elif ext in self.STRMExts: self.parser = STRMParser.STRMParser() else: self.log("getVideoLength, No parser found for extension " + ext) return 0 return self.parser.determineLength(filename)
def getSize(file): if FileAccess.exists(file): fileobject = FileAccess.open(file, "r") fileobject.seek(0, 2) # move the cursor to the end of the file size = fileobject.tell() fileobject.close() return size
def getVideoLength(self, filename): self.log("getVideoLength " + filename) if len(filename) == 0: self.log("No file name specified") return 0 if FileAccess.exists(filename) == False: self.log("Unable to find the file") return 0 base, ext = os.path.splitext(filename) ext = ext.lower() if ext in self.AVIExts: self.parser = AVIParser.AVIParser() elif ext in self.MP4Exts: self.parser = MP4Parser.MP4Parser() elif ext in self.MKVExts: self.parser = MKVParser.MKVParser() elif ext in self.FLVExts: self.parser = FLVParser.FLVParser() elif ext in self.TSExts: self.parser = TSParser.TSParser() else: self.log("No parser found for extension " + ext) return 0 return self.parser.determineLength(filename)
def setShowInfo(self): self.log('setShowInfo') basex, basey = self.getControl(111 + self.focusRow).getPosition() baseh = self.getControl(111 + self.focusRow).getHeight() basew = self.getControl(111 + self.focusRow).getWidth() # use the selected time to set the video left, top = self.channelButtons[self.focusRow][self.focusIndex].getPosition() width = self.channelButtons[self.focusRow][self.focusIndex].getWidth() left = left - basex + (width / 2) starttime = self.shownTime + (left / (basew / 5400.0)) chnoffset = self.focusRow - 2 newchan = self.centerChannel while chnoffset != 0: if chnoffset > 0: newchan = self.MyOverlayWindow.fixChannel(newchan + 1, True) chnoffset -= 1 else: newchan = self.MyOverlayWindow.fixChannel(newchan - 1, False) chnoffset += 1 plpos = self.determinePlaylistPosAtTime(starttime, newchan) if plpos == -1: self.log('Unable to find the proper playlist to set from EPG') return self.getControl(500).setLabel(self.MyOverlayWindow.channels[newchan - 1].getItemTitle(plpos)) self.getControl(501).setLabel(self.MyOverlayWindow.channels[newchan - 1].getItemEpisodeTitle(plpos)) self.getControl(502).setLabel(self.MyOverlayWindow.channels[newchan - 1].getItemDescription(plpos)) self.getControl(503).setImage(self.channelLogos + ascii(self.MyOverlayWindow.channels[newchan - 1].name) + '.png') if not FileAccess.exists(self.channelLogos + ascii(self.MyOverlayWindow.channels[newchan - 1].name) + '.png'): self.getControl(503).setImage(IMAGES_LOC + 'Default.png') self.log('setShowInfo return')
def findMaxChannels(self): self.log('findMaxChannels') self.maxChannels = 0 self.enteredChannelCount = 0 for i in range(999): chtype = 9999 chsetting1 = '' chsetting2 = '' try: chtype = int(ADDON_SETTINGS.getSetting('Channel_' + str(i + 1) + '_type')) chsetting1 = ADDON_SETTINGS.getSetting('Channel_' + str(i + 1) + '_1') chsetting2 = ADDON_SETTINGS.getSetting('Channel_' + str(i + 1) + '_2') except: pass if chtype == 0: if FileAccess.exists(xbmc.translatePath(chsetting1)): self.maxChannels = i + 1 self.enteredChannelCount += 1 elif chtype < 8: if len(chsetting1) > 0: self.maxChannels = i + 1 self.enteredChannelCount += 1 if self.forceReset and (chtype != 9999): ADDON_SETTINGS.setSetting('Channel_' + str(i + 1) + '_changed', "True") self.log('findMaxChannels return ' + str(self.maxChannels))
def getVideoLength(self, filename): self.log("getVideoLength" + filename) if len(filename) == 0: self.log("No file name specified") return 0 if FileAccess.exists(filename) == False: self.log("Unable to find the file") return 0 base, ext = os.path.splitext(filename) ext = ext.lower() if ext in self.AVIExts: self.parser = AVIParser.AVIParser() elif ext in self.MP4Exts: self.parser = MP4Parser.MP4Parser() elif ext in self.MKVExts: self.parser = MKVParser.MKVParser() elif ext in self.FLVExts: self.parser = FLVParser.FLVParser() elif ext in self.TSExts: self.parser = TSParser.TSParser() elif ext in self.STRMExts: self.parser = STRMParser.STRMParser() else: self.log("No parser found for extension " + ext) return 0 return self.parser.determineLength(filename)
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
def getSize(file): if FileAccess.exists(file): fileobject = FileAccess.open(file, "r") fileobject.seek(0,2) # move the cursor to the end of the file size = fileobject.tell() fileobject.close() return size
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
def FindBug(self, chtype, chname, mediapath): self.log("FindBug") setImage = '' BugName = (chname[0:18] + '.png') DefaultBug = os.path.join(IMAGES_LOC,'Default.png') BugFLE = xbmc.translatePath(os.path.join(LOGO_LOC,BugName)) if not FileAccess.exists(BugFLE): BugFLE = DefaultBug return BugFLE
def FindBug(self, chtype, chname): self.logDebug("FindBug, chname = " + chname) try: setImage = '' BugName = (chname[0:18] + '.png') BugFLE = xbmc.translatePath(os.path.join(LOGO_LOC, BugName)) cachedthumb = xbmc.getCacheThumbName(BugFLE) cachefile = xbmc.translatePath( os.path.join(ART_LOC, cachedthumb[0], cachedthumb[:-4] + ".png")).replace("\\", "/") if REAL_SETTINGS.getSetting('UNAlter_ChanBug') == 'true': if chname == 'OnDemand': DefaultBug = os.path.join(IMAGES_LOC, 'ondemand.png') else: DefaultBug = os.path.join(IMAGES_LOC, 'logo.png') else: if chname == 'OnDemand': DefaultBug = os.path.join(IMAGES_LOC, 'Default_ondemand.png') else: DefaultBug = os.path.join(IMAGES_LOC, 'Default.png') if chtype == 8: return 'NA.png' else: if REAL_SETTINGS.getSetting('UNAlter_ChanBug') == 'true': if not FileAccess.exists(BugFLE): BugFLE = DefaultBug return BugFLE else: if FileAccess.exists(cachefile): return cachefile else: if not FileAccess.exists(BugFLE): return DefaultBug else: return self.ConvertBug(BugFLE, cachefile) except Exception, e: self.log( "script.pseudotv.live-Artdownloader: FindBug Failed" + str(e), xbmc.LOGERROR) buggalo.onExceptionRaised()
def FindBug(self, chtype, chname): self.logDebug("FindBug, chname = " + chname) setImage = '' BugName = (chname[0:18] + '.png') DefaultBug = os.path.join(IMAGES_LOC,'Default.png') BugFLE = xbmc.translatePath(os.path.join(LOGO_LOC,BugName)) cachedthumb = xbmc.getCacheThumbName(BugFLE) cachefile = xbmc.translatePath(os.path.join(ART_LOC, cachedthumb[0], cachedthumb[:-4] + ".png")).replace("\\", "/") if REAL_SETTINGS.getSetting('UNAlter_ChanBug') == 'true': if not FileAccess.exists(BugFLE): BugFLE = DefaultBug return BugFLE else: if FileAccess.exists(cachefile): return cachefile else: if not FileAccess.exists(BugFLE): return DefaultBug else: return self.ConvertBug(BugFLE, cachefile)
def writeSettingsNew(self, updateDialog): self.log("writeSettingsNew") updateDialog.update(90, "Repairing Channel Configurations", "Saving Changes") if FileAccess.exists(Globals.SETTINGS_FLE_REPAIR): FileAccess.delete(Globals.SETTINGS_FLE_REPAIR) try: fle = FileAccess.open(Globals.SETTINGS_FLE_REPAIR, "w") except Exception,e: self.log("Unable to open the file for writing") return
def writeSettingsNew(self, updateDialog): self.log("writeSettingsNew") updateDialog.update(90, "Repairing Channel Configurations", "Saving Changes") if FileAccess.exists(self.repairfile): xbmcvfs.delete(self.repairfile) try: fle = FileAccess.open(self.repairfile, "w") except Exception,e: self.log("Unable to open the file for writing") return
def FindLogo(self, chtype, chname, mediapath): self.log("FindLogo") found = False setImage = '' LogoName = (chname[0:18] + '.png') LogoFolder = os.path.join(LOGO_LOC,LogoName) self.logoParser = lsHTMLParser() if FileAccess.exists(LogoFolder): setImage = LogoFolder else: setImage = 'NA.png' return setImage
def FindBug(self, chtype, chname): self.logDebug("FindBug, chname = " + chname) setImage = '' BugName = (chname[0:18] + '.png') DefaultBug = os.path.join(IMAGES_LOC, 'Default.png') BugFLE = xbmc.translatePath(os.path.join(LOGO_LOC, BugName)) cachedthumb = xbmc.getCacheThumbName(BugFLE) cachefile = xbmc.translatePath( os.path.join(ART_LOC, cachedthumb[0], cachedthumb[:-4] + ".png")).replace("\\", "/") if REAL_SETTINGS.getSetting('UNAlter_ChanBug') == 'true': if not FileAccess.exists(BugFLE): BugFLE = DefaultBug return BugFLE else: if FileAccess.exists(cachefile): return cachefile else: if not FileAccess.exists(BugFLE): return DefaultBug else: return self.ConvertBug(BugFLE, cachefile)
def setChannelBug(self): posx = self.channelBugPosition[0] posy = self.channelBugPosition[1] if self.showChannelBug: try: if not FileAccess.exists(self.channelLogos + ascii(self.channels[self.currentChannel - 1].name) + '.png'): self.getControl(103).setImage(IMAGES_LOC + 'Default2.png') self.getControl(103).setPosition(posx, posy) original = Image.open(self.channelLogos + ascii(self.channels[self.currentChannel - 1].name) + '.png') converted_img = original.convert('LA') img_bright = ImageEnhance.Brightness(converted_img) converted_img = img_bright.enhance(2.0) if not FileAccess.exists(CHANNELBUG_LOC + ascii(self.channels[self.currentChannel - 1].name) + '.png'): converted_img.save(CHANNELBUG_LOC + ascii(self.channels[self.currentChannel - 1].name) + '.png') self.getControl(103).setImage(CHANNELBUG_LOC + ascii(self.channels[self.currentChannel - 1].name) + '.png') self.getControl(103).setPosition(posx, posy) except: self.getControl(103).setImage(IMAGES_LOC + 'Default2.png') self.getControl(103).setPosition(posx, posy) else: self.getControl(103).setImage('')
def FindBug(self, chtype, chname): self.log("FindBug, chname = " + chname) try: setImage = '' BugName = (chname[0:18] + '.png') BugFLE = xbmc.translatePath(os.path.join(LOGO_LOC,BugName)) cachedthumb = xbmc.getCacheThumbName(BugFLE) cachefile = xbmc.translatePath(os.path.join(ART_LOC, cachedthumb[0], cachedthumb[:-4] + ".png")).replace("\\", "/") if REAL_SETTINGS.getSetting('UNAlter_ChanBug') == 'true': if chname == 'OnDemand': DefaultBug = os.path.join(IMAGES_LOC,'ondemand.png') else: DefaultBug = os.path.join(IMAGES_LOC,'logo.png') else: if chname == 'OnDemand': DefaultBug = os.path.join(IMAGES_LOC,'Default_ondemand.png') else: DefaultBug = os.path.join(IMAGES_LOC,'Default.png') if chtype in [8,9]: return 'NA.png' else: if REAL_SETTINGS.getSetting('UNAlter_ChanBug') == 'true': if not FileAccess.exists(BugFLE): BugFLE = DefaultBug return BugFLE else: if FileAccess.exists(cachefile): return cachefile else: if not FileAccess.exists(BugFLE): return DefaultBug else: return self.ConvertBug(BugFLE, cachefile) except Exception,e: self.log("FindBug, Failed" + str(e), xbmc.LOGERROR) return 'NA.png'
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 ''
def FindBug(self, chtype, chname): self.log("FindBug, chname = " + chname) try: FindBug_Type = int(REAL_SETTINGS.getSetting('Enable_ChannelBug')) OEMBugFLE_ANI = xbmc.translatePath( os.path.join(LOGO_LOC, (chname + '.gif'))) OEMBugFLE = xbmc.translatePath( os.path.join(LOGO_LOC, (chname + '.png'))) NEWBugFLE = xbmc.translatePath( os.path.join(LOGO_LOC, (chname + '_mono.png'))) OEMDefaultBugFLE = os.path.join(IMAGES_LOC, 'logo.png') NEWDefaultBugFLE = os.path.join(IMAGES_LOC, 'icon_mono.png') # no channel bug for livetv/internettv if chtype in [8, 9]: return 'NA.png' if FindBug_Type > 0: if FindBug_Type == 3: if FileAccess.exists(OEMBugFLE_ANI) == True: return OEMBugFLE_ANI if FindBug_Type == 2: if FileAccess.exists(NEWBugFLE) == True: return NEWBugFLE if FileAccess.exists( NEWBugFLE) == False and FileAccess.exists( OEMBugFLE) == True: return self.ConvertBug(OEMBugFLE, NEWBugFLE) return NEWDefaultBugFLE if FileAccess.exists(OEMBugFLE) == True: return OEMBugFLE return OEMDefaultBugFLE except Exception, e: self.log("FindBug, Failed" + str(e), xbmc.LOGERROR) return 'NA.png'
def SetDefaultArt(self, chname, mpath, arttypeEXT): self.log('SetDefaultArt') try: setImage = '' arttype = arttypeEXT.split(".")[0] MediaImage = os.path.join(MEDIA_LOC, (arttype + '.png')) StockImage = os.path.join(IMAGES_LOC, (arttype + '.png')) ChannelLogo = os.path.join(LOGO_LOC, chname + '.png') # Selected Skin Fallback ie (poster.jpg, landscape.jpg, logo.png, etc...) if FileAccess.exists(MediaImage) == True: self.log('SetDefaultArt, return MediaImage') return MediaImage # Channel Logo elif FileAccess.exists(ChannelLogo) == True: self.log('SetDefaultArt, return ChannelLogo') return ChannelLogo # Plugin Icon elif mpath[0:6] == 'plugin': icon = 'special://home/addons/' + (mpath.replace( 'plugin://', '')) + '/icon.png' self.log('SetDefaultArt, return plugin icon') return icon # Default Skin Fallback ie (poster.jpg, landscape.jpg, logo.png, etc...) elif FileAccess.exists(StockImage) == True: self.log('SetDefaultArt, return StockImage') return StockImage # PTVL Icon else: self.log('SetDefaultArt, return THUMB') return THUMB except Exception, e: self.log( "script.pseudotv.live-Artdownloader: SetDefaultArt Failed" + str(e), xbmc.LOGERROR) return THUMB
def SetDefaultArt(self, chname, mpath, arttypeEXT): self.log('SetDefaultArt') setImage = '' arttype = arttypeEXT.split(".")[0] MediaImage = os.path.join(MEDIA_LOC, (arttype + '.png')) StockImage = os.path.join(IMAGES_LOC, (arttype + '.png')) ChannelLogo = os.path.join(LOGO_LOC,chname[0:18] + '.png') if FileAccess.exists(ChannelLogo): self.logDebug('SetDefaultArt, Channel Logo') return ChannelLogo elif mpath[0:6] == 'plugin': self.logDebug('SetDefaultArt, Plugin Icon') icon = 'special://home/addons/'+(mpath.replace('plugin://',''))+ '/icon.png' return icon elif FileAccess.exists(MediaImage): self.logDebug('SetDefaultArt, Media Image') return MediaImage elif FileAccess.exists(StockImage): self.logDebug('SetDefaultArt, Stock Image') return StockImage else: self.logDebug('SetDefaultArt, THUMB') return THUMB
def readConfig(self): self.log('readConfig') # Sleep setting is in 30 minute incriments...so multiply by 30, and then 60 (min to sec) self.sleepTimeValue = int(ADDON.getSetting('AutoOff')) * 1800 self.log('Auto off is ' + str(self.sleepTimeValue)) self.infoOnChange = ADDON.getSetting("InfoOnChange") == "true" self.infoDuration = INFO_DUR[int(ADDON.getSetting("InfoLength"))] self.log('Show info label on channel change is ' + str(self.infoOnChange)) self.showChannelBug = ADDON.getSetting("ShowChannelBug") == "true" self.channelBugPosition = CHANNELBUG_POS[int( ADDON.getSetting("ChannelBugPosition"))] self.log('Show channel bug - ' + str(self.showChannelBug)) self.forceReset = ADDON.getSetting('ForceChannelReset') == "true" self.channelResetSetting = ADDON.getSetting('ChannelResetSetting') self.log("Channel reset setting - " + str(self.channelResetSetting)) self.channelLogos = xbmc.translatePath( ADDON.getSetting('ChannelLogoFolder')) self.backgroundUpdating = int(ADDON.getSetting("ThreadMode")) self.log("Background updating - " + str(self.backgroundUpdating)) self.showNextItem = ADDON.getSetting("EnableComingUp") == "true" self.log("Show Next Item - " + str(self.showNextItem)) self.hideShortItems = ADDON.getSetting("HideClips") == "true" self.log("Hide Short Items - " + str(self.hideShortItems)) self.shortItemLength = SHORT_CLIP_ENUM[int( ADDON.getSetting("ClipLength"))] self.seekForward = SEEK_FORWARD[int(ADDON.getSetting("SeekForward"))] self.seekBackward = SEEK_BACKWARD[int( ADDON.getSetting("SeekBackward"))] self.log("Short item length - " + str(self.shortItemLength)) if FileAccess.exists(self.channelLogos) == False: self.channelLogos = LOGOS_LOC self.log('Channel logo folder - ' + self.channelLogos) self.channelList = ChannelList() self.channelList.myOverlay = self self.channels = self.channelList.setupList() if self.channels is None: self.log('readConfig No channel list returned') self.end() return False self.Player.stop() self.log('readConfig return') return True
def PreArtService(self): print 'PreArtService' ADDON_SETTINGS.loadSettings() exclude = ['#EXTM3U', '#EXTINF'] i = 0 lineLST = [] newLST = [] ArtLST = [] for i in range(999): chtype = -1 id = -1 type = '' mpath = '' try: chtype = int( ADDON_SETTINGS.getSetting('Channel_' + str(i + 1) + '_type')) fle = xbmc.translatePath( os.path.join(LOCK_LOC, ("channel_" + str(i + 1) + '.m3u'))) except: pass if chtype >= 0: try: if FileAccess.exists(fle): f = FileAccess.open(fle, 'r') lineLST = f.readlines() lineLST.pop(0) #Remove unwanted first line '#EXTM3U' for n in range(len(lineLST)): line = lineLST[n] if line[0:7] == '#EXTINF': try: TV_liveid = (line.split('tvshow|')[1]) TV_liveid = 'tvshow|' + TV_liveid type = (TV_liveid.split('|'))[0] id = (TV_liveid.split('|'))[1] except Exception, e: MO_liveid = line.split('movie|')[1] MO_liveid = 'movie|' + MO_liveid type = MO_liveid.split('|')[0] id = MO_liveid.split('|')[1] except: 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
def readConfig(self): self.log('readConfig') # Sleep setting is in 30 minute incriments...so multiply by 30, and then 60 (min to sec) self.sleepTimeValue = int(REAL_SETTINGS.getSetting('AutoOff')) * 1800 self.log('Auto off is ' + str(self.sleepTimeValue)) self.infoOnChange = REAL_SETTINGS.getSetting("InfoOnChange") == "true" self.log('Show info label on channel change is ' + str(self.infoOnChange)) self.showChannelBug = REAL_SETTINGS.getSetting( "ShowChannelBug") == "true" self.log('Show channel bug - ' + str(self.showChannelBug)) self.forceReset = REAL_SETTINGS.getSetting( 'ForceChannelReset') == "true" self.channelResetSetting = REAL_SETTINGS.getSetting( 'ChannelResetSetting') self.log("Channel reset setting - " + str(self.channelResetSetting)) self.channelLogos = xbmc.translatePath( REAL_SETTINGS.getSetting('ChannelLogoFolder')) self.backgroundUpdating = int(REAL_SETTINGS.getSetting("ThreadMode")) self.log("Background updating - " + str(self.backgroundUpdating)) self.showNextItem = REAL_SETTINGS.getSetting( "EnableComingUp") == "true" self.log("Show Next Item - " + str(self.showNextItem)) self.hideShortItems = REAL_SETTINGS.getSetting("HideClips") == "true" self.log("Hide Short Items - " + str(self.hideShortItems)) self.shortItemLength = SHORT_CLIP_ENUM[int( REAL_SETTINGS.getSetting("ClipLength"))] self.log("Short item length - " + str(self.shortItemLength)) self.channelDelay = int(REAL_SETTINGS.getSetting("ChannelDelay")) * 250 if FileAccess.exists(self.channelLogos) == False: self.channelLogos = IMAGES_LOC self.log('Channel logo folder - ' + self.channelLogos) chn = ChannelList() chn.myOverlay = self self.channels = chn.setupList() if self.channels is None: self.log('readConfig No channel list returned') self.end() return False self.Player.stop() self.log('readConfig return') return True
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") 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
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
def ArtSpool(self, chtype, channel): print 'ArtSpool' print str(chtype), ' ', str(channel) type1EXT = '' type2EXT = '' exclude = ['#EXTM3U', '#EXTINF'] lineLST = [] newLST = [] ArtLST = [] id = -1 type = '' mpath = '' fle = xbmc.translatePath( os.path.join(LOCK_LOC, ("channel_" + str(channel) + '.m3u'))) global ArtService_Running if not ArtService_Running: ArtService_Running = True if chtype >= 0: try: if FileAccess.exists(fle): f = FileAccess.open(fle, 'r') lineLST = f.readlines() lineLST.pop(0) #Remove unwanted first line '#EXTM3U' for n in range(len(lineLST)): line = lineLST[n] if line[0:7] == '#EXTINF': try: TV_liveid = (line.split('tvshow|')[1]) TV_liveid = 'tvshow|' + TV_liveid type = (TV_liveid.split('|'))[0] id = (TV_liveid.split('|'))[1] except Exception, e: MO_liveid = line.split('movie|')[1] MO_liveid = 'movie|' + MO_liveid type = MO_liveid.split('|')[0] id = MO_liveid.split('|')[1] except: pass
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'
def loadSettings(self): self.log("Loading settings from " + self.logfile); del self.currentSettings[:] if FileAccess.exists(self.logfile): try: fle = FileAccess.open(self.logfile, "r") curset = fle.readlines() fle.close() except Exception,e: self.log("Exception when reading settings: ") self.log(traceback.format_exc(), xbmc.LOGERROR) for line in curset: name = re.search('setting id="(.*?)"', line) if name: val = re.search(' value="(.*?)"', line) if val: self.currentSettings.append([name.group(1), val.group(1)])
def loadSettings(self): self.log("Loading settings from " + self.logfile) del self.currentSettings[:] if FileAccess.exists(self.logfile): try: fle = FileAccess.open(self.logfile, "r") curset = fle.readlines() fle.close() except: pass for line in curset: name = re.search('setting id="(.*?)"', line) if name: val = re.search(' value="(.*?)"', line) if val: self.currentSettings.append( [name.group(1), val.group(1)])
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
def makeChannelList(self, channel, chtype, setting1, setting2, append=False): self.log('makeChannelList ' + str(channel)) israndom = False fileList = [] if chtype == 7: fileList = self.createDirectoryPlaylist(setting1) israndom = True else: if chtype == 0: if FileAccess.copy(setting1, MADE_CHAN_LOC + os.path.split(setting1)[1]) == False: if FileAccess.exists(MADE_CHAN_LOC + os.path.split(setting1)[1]) == False: self.log("Unable to copy or find playlist " + setting1) return False fle = MADE_CHAN_LOC + os.path.split(setting1)[1] else: fle = self.makeTypePlaylist(chtype, setting1, setting2) fle = uni(fle) if len(fle) == 0: self.log( 'Unable to locate the playlist for channel ' + str(channel), xbmc.LOGERROR) return False try: xml = FileAccess.open(fle, "r") except: self.log( "makeChannelList Unable to open the smart playlist " + fle, xbmc.LOGERROR) return False try: dom = parse(xml) except: self.log('makeChannelList Problem parsing playlist ' + fle, xbmc.LOGERROR) xml.close() return False xml.close() if self.getSmartPlaylistType(dom) == 'mixed': fileList = self.buildMixedFileList(dom, channel) else: fileList = self.buildFileList(fle, channel) try: order = dom.getElementsByTagName('order') if order[0].childNodes[0].nodeValue.lower() == 'random': israndom = True except: pass try: if append == True: channelplaylist = FileAccess.open( CHANNELS_LOC + "channel_" + str(channel) + ".m3u", "r") channelplaylist.seek(0, 2) channelplaylist.close() else: channelplaylist = FileAccess.open( CHANNELS_LOC + "channel_" + str(channel) + ".m3u", "w") except: self.log( 'Unable to open the cache file ' + CHANNELS_LOC + 'channel_' + str(channel) + '.m3u', xbmc.LOGERROR) return False if append == False: channelplaylist.write(uni("#EXTM3U\n")) if israndom: random.shuffle(fileList) if len(fileList) > 16384: fileList = fileList[:16384] fileList = self.runActions(RULES_ACTION_LIST, channel, fileList) self.channels[channel - 1].isRandom = israndom if append: if len(fileList) + self.channels[channel - 1].Playlist.size() > 16384: fileList = fileList[:( 16384 - self.channels[channel - 1].Playlist.size())] else: if len(fileList) > 16384: fileList = fileList[:16384] # Write each entry into the new playlist for string in fileList: channelplaylist.write(uni("#EXTINF:") + uni(string) + uni("\n")) channelplaylist.close() self.log('makeChannelList return') return True
def setupChannel(self, channel, background=False, makenewlist=False, append=False): self.log('setupChannel ' + str(channel)) returnval = False createlist = makenewlist chtype = 9999 chsetting1 = '' chsetting2 = '' needsreset = False self.background = background self.settingChannel = channel try: chtype = int( ADDON_SETTINGS.getSetting('Channel_' + str(channel) + '_type')) chsetting1 = ADDON_SETTINGS.getSetting('Channel_' + str(channel) + '_1') chsetting2 = ADDON_SETTINGS.getSetting('Channel_' + str(channel) + '_2') except: pass while len(self.channels) < channel: self.channels.append(Channel()) if chtype == 9999: self.channels[channel - 1].isValid = False return False self.channels[channel - 1].isSetup = True self.channels[channel - 1].loadRules(channel) self.runActions(RULES_ACTION_START, channel, self.channels[channel - 1]) try: needsreset = ADDON_SETTINGS.getSetting('Channel_' + str(channel) + '_changed') == 'True' if needsreset: self.channels[channel - 1].isSetup = False except: pass # If possible, use an existing playlist # Don't do this if we're appending an existing channel # Don't load if we need to reset anyway if FileAccess.exists(CHANNELS_LOC + 'channel_' + str(channel) + '.m3u' ) and append == False and needsreset == False: try: self.channels[channel - 1].totalTimePlayed = int( ADDON_SETTINGS.getSetting( 'Channel_' + str(channel) + '_time', True)) createlist = True if self.background == False: self.updateDialog.update(self.updateDialogProgress, "Loading channel " + str(channel), "reading playlist", '') if self.channels[channel - 1].setPlaylist(CHANNELS_LOC + 'channel_' + str(channel) + '.m3u') == True: self.channels[channel - 1].isValid = True self.channels[ channel - 1].fileName = CHANNELS_LOC + 'channel_' + str( channel) + '.m3u' returnval = True # If this channel has been watched for longer than it lasts, reset the channel if self.channelResetSetting == 0 and self.channels[ channel - 1].totalTimePlayed < self.channels[ channel - 1].getTotalDuration(): createlist = False if self.channelResetSetting > 0 and self.channelResetSetting < 4: timedif = time.time() - self.lastResetTime if self.channelResetSetting == 1 and timedif < ( 60 * 60 * 24): createlist = False if self.channelResetSetting == 2 and timedif < ( 60 * 60 * 24 * 7): createlist = False if self.channelResetSetting == 3 and timedif < ( 60 * 60 * 24 * 30): createlist = False if timedif < 0: createlist = False if self.channelResetSetting == 4: createlist = False except: pass if createlist or needsreset: self.channels[channel - 1].isValid = False if makenewlist: try: os.remove(CHANNELS_LOC + 'channel_' + str(channel) + '.m3u') except: pass append = False if createlist: ADDON_SETTINGS.setSetting('LastResetTime', str(int(time.time()))) if append == False: if chtype == 6 and chsetting2 == str(MODE_ORDERAIRDATE): self.channels[channel - 1].mode = MODE_ORDERAIRDATE # if there is no start mode in the channel mode flags, set it to the default if self.channels[channel - 1].mode & MODE_STARTMODES == 0: if self.startMode == 0: self.channels[channel - 1].mode |= MODE_RESUME elif self.startMode == 1: self.channels[channel - 1].mode |= MODE_REALTIME elif self.startMode == 2: self.channels[channel - 1].mode |= MODE_RANDOM if ((createlist or needsreset) and makenewlist) or append: if self.background == False: self.updateDialogProgress = ( channel - 1) * 100 // self.enteredChannelCount self.updateDialog.update(self.updateDialogProgress, "Updating channel " + str(channel), "adding videos", '') if self.makeChannelList(channel, chtype, chsetting1, chsetting2, append) == True: if self.channels[channel - 1].setPlaylist(CHANNELS_LOC + 'channel_' + str(channel) + '.m3u') == True: returnval = True self.channels[ channel - 1].fileName = CHANNELS_LOC + 'channel_' + str( channel) + '.m3u' self.channels[channel - 1].isValid = True # Don't reset variables on an appending channel if append == False: self.channels[channel - 1].totalTimePlayed = 0 ADDON_SETTINGS.setSetting( 'Channel_' + str(channel) + '_time', '0') if needsreset: ADDON_SETTINGS.setSetting( 'Channel_' + str(channel) + '_changed', 'False') self.channels[channel - 1].isSetup = True self.runActions(RULES_ACTION_BEFORE_CLEAR, channel, self.channels[channel - 1]) # Don't clear history when appending channels if self.background == False and append == False and self.myOverlay.isMaster: self.updateDialogProgress = (channel - 1) * 100 // self.enteredChannelCount self.updateDialog.update(self.updateDialogProgress, "Loading channel " + str(channel), "clearing history", '') self.clearPlaylistHistory(channel) if append == False: self.runActions(RULES_ACTION_BEFORE_TIME, channel, self.channels[channel - 1]) if self.channels[channel - 1].mode & MODE_ALWAYSPAUSE > 0: self.channels[channel - 1].isPaused = True if self.channels[channel - 1].mode & MODE_RANDOM > 0: self.channels[channel - 1].showTimeOffset = random.randint( 0, self.channels[channel - 1].getTotalDuration()) if self.channels[channel - 1].mode & MODE_REALTIME > 0: timedif = int(self.myOverlay.timeStarted) - self.lastExitTime self.channels[channel - 1].totalTimePlayed += timedif if self.channels[channel - 1].mode & MODE_RESUME > 0: self.channels[channel - 1].showTimeOffset = self.channels[ channel - 1].totalTimePlayed self.channels[channel - 1].totalTimePlayed = 0 while self.channels[channel - 1].showTimeOffset > self.channels[ channel - 1].getCurrentDuration(): self.channels[channel - 1].showTimeOffset -= self.channels[ channel - 1].getCurrentDuration() self.channels[channel - 1].addShowPosition(1) self.channels[channel - 1].name = self.getChannelName( chtype, chsetting1) if ((createlist or needsreset) and makenewlist) and returnval: self.runActions(RULES_ACTION_FINAL_MADE, channel, self.channels[channel - 1]) else: self.runActions(RULES_ACTION_FINAL_LOADED, channel, self.channels[channel - 1]) return returnval