本文整理汇总了Python中xbmcvfs.exists函数的典型用法代码示例。如果您正苦于以下问题:Python exists函数的具体用法?Python exists怎么用?Python exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exists函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_advancedxml
def import_advancedxml():
userdatapath = xbmc.translatePath(os.path.join('special://home/userdata'.decode('utf-8'),''.decode('utf-8')))
advancedsettings_var = os.path.join(userdatapath,'advancedsettings.xml')
advancedsettingsbackup_var = os.path.join(userdatapath,'advancedsettingsbackup.xml')
if xbmcvfs.exists(advancedsettings_var):
print("An advanced settings XML file already exists")
if xbmcvfs.exists(advancedsettingsbackup_var):
print("An advanced settings backup already exists")
xbmcvfs.delete(advancedsettingsbackup_var)
xbmcvfs.rename(advancedsettings_var,advancedsettingsbackup_var)
advancedname = ["Cachemembuffer=252420","freememorycachepercent=5"]
advancedurl = ["http://p2p-strm.googlecode.com/svn/trunk/Advancedsettings/advancedsettings.xml","http://p2p-strm.googlecode.com/svn/trunk/Advancedsettings/advancedsettingstonicillo.xml"]
index = xbmcgui.Dialog().select(translate(40185), advancedname)
if index > -1:
download_tools().Downloader(advancedurl[index],advancedsettings_var,translate(40059),translate(40000))
mensagemok(translate(40000),translate(40060))
else:
xbmcvfs.rename(advancedsettings_var,advancedsettingsbackup_var)
advancedname = ["Cachemembuffer=252420","freememorycachepercent=5"]
advancedurl = ["http://p2p-strm.googlecode.com/svn/trunk/Advancedsettings/advancedsettings.xml","http://p2p-strm.googlecode.com/svn/trunk/Advancedsettings/advancedsettingstonicillo.xml"]
index = xbmcgui.Dialog().select(translate(40185), advancedname)
if index > -1:
download_tools().Downloader(advancedurl[index],advancedsettings_var,translate(40059),translate(40000))
mensagemok(translate(40000),translate(40060))
else:
print("No advancedsettings.xml in the system yet")
advancedname = ["Cachemembuffer=252420","freememorycachepercent=5"]
advancedurl = ["http://p2p-strm.googlecode.com/svn/trunk/Advancedsettings/advancedsettings.xml","http://p2p-strm.googlecode.com/svn/trunk/Advancedsettings/advancedsettingstonicillo.xml"]
index = xbmcgui.Dialog().select(translate(40185), advancedname)
if index > -1:
download_tools().Downloader(advancedurl[index],advancedsettings_var,translate(40059),translate(40000))
mensagemok(translate(40000),translate(40060))
xbmc.executebuiltin("Container.Refresh")
示例2: autostart
def autostart():
xbmcaddon.Addon().setSetting(id="files_overwrite", value='false')
settings = _settings()
settings._get_general()
addondir = xbmc.translatePath( utils.__addon__.getAddonInfo('profile') )
tempdir = os.path.join(addondir, 'temp')
service_runtime = str(settings.service_runtime + ':00')
log('Service - Run at startup: %s'%settings.service_startup, xbmc.LOGNOTICE)
log('Service - Delayed startup: %s minutes'%settings.service_startupdelay, xbmc.LOGNOTICE)
log('Service - Run as service: %s'%settings.service_enable, xbmc.LOGNOTICE)
log('Service - Time: %s'%service_runtime, xbmc.LOGNOTICE)
if xbmcvfs.exists(tempdir):
xbmcvfs.rmdir(tempdir)
log('Removing temp folder from previous run.')
if settings.service_startup:
if settings.service_startupdelay != '--':
xbmc.executebuiltin('XBMC.AlarmClock(ArtworkDownloader,XBMC.RunScript(script.artwork.downloader,silent=true),00:%s:00,silent)' %settings.service_startupdelay)
else:
xbmc.executebuiltin('XBMC.AlarmClock(ArtworkDownloader,XBMC.RunScript(script.artwork.downloader,silent=true),00:00:20,silent)')
if settings.service_enable:
while (not xbmc.abortRequested):
xbmc.sleep(5000)
if not(time.strftime('%H:%M') == service_runtime):
pass
else:
if not xbmcvfs.exists(tempdir):
log('Time is %s:%s, Scheduled run starting' % (time.strftime('%H'), time.strftime('%M')))
xbmc.executebuiltin('XBMC.RunScript(script.artwork.downloader,silent=true)')
else:
log('Addon already running, scheduled run aborted', xbmc.LOGNOTICE)
示例3: get_visibility
def get_visibility(self, path):
path = path.replace("videodb://", "library://video/")
customPath = path.replace("library://video", os.path.join(xbmc.translatePath("special://profile".decode('utf-8')), "library", "video")) + "index.xml"
customFile = path.replace("library://video", os.path.join(xbmc.translatePath("special://profile".decode('utf-8')), "library", "video"))[:-1] + ".xml"
defaultPath = path.replace("library://video", os.path.join(xbmc.translatePath("special://xbmc".decode('utf-8')), "system", "library", "video")) + "index.xml"
defaultFile = path.replace("library://video", os.path.join(xbmc.translatePath("special://xbmc".decode('utf-8')), "system", "library", "video"))[:-1] + ".xml"
# Check whether the node exists - either as a parent node (with an index.xml) or a view node (append .xml)
# in first custom video nodes, then default video nodes
if xbmcvfs.exists(customPath):
path = customPath
elif xbmcvfs.exists(customFile):
path = customFile
elif xbmcvfs.exists(defaultPath):
path = defaultPath
elif xbmcvfs.exists(defaultFile):
path = defaultFile
else:
return ""
# Open the file
try:
# Load the xml file
tree = xmltree.parse(path)
root = tree.getroot()
if "visible" in root.attrib:
return root.attrib.get("visible")
else:
return ""
except:
return False
示例4: Get_JSON_response
def Get_JSON_response(url="", cache_days=7.0, folder=False, headers=False):
now = time.time()
hashed_url = hashlib.md5(url).hexdigest()
path = xbmc.translatePath(os.path.join(ADDON_DATA_PATH, hashed_url + ".txt"))
cache_seconds = int(cache_days * 86400.0)
prop_time = HOME.getProperty(hashed_url + "_timestamp")
if prop_time and now - float(prop_time) < cache_seconds:
try:
prop = simplejson.loads(HOME.getProperty(hashed_url))
log("prop load for %s. time: %f" % (url, time.time() - now))
return prop
except:
log("could not load prop data")
if xbmcvfs.exists(path) and ((now - os.path.getmtime(path)) < cache_seconds):
results = read_from_file(path)
log("loaded file for %s. time: %f" % (url, time.time() - now))
else:
response = GetStringFromUrl(url, headers)
try:
results = simplejson.loads(response)
log("download %s. time: %f" % (url, time.time() - now))
save_to_file(results, hashed_url, ADDON_DATA_PATH)
except:
log("Exception: Could not get new JSON data. Tryin to fallback to cache")
log(response)
if xbmcvfs.exists(path):
results = read_from_file(path)
else:
results = []
HOME.setProperty(hashed_url + "_timestamp", str(now))
HOME.setProperty(hashed_url, simplejson.dumps(results))
return results
示例5: add2lib
def add2lib( url, name, infol, img, fanart, year ):
img = 'http://oi62.tinypic.com/dvgj1t.jpg'
addon.log('Add To Library %s , %s, %s' % (name,year,url))
path = xbmc.translatePath( addon.get_setting('movie-folder') )
string = 'plugin://plugin.video.mutttsnutz/?mode=playstream&url='+url+'&name='+name+'&infol='
filename = '%s.strm' % name
path = xbmc.makeLegalFilename( xbmc.translatePath(os.path.join( path, name, filename )))
if not xbmcvfs.exists(os.path.dirname(path)):
try:
try: xbmcvfs.mkdirs(os.path.dirname(path))
except: os.mkdir(os.path.dirname(path))
except:
addon.log('FAILED to create directory')
if xbmcvfs.exists(path):
addon.log( name+' Already in the library' )
notification( addon.get_name()+' allready added', name, img)
return
notification( addon.get_name()+' adding to library', name+' adding to library', img)
strm = xbmcvfs.File(path, 'w')
strm.write(string)
strm.close()
xbmc.executebuiltin("UpdateLibrary(video)")
示例6: writeConfig
def writeConfig(cfile, value=''):
cfgfile = os.path.join(configpath, cfile)
cfglockfile = os.path.join(configpath, cfile + '.lock')
if not xbmcvfs.exists(configpath):
xbmcvfs.mkdirs(configpath)
while True:
if not xbmcvfs.exists(cfglockfile):
l = xbmcvfs.File(cfglockfile, 'w')
l.write(str(time.time()))
l.close()
if value == '':
xbmcvfs.delete(cfgfile)
else:
f = xbmcvfs.File(cfgfile, 'w')
f.write(value.__str__())
f.close()
xbmcvfs.delete(cfglockfile)
xbmcvfs.delete(cfglockfile)
return True
else:
l = xbmcvfs.File(cfglockfile)
modified = float(l.read())
l.close()
if time.time() - modified > 0.1:
xbmcvfs.delete(cfglockfile)
示例7: series
def series(series_id, series_title, season, single_update=True):
filename = utility.clean_filename(series_title, ' .')
series_file = xbmc.translatePath(utility.tv_dir() + filename)
if not xbmcvfs.exists(series_file):
xbmcvfs.mkdir(series_file)
content = get.series_info(series_id)
content = json.loads(content)['video']['seasons']
for test in content:
episode_season = unicode(test['seq'])
if episode_season == season or season == '':
season_dir = utility.create_pathname(series_file, test['title'])
if not xbmcvfs.exists(season_dir):
xbmcvfs.mkdir(season_dir)
for item in test['episodes']:
episode_id = unicode(item['episodeId'])
episode_nr = unicode(item['seq'])
episode_title = item['title']
if len(episode_nr) == 1:
episode_nr = '0' + episode_nr
season_nr = episode_season
if len(season_nr) == 1:
season_nr = '0' + season_nr
filename = 'S' + season_nr + 'E' + episode_nr + ' - ' + episode_title + '.strm'
filename = utility.clean_filename(filename, ' .')
file_handler = xbmcvfs.File(utility.create_pathname(season_dir, filename), 'w')
file_handler.write(
utility.encode('plugin://%s/?mode=play_video&url=%s' % (utility.addon_id, episode_id)))
file_handler.close()
if utility.get_setting('update_db') and single_update:
xbmc.executebuiltin('UpdateLibrary(video)')
示例8: housekeeper
def housekeeper():
file_flag = xbmcvfs.exists("special://home/userdata/addon_data/script.audio.rhapsody/.clean_me")
files = [".albumdb.obj", ".artistdb.obj", ".genres.obj", ".rhapuser.obj"]
#now = time.time()
#print "current timestamp, type: %s %s" % (str(now), type(now))
if file_flag:
print "Found the clean_me file! Now let's delete it"
xbmcvfs.delete("special://home/userdata/addon_data/script.audio.rhapsody/.clean_me")
else:
print "No clean-me file. Let's check file dates"
for item in files:
f = "special://home/userdata/addon_data/script.audio.rhapsody/"+item
f_os = xbmc.translatePath(f)
print "Checking "+f_os
if xbmcvfs.exists(f):
modifiedTime = os.path.getmtime(f_os)
if modifiedTime < AGE_STAMP:
file_flag = True
print "%s is too old. Let's do some housekeeping." % (item)
break
if file_flag:
print "Deleting files..."
for item in files:
f = "special://home/userdata/addon_data/script.audio.rhapsody/"+item
f_os = xbmc.translatePath(f)
print "Deleting "+f_os
if xbmcvfs.exists(f):
xbmcvfs.delete(f)
print "Performed housekeeping"
else:
print "No housekeeping necessary"
示例9: getAllColors
def getAllColors():
# get all colors from the colors xml file and fill a list with tuples to sort later on
allColors = []
colors_file = xbmc.translatePath(
"special://home/addons/script.skin.helper.service/resources/colors/colors.xml"
).decode("utf-8")
if xbmcvfs.exists(colors_file):
doc = parse(colors_file)
listing = doc.documentElement.getElementsByTagName("color")
for count, color in enumerate(listing):
name = color.attributes["name"].nodeValue.lower()
colorstring = color.childNodes[0].nodeValue.lower()
allColors.append((name, colorstring))
# get skin colors too
colors_file = xbmc.translatePath("special://skin/colors/defaults.xml").decode("utf-8")
if xbmcvfs.exists(colors_file):
doc = parse(colors_file)
listing = doc.documentElement.getElementsByTagName("color")
for count, color in enumerate(listing):
name = color.attributes["name"].nodeValue.lower()
colorstring = color.childNodes[0].nodeValue.lower()
allColors.append((name, colorstring))
return allColors
示例10: setThumbnail
def setThumbnail(self, service, url=''):
#load cachePath if not already loaded
if self.cachePath == '':
self.cachePath = service.settings.cachePath
# there is no cache path setting or the setting is unset -- we should assume user does not want to use caching
if not service.settings.cacheThumbnails or self.cachePath == '':
if url == '':
return self.package.file.thumbnail
else:
return url
if url == '':
url = self.package.file.thumbnail
#simply no thumbnail
if url == '':
return ""
#user doesn't want to cache thumbnails
if not service.settings.cacheThumbnails:
return url
cachePath = str(self.cachePath) + str(self.package.file.id) + '/'
cacheFile = str(self.cachePath) + str(self.package.file.id) + '.jpg'
if not xbmcvfs.exists(cachePath):
xbmcvfs.mkdirs(cachePath)
if not xbmcvfs.exists(cacheFile):
cacheFile = service.downloadGeneralFile(url, cacheFile)
if cacheFile is None:
return url
return cacheFile
示例11: season
def season(name, url, mode, thumb, series_name, series_id):
entries = []
filename = series_id + '.jpg'
cover_file = xbmc.translatePath(utility.cover_cache_dir() + filename)
fanart_file = xbmc.translatePath(utility.fanart_cache_dir() + filename)
u = sys.argv[0]
u += '?url=' + urllib.quote_plus(unicode(url))
u += '&mode=' + mode
u += '&series_id=' + urllib.quote_plus(series_id)
list_item = xbmcgui.ListItem(name)
list_item.setArt({'icon': 'DefaultTVShows.png', 'thumb': thumb})
list_item.setInfo(type='video', infoLabels={'title': name})
if xbmcvfs.exists(fanart_file):
list_item.setProperty('fanart_image', fanart_file)
elif xbmcvfs.exists(cover_file):
list_item.setProperty('fanart_image', cover_file)
else:
list_item.setProperty('fanart_image', utility.addon_fanart())
entries.append((utility.get_string(30150),
'RunPlugin(plugin://%s/?mode=add_series_to_library&url=%s&name=%s&series_id=%s)' % (
utility.addon_id, urllib.quote_plus(unicode(url)),
urllib.quote_plus(utility.encode(series_name.strip())),
series_id)))
list_item.addContextMenuItems(entries)
directory_item = xbmcplugin.addDirectoryItem(handle=plugin_handle, url=u, listitem=list_item, isFolder=True)
return directory_item
示例12: video
def video(name, url, mode, thumb, video_type='', description='', duration='', year='', mpaa='', director='', genre='',
rating=0.0, playcount=0, remove=False):
entries = []
filename = utility.clean_filename(url) + '.jpg'
cover_file = xbmc.translatePath(utility.cover_cache_dir() + filename)
fanart_file = xbmc.translatePath(utility.fanart_cache_dir() + filename)
if xbmcvfs.exists(cover_file):
thumb = cover_file
u = sys.argv[0]
u += '?url=' + urllib.quote_plus(url)
u += '&mode=' + mode
u += '&name=' + urllib.quote_plus(utility.encode(name))
u += '&thumb=' + urllib.quote_plus(thumb)
list_item = xbmcgui.ListItem(name)
list_item.setArt({'icon': 'DefaultTVShows.png', 'thumb': thumb})
list_item.setInfo(type='video',
infoLabels={'title': name, 'plot': description, 'duration': duration, 'year': int(year),
'mpaa': mpaa, 'director': director, 'genre': genre, 'rating': rating,
'playcount': playcount})
if xbmcvfs.exists(fanart_file):
list_item.setProperty('fanart_image', fanart_file)
elif xbmcvfs.exists(cover_file):
list_item.setProperty('fanart_image', cover_file)
else:
list_item.setProperty('fanart_image', utility.addon_fanart())
if video_type == 'tvshow':
if utility.get_setting('browse_tv_shows') == 'true':
entries.append((utility.get_string(30151),
'Container.Update(plugin://%s/?mode=play_video_main&url=%s&thumb=%s)' % (
utility.addon_id, urllib.quote_plus(url), urllib.quote_plus(thumb))))
else:
entries.append((utility.get_string(30152),
'Container.Update(plugin://%s/?mode=list_seasons&url=%s&thumb=%s)' % (
utility.addon_id, urllib.quote_plus(url), urllib.quote_plus(thumb))))
if video_type != 'episode':
entries.append((utility.get_string(30153), 'RunPlugin(plugin://%s/?mode=play_trailer&url=%s&type=%s)' % (
utility.addon_id, urllib.quote_plus(utility.encode(name)), video_type)))
if remove:
entries.append((utility.get_string(30154), 'RunPlugin(plugin://%s/?mode=remove_from_queue&url=%s)' % (
utility.addon_id, urllib.quote_plus(url))))
else:
entries.append((utility.get_string(30155), 'RunPlugin(plugin://%s/?mode=add_to_queue&url=%s)' % (
utility.addon_id, urllib.quote_plus(url))))
entries.append((utility.get_string(30156),
'Container.Update(plugin://%s/?mode=list_videos&url=%s&type=movie)' % (
utility.addon_id, urllib.quote_plus(utility.main_url + '/WiMovie/' + url))))
entries.append((utility.get_string(30157), 'Container.Update(plugin://%s/?mode=list_videos&url=%s&type=tv)' % (
utility.addon_id, urllib.quote_plus(utility.main_url + '/WiMovie/' + url))))
if video_type == 'tvshow':
entries.append((utility.get_string(30150),
'RunPlugin(plugin://%s/?mode=add_series_to_library&url=&name=%s&series_id=%s)' % (
utility.addon_id, urllib.quote_plus(utility.encode(name.strip())), urllib.quote_plus(url))))
elif video_type == 'movie':
entries.append((utility.get_string(30150),
'RunPlugin(plugin://%s/?mode=add_movie_to_library&url=%s&name=%s)' % (
utility.addon_id, urllib.quote_plus(url),
urllib.quote_plus(utility.encode(name.strip())) + ' (' + unicode(year) + ')')))
list_item.addContextMenuItems(entries)
directory_item = xbmcplugin.addDirectoryItem(handle=plugin_handle, url=u, listitem=list_item, isFolder=True)
return directory_item
示例13: setCC
def setCC(self, service):
if not constants.CONST.CC:
return
#load cachePath if not already loaded
if self.cachePath == '':
self.cachePath = service.settings.cachePath
# there is no cache path setting or the setting is unset -- we should assume user does not want to use caching
# CC files need to be cached (so they can be converted to SRT) -- don't do anything if we don't have the cachePath
if self.cachePath == '':
return
else:
cachePath = str(self.cachePath) + '/' + str(self.package.file.id)+'/'
if not xbmcvfs.exists(cachePath):
xbmcvfs.mkdirs(cachePath)
cachePath = str(cachePath) + str(self.package.file.id)
cc = service.getTTS(self.package.file.srtURL)
if cc:
for file in cc:
if not xbmcvfs.exists(cachePath + str(file[0])):
service.downloadTTS(file[1], str(cachePath) + str(file[0]))
self.srt.append(str(cachePath) + str(file[0]))
示例14: writeMediaList
def writeMediaList(url, name, cType='Other'):
utils.addon_log('writeMediaList')
existInList = False
thelist = []
thefile = xbmc.translatePath(os.path.join(profile, 'MediaList.xml'))
theentry = '|'.join([cType, name.decode("utf-8"), url]) + '\n'
if not xbmcvfs.exists(profile):
xbmcvfs.mkdirs(profile)
if not xbmcvfs.exists(thefile):
open(thefile, 'a').close()
fle = codecs.open(thefile, "r", 'UTF-8')
thelist = fle.readlines()
fle.close()
del fle
if len(thelist) > 0:
for i in thelist:
if i.split('|',2)[1] == name:
thelist = stringUtils.replaceStringElem(thelist, theentry, theentry)
existInList = True
if existInList != True:
thelist.append(theentry)
with open(thefile.decode("utf-8"), 'w') as output_file:
for linje in thelist:
if not linje.startswith('\n'):
output_file.write(linje.strip().encode('utf-8') + '\n')
else:
output_file.write(linje.strip())
示例15: _get_trailer_thumbnail
def _get_trailer_thumbnail( path ):
log( "Getting Trailer Thumbnail" )
# check for a thumb based on trailername.tbn
thumbnail = os.path.splitext( path )[ 0 ] + ".tbn"
log( "Looking for thumbnail: %s" % thumbnail )
# if thumb does not exist try stripping -trailer
if not xbmcvfs.exists( thumbnail ):
thumbnail = os.path.splitext( path )[ 0 ] + ".jpg"
log( "Looking for thumbnail: %s" % thumbnail )
if not xbmcvfs.exists( thumbnail ):
thumbnail = "%s.tbn" % ( os.path.splitext( path )[ 0 ].replace( "-trailer", "" ), )
log( "Thumbnail not found, Trying: %s" % thumbnail )
if not xbmcvfs.exists( thumbnail ):
thumbnail = "%s.jpg" % ( os.path.splitext( path )[ 0 ].replace( "-trailer", "" ), )
log( "Looking for thumbnail: %s" % thumbnail )
if not xbmcvfs.exists( thumbnail ):
thumbnail = os.path.join( os.path.dirname( path ), "movie.tbn" )
log( "Thumbnail not found, Trying: %s" % thumbnail )
# if thumb does not exist return empty
if not xbmcvfs.exists( thumbnail ):
# set empty string
thumbnail = ""
log( "Thumbnail not found" )
if thumbnail:
log( "Thumbnail found: %s" thumbnail )
# return result
return thumbnail