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 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 createGenreMixedPlaylist(self, genre): if isinstance(genre, str): filegenre = genre.decode('ascii', 'ignore').encode( 'ascii' ) #note: this removes the character and encodes back to string. elif isinstance(genre, unicode): filegenre = genre.encode('ascii', 'ignore') flename = xbmc.makeLegalFilename(u''.join( (GEN_CHAN_LOC, 'Mixed_', filegenre, '.xsp')).encode('utf-8').strip()) try: fle = FileAccess.open(flename, "w") except: self.log(LANGUAGE(30034) + ' ' + flename, xbmc.LOGERROR) return '' epname = os.path.basename( self.createGenrePlaylist('episodes', 3, genre)) moname = os.path.basename(self.createGenrePlaylist('movies', 4, genre)) self.writeXSPHeader(fle, 'mixed', self.getChannelName(5, genre)) fle.write(' <rule field="playlist" operator="is">' + epname + '</rule>\n') fle.write(' <rule field="playlist" operator="is">' + moname + '</rule>\n') self.writeXSPFooter(fle, 0, "random") fle.close() return flename
def createNetworkPlaylist(self, network): flename = xbmc.makeLegalFilename(GEN_CHAN_LOC + 'Network_' + network + '.xsp') try: fle = FileAccess.open(flename, "w") except: self.log(LANGUAGE(30034) + ' ' + flename, xbmc.LOGERROR) return '' self.writeXSPHeader(fle, "episodes", self.getChannelName(1, network)) network = network.lower() added = False fle.write(' <rule field="tvshow" operator="is">\n') for i in range(len(self.showList)): if self.showList[i][1].lower() == network: theshow = self.cleanString(self.showList[i][0]) fle.write(' <value>' + theshow + '</value>\n') added = True fle.write(' </rule>\n') self.writeXSPFooter(fle, 0, "random") fle.close() if added == False: return '' return flename
def createGenrePlaylist(self, pltype, chtype, genre): if isinstance(genre, str): filegenre = genre.decode('ascii', 'ignore').encode( 'ascii' ) #note: this removes the character and encodes back to string. elif isinstance(genre, unicode): filegenre = genre.encode('ascii', 'ignore') flename = xbmc.makeLegalFilename(u''.join( (GEN_CHAN_LOC, pltype, '_', filegenre, '.xsp')).encode('utf-8').strip()) try: fle = FileAccess.open(flename, "w") except: self.log(LANGUAGE(30034) + ' ' + flename, xbmc.LOGERROR) return '' self.writeXSPHeader(fle, pltype, self.getChannelName(chtype, genre)) genre = self.cleanString(genre) fle.write(' <rule field="genre" operator="is">\n') fle.write(' <value>' + genre + '</value>\n') fle.write(' </rule>\n') self.writeXSPFooter(fle, 0, "random") fle.close() return flename
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 getSmartPlaylistName(self, fle): self.log('getSmartPlaylistName') fle = xbmc.translatePath(fle) try: xml = FileAccess.open(fle, "r") except: self.log( "getSmartPlaylisyName Unable to open the smart playlist " + fle, xbmc.LOGERROR) return '' try: dom = parse(xml) except: self.log('getSmartPlaylistName Problem parsing playlist ' + fle, xbmc.LOGERROR) xml.close() return '' xml.close() try: plname = dom.getElementsByTagName('name') self.log('getSmartPlaylistName return ' + plname[0].childNodes[0].nodeValue) return plname[0].childNodes[0].nodeValue except: self.log("Unable to get the playlist name.", xbmc.LOGERROR) return ''
def getSmartPlaylistName(self, fle): self.log("getSmartPlaylistName " + fle) fle = xbmc.translatePath(fle) try: xml = FileAccess.open(fle, "r") except: self.log('Unable to open smart playlist') return '' try: dom = parse(xml) except: xml.close() self.log("getSmartPlaylistName return unable to parse") return '' xml.close() try: plname = dom.getElementsByTagName('name') self.log("getSmartPlaylistName return " + plname[0].childNodes[0].nodeValue) return plname[0].childNodes[0].nodeValue except: self.playlisy('Unable to find element name') self.log("getSmartPlaylistName return")
def createShowPlaylist(self, show, setting2): order = 'random' try: setting = int(setting2) if setting & MODE_ORDERAIRDATE > 0: order = 'episode' except: pass flename = xbmc.makeLegalFilename(GEN_CHAN_LOC + 'Show_' + show + '_' + order + '.xsp') try: fle = FileAccess.open(flename, "w") except: self.log(LANGUAGE(30034) + ' ' + flename, xbmc.LOGERROR) return '' self.writeXSPHeader(fle, 'episodes', self.getChannelName(6, show)) show = self.cleanString(show) fle.write(' <rule field="tvshow" operator="is">\n') fle.write(' <value>' + show + '</value>\n') fle.write(' </rule>\n') self.writeXSPFooter(fle, 0, order) fle.close() return flename
def createNetworkPlaylist(self, network): flename = xbmc.makeLegalFilename(GEN_CHAN_LOC + 'Network_' + network + '.xsp') try: fle = FileAccess.open(flename, "w") except: self.Error('Unable to open the cache file ' + flename, xbmc.LOGERROR) return '' self.writeXSPHeader(fle, "episodes", self.getChannelName(1, network)) network = network.lower() added = False for i in range(len(self.showList)): if self.threadPause() == False: fle.close() return '' if self.showList[i][1].lower() == network: theshow = self.cleanString(self.showList[i][0]) fle.write(' <rule field="tvshow" operator="is">' + theshow + '</rule>\n') added = True self.writeXSPFooter(fle, 0, "random") fle.close() if added == False: return '' return flename
def createShowPlaylist(self, show, setting2): order = 'random' try: setting = int(setting2) if setting & MODE_ORDERAIRDATE > 0: order = 'airdate' except: pass flename = xbmc.makeLegalFilename(GEN_CHAN_LOC + 'Show_' + show + '_' + order + '.xsp') try: fle = FileAccess.open(flename, "w") except: self.Error('Unable to open the cache file ' + flename, xbmc.LOGERROR) return '' self.writeXSPHeader(fle, 'episodes', self.getChannelName(6, show)) show = self.cleanString(show) fle.write(' <rule field="tvshow" operator="is">' + show + '</rule>\n') self.writeXSPFooter(fle, 0, order) fle.close() return flename
def determineLength(self, filename): self.log("determineLength " + filename) self.pid = -1 try: self.File = FileAccess.open(filename, "rb", None) except: self.log("Unable to open the file") return self.filesize = self.getFileSize() self.packetLength = self.findPacketLength() if self.packetLength <= 0: return 0 start = self.getStartTime() self.log('Start - ' + str(start)) end = self.getEndTime() self.log('End - ' + str(end)) if end > start: dur = int((end - start) / 90000) else: dur = 0 self.File.close() self.log("Duration: " + str(dur)) return dur
def getSmartPlaylistName(self, fle): self.log('getSmartPlaylistName') fle = xbmc.translatePath(fle) try: xml = FileAccess.open(fle, "r") except: self.log("getSmartPlaylisyName Unable to open the smart playlist " + fle, xbmc.LOGERROR) return '' try: dom = parse(xml) except: self.log('getSmartPlaylistName Problem parsing playlist ' + fle, xbmc.LOGERROR) xml.close() return '' xml.close() try: plname = dom.getElementsByTagName('name') self.log('getSmartPlaylistName return ' + plname[0].childNodes[0].nodeValue) return plname[0].childNodes[0].nodeValue except: self.log("Unable to get the playlist name.", xbmc.LOGERROR) return ''
def determineLength(self, filename): self.log("determineLength " + filename) try: self.File = FileAccess.open(filename, "rb", None) except: self.log("Unable to open the file") return if self.verifyFLV() == False: self.log("Not a valid FLV") self.File.close() return 0 tagheader = self.findLastVideoTag() if tagheader is None: self.log("Unable to find a video tag") self.File.close() return 0 dur = self.getDurFromTag(tagheader) self.File.close() self.log("Duration: " + str(dur)) return dur
def DownloadMetaArt(self, type, fle, id, typeEXT, ART_LOC): self.log('DownloadMetaArt') ArtPath = os.path.join(ART_LOC, fle) setImage = '' if type == 'tvshow': Tid = id Mid = '' else: Mid = id Tid = '' typeEXT = typeEXT.split('.')[0] typeEXT = typeEXT.replace('landscape', 'backdrop_url').replace( 'fanart', 'backdrop_url').replace('logo', 'backdrop_url').replace( 'clearart', 'backdrop_url').replace('poster', 'cover_url').replace( 'banner', 'banner_url') try: self.log('DownloadMetaArt, metahander') self.metaget = metahandlers.MetaData(preparezip=False) ImageURL = str( self.metaget.get_meta(type, '', imdb_id=str(Mid), tmdb_id=str(Tid)))[typeEXT] resource = urllib.urlopen(ImageURL) output = FileAccess.open(ArtPath, 'w') output.write(resource.read()) output.close() setImage = ArtPath except Exception: buggalo.onExceptionRaised() return setImage
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 DownloadMetaArt(self, type, fle, id, typeEXT, ART_LOC): print ('DownloadMetaArt') ArtPath = os.path.join(ART_LOC, fle) if type == 'tvshow': Tid = id Mid = '' else: Mid = id Tid = '' typeEXT = typeEXT.split('.')[0] typeEXT = typeEXT.replace('landscape','backdrop_url').replace('fanart','backdrop_url').replace('logo','backdrop_url').replace('clearart','backdrop_url').replace('poster','cover_url').replace('banner','banner_url') # try: print 'metahander' self.metaget = metahandlers.MetaData(preparezip=False) ImageURL = str(self.metaget.get_meta(type, '', imdb_id=str(Mid), tmdb_id=str(Tid)))[typeEXT] resource = urllib.urlopen(ImageURL) output = FileAccess.open(ArtPath, 'w') output.write(resource.read()) output.close() setImage = ArtPath # except: # pass return setImage
def loadSettings(self): self.log("Loading settings from " + self.logfile) if Globals.GlobalFileLock.lockFile(self.logfile) == False: self.log("Unable to lock the settings file before loading it") 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)]) Globals.GlobalFileLock.unlockFile(self.logfile)
def loadSettings(self): self.log("Loading settings from " + self.logfile) del self.currentSettings[:] try: 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)]) except Exception, e: print str(e) return
def DownloadMetaArt(self, type, fle, id, typeEXT, ART_LOC): self.log('DownloadMetaArt') ArtPath = os.path.join(ART_LOC, fle) setImage = '' if type == 'tvshow': Tid = id Mid = '' else: Mid = id Tid = '' typeEXT = typeEXT.split('.')[0] typeEXT = typeEXT.replace('landscape','backdrop_url').replace('fanart','backdrop_url').replace('logo','backdrop_url').replace('clearart','backdrop_url').replace('poster','cover_url').replace('banner','banner_url') try: self.log('DownloadMetaArt, metahander') self.metaget = metahandlers.MetaData(preparezip=False) ImageURL = str(self.metaget.get_meta(type, '', imdb_id=str(Mid), tmdb_id=str(Tid)))[typeEXT] resource = urllib.urlopen(ImageURL) output = FileAccess.open(ArtPath, 'w') output.write(resource.read()) output.close() setImage = ArtPath except Exception,e: self.log("script.pseudotv.live-Artdownloader: DownloadMetaArt Failed" + str(e), xbmc.LOGERROR) self.log(traceback.format_exc(), xbmc.LOGERROR)
def save(self, filename): self.log("save " + filename) try: fle = FileAccess.open(filename, 'w') except Exception,e: self.log("save Unable to open the smart playlist", xbmc.LOGERROR) return
def clearPlaylistHistory(self, channel): self.log("clearPlaylistHistory") if self.channels[channel - 1].isValid == False: self.log("channel not valid, ignoring") return # if we actually need to clear anything if self.channels[channel - 1].totalTimePlayed > (60 * 60 * 24 * 2): try: fle = FileAccess.open( CHANNELS_LOC + 'channel_' + str(channel) + '.m3u', 'w') except: self.log( "clearPlaylistHistory Unable to open the smart playlist", xbmc.LOGERROR) return flewrite = uni("#EXTM3U\n") tottime = 0 timeremoved = 0 for i in range(self.channels[channel - 1].Playlist.size()): tottime += self.channels[channel - 1].getItemDuration(i) if tottime > (self.channels[channel - 1].totalTimePlayed - (60 * 60 * 12)): tmpstr = str( self.channels[channel - 1].getItemDuration(i)) + ',' tmpstr += self.channels[channel - 1].getItemTitle( i) + "//" + self.channels[ channel - 1].getItemEpisodeTitle(i) + "//" + self.channels[ channel - 1].getItemDescription(i) tmpstr = uni(tmpstr[:2036]) tmpstr = tmpstr.replace("\\n", " ").replace("\\r", " ").replace( "\\\"", "\"") tmpstr = uni(tmpstr) + uni('\n') + uni( self.channels[channel - 1].getItemFilename(i)) flewrite += uni("#EXTINF:") + uni(tmpstr) + uni("\n") else: timeremoved = tottime fle.write(flewrite) fle.close() if timeremoved > 0: if self.channels[channel - 1].setPlaylist(CHANNELS_LOC + 'channel_' + str(channel) + '.m3u') == False: self.channels[channel - 1].isValid = False else: self.channels[channel - 1].totalTimePlayed -= timeremoved # Write this now so anything sharing the playlists will get the proper info ADDON_SETTINGS.setSetting( 'Channel_' + str(channel) + '_time', str(self.channels[channel - 1].totalTimePlayed))
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 anonFTPDownload(filename, DL_LOC): log("anonFTPDownload, " + filename + " - " + DL_LOC) try: ftp = ftplib.FTP("ftp.pseudotvlive.com", "*****@*****.**", "*****@*****.**") ftp.cwd("/ptvl") file = FileAccess.open(DL_LOC, "w") ftp.retrbinary("RETR %s" % filename, file.write) file.close() ftp.quit() except: pass
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 anonFTPDownload(filename, DL_LOC): log('anonFTPDownload, ' + filename + ' - ' + DL_LOC) try: ftp = ftplib.FTP("ftp.pseudotvlive.com", "*****@*****.**", "*****@*****.**") ftp.cwd("/ptvl") file = FileAccess.open(DL_LOC, 'w') ftp.retrbinary('RETR %s' % filename, file.write) file.close() ftp.quit() except: pass
def determineLength(self, filename): self.log("determineLength " + filename) try: self.File = FileAccess.open(filename, "rb", None) except: self.log("Unable to open the file") return 0 dur = self.readHeader() self.File.close() self.log('Duration: ' + str(dur)) return dur
def writeSettings(self): try: fle = FileAccess.open(self.logfile, "w") except: self.log("Unable to open the file for writing") return flewrite = Globals.uni("<settings>\n") for i in range(len(self.currentSettings)): flewrite += Globals.uni(' <setting id="') + Globals.uni(self.currentSettings[i][0]) + Globals.uni('" value="') + Globals.uni(self.currentSettings[i][1]) + Globals.uni('" />\n') flewrite += Globals.uni('</settings>\n') fle.write(flewrite) fle.close()
def createGenrePlaylist(self, pltype, chtype, genre): flename = xbmc.makeLegalFilename(GEN_CHAN_LOC + pltype + '_' + genre + '.xsp') try: fle = FileAccess.open(flename, "w") except: self.Error('Unable to open the cache file ' + flename, xbmc.LOGERROR) return '' self.writeXSPHeader(fle, pltype, self.getChannelName(chtype, genre)) genre = self.cleanString(genre) fle.write(' <rule field="genre" operator="is">' + genre + '</rule>\n') self.writeXSPFooter(fle, 0, "random") fle.close() return flename
def createStudioPlaylist(self, studio): flename = xbmc.makeLegalFilename(GEN_CHAN_LOC + 'Studio_' + studio + '.xsp') try: fle = FileAccess.open(flename, "w") except: self.Error('Unable to open the cache file ' + flename, xbmc.LOGERROR) return '' self.writeXSPHeader(fle, "movies", self.getChannelName(2, studio)) studio = self.cleanString(studio) fle.write(' <rule field="studio" operator="is">' + studio + '</rule>\n') self.writeXSPFooter(fle, 0, "random") fle.close() return flename
def writeSettings(self): try: fle = FileAccess.open(self.logfile, "w") except: self.log("Unable to open the file for writing") return flewrite = Globals.uni("<settings>\n") for i in range(len(self.currentSettings)): flewrite += ' <setting id="' + self.currentSettings[i][ 0] + '" value="' + self.currentSettings[i][1] + '" />\n' flewrite += '</settings>\n' fle.write(flewrite) fle.close()
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 createGenreMixedPlaylist(self, genre): flename = xbmc.makeLegalFilename(GEN_CHAN_LOC + 'Mixed_' + genre + '.xsp') try: fle = FileAccess.open(flename, "w") except: self.Error('Unable to open the cache file ' + flename, xbmc.LOGERROR) return '' epname = os.path.basename(self.createGenrePlaylist('episodes', 3, genre)) moname = os.path.basename(self.createGenrePlaylist('movies', 4, genre)) self.writeXSPHeader(fle, 'mixed', self.getChannelName(5, genre)) fle.write(' <rule field="playlist" operator="is">' + epname + '</rule>\n') fle.write(' <rule field="playlist" operator="is">' + moname + '</rule>\n') self.writeXSPFooter(fle, 0, "random") fle.close() return flename
def createGenreMixedPlaylist(self, genre): flename = xbmc.makeLegalFilename(GEN_CHAN_LOC + 'Mixed_' + genre + '.xsp') try: fle = FileAccess.open(flename, "w") except: self.Error(LANGUAGE(30034) + ' ' + flename, xbmc.LOGERROR) return '' epname = os.path.basename(self.createGenrePlaylist('episodes', 3, genre)) moname = os.path.basename(self.createGenrePlaylist('movies', 4, genre)) self.writeXSPHeader(fle, 'mixed', self.getChannelName(5, genre)) fle.write(' <rule field="playlist" operator="is">' + epname + '</rule>\n') fle.write(' <rule field="playlist" operator="is">' + moname + '</rule>\n') self.writeXSPFooter(fle, 0, "random") fle.close() return flename
def load(self, filename): self.log("load " + filename) self.processingSemaphore.acquire() self.clear() try: fle = FileAccess.open(filename, 'r') except IOError: self.log('Unable to open the file: ' + filename) self.processingSemaphore.release() return False # find and read the header try: lines = fle.readlines() except Exception,e: self.log("ERROR loading playlist: " + filename) self.log(traceback.format_exc(), xbmc.LOGERROR)
def Download_URL(_in, _out): Finished = False if xbmcvfs.exists(_out): try: os.remove(_out) except: pass try: resource = urllib.urlopen(_in) output = FileAccess.open(_out, 'w') output.write(resource.read()) Finished = True output.close() except: pass return Finished
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 writeSettings(self): if Globals.GlobalFileLock.lockFile(self.logfile) == False: self.log("Unable to lock the settings file before writing it") try: fle = FileAccess.open(self.logfile, "w") except: self.log("Unable to open the file for writing") return flewrite = "<settings>\n" for i in range(len(self.currentSettings)): flewrite += ' <setting id="' + self.currentSettings[i][0] + '" value="' + self.currentSettings[i][1] + '" />\n' flewrite += '</settings>\n' fle.write(flewrite) fle.close() Globals.GlobalFileLock.unlockFile(self.logfile)
def determineWebServer(self): if self.discoveredWebServer: return self.discoveredWebServer = True self.webPort = 8080 self.webUsername = '' self.webPassword = '' fle = xbmc.translatePath("special://profile/guisettings.xml") try: xml = FileAccess.open(fle, "r") except: self.log("determineWebServer Unable to open the settings file", xbmc.LOGERROR) self.httpJSON = False return try: dom = parse(xml) except: self.log('determineWebServer Unable to parse settings file', xbmc.LOGERROR) self.httpJSON = False return xml.close() try: plname = dom.getElementsByTagName('webserver') self.httpJSON = (plname[0].childNodes[0].nodeValue.lower() == 'true') self.log('determineWebServer is ' + str(self.httpJSON)) if self.httpJSON == True: plname = dom.getElementsByTagName('webserverport') self.webPort = int(plname[0].childNodes[0].nodeValue) self.log('determineWebServer port ' + str(self.webPort)) plname = dom.getElementsByTagName('webserverusername') self.webUsername = plname[0].childNodes[0].nodeValue self.log('determineWebServer username ' + self.webUsername) plname = dom.getElementsByTagName('webserverpassword') self.webPassword = plname[0].childNodes[0].nodeValue self.log('determineWebServer password is ' + self.webPassword) except: return
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 clearPlaylistHistory(self, channel): self.log("clearPlaylistHistory") if self.channels[channel - 1].isValid == False: self.log("channel not valid, ignoring") return # if we actually need to clear anything if self.channels[channel - 1].totalTimePlayed > (60 * 60 * 24 * 2): try: fle = FileAccess.open(CHANNELS_LOC + 'channel_' + str(channel) + '.m3u', 'w') except: self.log("clearPlaylistHistory Unable to open the smart playlist", xbmc.LOGERROR) return flewrite = "#EXTM3U\n" tottime = 0 timeremoved = 0 for i in range(self.channels[channel - 1].Playlist.size()): tottime += self.channels[channel - 1].getItemDuration(i) if tottime > (self.channels[channel - 1].totalTimePlayed - (60 * 60 * 12)): tmpstr = str(self.channels[channel - 1].getItemDuration(i)) + ',' tmpstr += self.channels[channel - 1].getItemTitle(i) + "//" + self.channels[channel - 1].getItemEpisodeTitle(i) + "//" + self.channels[channel - 1].getItemDescription(i) tmpstr = tmpstr[:600] tmpstr = tmpstr.replace("\\n", " ").replace("\\r", " ").replace("\\\"", "\"") tmpstr = tmpstr + '\n' + self.channels[channel - 1].getItemFilename(i) flewrite += "#EXTINF:" + tmpstr + "\n" else: timeremoved = tottime fle.write(flewrite) fle.close() if timeremoved > 0: if self.channels[channel - 1].setPlaylist(CHANNELS_LOC + 'channel_' + str(channel) + '.m3u') == False: self.channels[channel - 1].isValid = False else: self.channels[channel - 1].totalTimePlayed -= timeremoved # Write this now so anything sharing the playlists will get the proper info ADDON_SETTINGS.setSetting('Channel_' + str(channel) + '_time', str(self.channels[channel - 1].totalTimePlayed))
def save(self, filename): self.log("save " + filename) try: fle = FileAccess.open(filename, 'w') except: self.log("save Unable to open the smart playlist", xbmc.LOGERROR) return flewrite = uni("#EXTM3U\n") for i in range(self.size()): tmpstr = str(self.getduration(i)) + ',' tmpstr += self.getTitle(i) + "//" + self.getepisodetitle(i) + "//" + self.getdescription(i) + "//" + self.getgenre(i) + "//" + self.gettimestamp(i) + "//" + self.getLiveID(i) tmpstr = tmpstr[:600] tmpstr = tmpstr.replace("\\n", " ").replace("\\r", " ").replace("\\\"", "\"") tmpstr = tmpstr + '\n' + self.getfilename(i) flewrite += "#EXTINF:" + tmpstr + "\n" fle.write(flewrite) fle.close()
def determineLength(self, filename): self.log("determineLength " + filename) try: self.File = FileAccess.open(filename, "rb", None) except: self.log("Unable to open the file") self.log(traceback.format_exc()) return size = self.findHeader() if size == 0: self.log('Unable to find the segment info') dur = 0 else: dur = self.parseHeader(size) self.log("Duration is " + str(dur)) return dur
def writeSettings(self): if Globals.GlobalFileLock.lockFile(self.logfile) == False: self.log("Unable to lock the settings file before writing it") try: fle = FileAccess.open(self.logfile, "w") except: self.log("Unable to open the file for writing") return flewrite = "<settings>\n" for i in range(len(self.currentSettings)): flewrite += ' <setting id="' + self.currentSettings[i][ 0] + '" value="' + self.currentSettings[i][1] + '" />\n' flewrite += '</settings>\n' fle.write(flewrite) fle.close() Globals.GlobalFileLock.unlockFile(self.logfile)
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 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 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)])