本文整理匯總了Python中xbmcvfs.File方法的典型用法代碼示例。如果您正苦於以下問題:Python xbmcvfs.File方法的具體用法?Python xbmcvfs.File怎麽用?Python xbmcvfs.File使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類xbmcvfs
的用法示例。
在下文中一共展示了xbmcvfs.File方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: images
# 需要導入模塊: import xbmcvfs [as 別名]
# 或者: from xbmcvfs import File [as 別名]
def images(self):
''' Return a dummy image for unwanted images requests over the webservice.
Required to prevent freezing of widget playback if the file url has no
local textures cached yet.
'''
image = xbmc.translatePath("special://home/addons/plugin.video.emby/icon.png").decode('utf-8')
self.send_response(200)
self.send_header('Content-type', 'image/png')
modified = xbmcvfs.Stat(image).st_mtime()
self.send_header('Last-Modified', "%s" % modified)
image = xbmcvfs.File(image)
size = image.size()
self.send_header('Content-Length', str(size))
self.end_headers()
self.wfile.write(image.readBytes())
image.close()
示例2: add_item_to_library
# 需要導入模塊: import xbmcvfs [as 別名]
# 或者: from xbmcvfs import File [as 別名]
def add_item_to_library(self, item_path, item_url):
error = False
new = False
if item_path:
item_path = xbmc.translatePath(item_path)
dir = os.path.dirname(item_path)
if not xbmcvfs.exists(dir):
try:
xbmcvfs.mkdirs(dir)
except Exception, e:
error = True
util.error('Failed to create directory 1: ' + dir)
if not xbmcvfs.exists(item_path):
try:
file_desc = xbmcvfs.File(item_path, 'w')
file_desc.write(item_url)
file_desc.close()
new = True
except Exception, e:
util.error('Failed to create .strm file: ' +
item_path + " | " + str(e))
error = True
示例3: get_current_view
# 需要導入模塊: import xbmcvfs [as 別名]
# 或者: from xbmcvfs import File [as 別名]
def get_current_view():
skinPath = translate_path('special://skin/')
xml = os.path.join(skinPath, 'addon.xml')
f = xbmcvfs.File(xml)
read = f.read()
f.close()
try:
src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1)
except:
src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1)
src = os.path.join(skinPath, src, 'MyVideoNav.xml')
f = xbmcvfs.File(src)
read = f.read()
f.close()
match = re.search('<views>([^<]+)', read, re.DOTALL)
if match:
views = match.group(1)
for view in views.split(','):
if xbmc.getInfoLabel('Control.GetLabel(%s)' % view):
return view
示例4: library_getnfo_tmdbid
# 需要導入模塊: import xbmcvfs [as 別名]
# 或者: from xbmcvfs import File [as 別名]
def library_getnfo_tmdbid(basedir=None, folder=None):
""" Checks .nfo file and returns TMDB ID it contains """
tmdb_id = None
folder_list = xbmcvfs.listdir(basedir)[0]
if folder in folder_list:
nfo_folder = basedir + folder + '/'
nfo = None
for x in xbmcvfs.listdir(nfo_folder)[1]:
if x.endswith('.nfo'):
nfo = x
if nfo:
vfs_file = xbmcvfs.File(nfo_folder + nfo)
content = ''
try:
content = vfs_file.read()
finally:
vfs_file.close()
tmdb_id = content.replace('https://www.themoviedb.org/tv/', '')
tmdb_id = tmdb_id.replace('&islocal=True', '')
return tmdb_id
示例5: read_nfofile
# 需要導入模塊: import xbmcvfs [as 別名]
# 或者: from xbmcvfs import File [as 別名]
def read_nfofile(filename):
if not xbmcvfs.exists(filename):
return None
with closing(xbmcvfs.File(filename)) as nfofile:
try:
return ET.parse(nfofile).getroot()
except ParseError:
pass
# maybe it's all XML except the last line, like the wiki suggests for XML + URL
nfofile.seek(0, 0)
lines = nfofile.read().split('\n')
while lines and not lines[-1].strip():
del lines[-1] # Remove final blank lines
if lines: # Remove the line that possibly contains the URL
del lines[-1]
if lines:
try:
return ET.XML('\n'.join(lines))
except ParseError:
pass
示例6: GetCurrentView
# 需要導入模塊: import xbmcvfs [as 別名]
# 或者: from xbmcvfs import File [as 別名]
def GetCurrentView(self):
skinPath = xbmc.translatePath('special://skin/')
xml = os.path.join(skinPath, 'addon.xml')
f = xbmcvfs.File(xml)
read = f.read()
f.close()
try:
src = re.search('defaultresolution="([^"]+)', read, re.DOTALL).group(1)
except:
src = re.search('<res.+?folder="([^"]+)', read, re.DOTALL).group(1)
src = os.path.join(skinPath, src, 'MyVideoNav.xml')
f = xbmcvfs.File(src)
read = f.read()
f.close()
match = re.search('<views>([^<]+)', read, re.DOTALL)
if match:
views = match.group(1)
log.info("Skin's ViewModes: %s" % views)
for view in views.split(','):
if xbmc.getInfoLabel('Control.GetLabel(%s)' % view):
return view
示例7: getsize
# 需要導入模塊: import xbmcvfs [as 別名]
# 或者: from xbmcvfs import File [as 別名]
def getsize(path, silent=False, vfs=True):
"""
Obtiene el tamaño de un archivo
@param path: ruta del fichero
@type path: str
@rtype: str
@return: tamaño del fichero
"""
path = encode(path)
try:
if xbmc_vfs and vfs:
if not exists(path): return long(0)
f = xbmcvfs.File(path)
s = f.size()
f.close()
return s
elif path.lower().startswith("smb://"):
return long(samba.get_attributes(path).file_size)
else:
return os.path.getsize(path)
except:
logger.error("ERROR al obtener el tamaño: %s" % path)
if not silent:
logger.error(traceback.format_exc())
return long(0)
示例8: convert
# 需要導入模塊: import xbmcvfs [as 別名]
# 或者: from xbmcvfs import File [as 別名]
def convert(path):
input = xbmcvfs.File(path,'rb')
output = xbmcvfs.File(path.replace('.ts','.mp4'),'wb')
error = open(xbmc.translatePath("special://profile/addon_data/plugin.video.iptv.recorder/errors.txt"),"w")
cmd = [ffmpeg_location(),"-fflags","+genpts","-y","-i","-","-vcodec","copy","-acodec","copy","-f", "mpegts", "-"]
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=error, shell=windows())
t = threading.Thread(target=read_thread,args=[p,output])
t.start()
while True:
data = input.read(100000)
log(("read",len(data)))
if not data:
break
p.stdin.write(data)
p.stdin.close()
error.close()
示例9: load_cache
# 需要導入模塊: import xbmcvfs [as 別名]
# 或者: from xbmcvfs import File [as 別名]
def load_cache(self):
try:
fd = xbmcvfs.File(FAVORITES_FILE, 'r')
self.ids_content = fd.read()
self.ids = eval(self.ids_content)
if not 'locked_artists' in self.ids:
self.ids['locked_artists'] = [VARIOUS_ARTIST_ID]
fd.close()
self.ids_loaded = not (self.ids['artists'] == None or self.ids['albums'] == None or
self.ids['playlists'] == None or self.ids['tracks'] == None or
self.ids['videos'] == None)
if self.ids_loaded:
log('Loaded %s Favorites from disk.' % sum(len(self.ids[content]) for content in ['artists', 'albums', 'playlists', 'tracks', 'videos']))
except:
self.ids_loaded = False
self.reset()
return self.ids_loaded
示例10: batch_add_tvshows_to_library
# 需要導入模塊: import xbmcvfs [as 別名]
# 或者: from xbmcvfs import File [as 別名]
def batch_add_tvshows_to_library(library_folder, show):
id = show['id']
showname = text.to_utf8(show['seriesname'])
show_folder = os.path.join(library_folder, str(id) + '/')
if not xbmcvfs.exists(show_folder):
try:
xbmcvfs.mkdir(show_folder)
except:
pass
nfo_filepath = os.path.join(show_folder, 'tvshow.nfo')
if not xbmcvfs.exists(nfo_filepath):
nfo_file = xbmcvfs.File(nfo_filepath, 'w')
content = 'https://thetvdb.com/?tab=series&id=%s' % str(id)
nfo_file.write(content)
nfo_file.close()
clean_needed = True
return clean_needed
示例11: movies_add_all_to_library
# 需要導入模塊: import xbmcvfs [as 別名]
# 或者: from xbmcvfs import File [as 別名]
def movies_add_all_to_library(items, noscan=False):
library_folder = lib_movies.setup_library(plugin.get_setting('movies_library_folder', unicode))
if 'results' in items:
ids = '\n'.join([str(r['id']) for r in items['results']])
else:
ids = '\n'.join([i['movie']['ids']['imdb'] if i['movie']['ids']['imdb'] != None and i['movie']['ids']['imdb'] != '' else str(i['movie']['ids']['tmdb']) for i in items])
movies_batch_add_file = plugin.get_setting('movies_batch_add_file_path', unicode)
if xbmcvfs.exists(movies_batch_add_file):
batch_add_file = xbmcvfs.File(movies_batch_add_file)
pre_ids = batch_add_file.read()
xids = pre_ids.split('\n')
for id in xids:
if id != '' and id != None and id not in ids:
ids = ids + str(id) + '\n'
batch_add_file.close()
xbmcvfs.delete(movies_batch_add_file)
batch_add_file = xbmcvfs.File(movies_batch_add_file, 'w')
batch_add_file.write(str(ids))
batch_add_file.close()
xbmc.executebuiltin('RunPlugin(plugin://plugin.video.openmeta/movies/batch_add_to_library)')
示例12: get_players
# 需要導入模塊: import xbmcvfs [as 別名]
# 或者: from xbmcvfs import File [as 別名]
def get_players(media, filters={}):
assert media in ('tvshows', 'movies')
players = []
players_path = 'special://profile/addon_data/plugin.video.openmeta/Players/'
files = [x for x in xbmcvfs.listdir(players_path)[1] if x.endswith('.json')]
for file in files:
path = players_path + file
try:
f = xbmcvfs.File(path)
try:
content = f.read()
meta = json.loads(content)
finally:
f.close()
player = AddonPlayer(file, media, meta)
if not player.is_empty():
players.append(player)
except:
xbmcgui.Dialog().ok('Invalid player', 'player %s is invalid' % file)
return sort_players(players, filters)
示例13: tv_add_all_to_library
# 需要導入模塊: import xbmcvfs [as 別名]
# 或者: from xbmcvfs import File [as 別名]
def tv_add_all_to_library(items, noscan=False):
library_folder = lib_tvshows.setup_library(plugin.get_setting('tv_library_folder', unicode))
ids = ''
if 'results' in items:
preids = []
for tvdb_show, tmdb_show in executor.execute(tmdb_to_tvdb, items['results'], workers=10):
if tvdb_show is not None:
preids.append(tvdb_show['id'])
ids = '\n'.join(preids)
else:
ids = '\n'.join([str(i['show']['ids']['tvdb']) if i['show']['ids']['tvdb'] != None and i['show']['ids']['tvdb'] != '' else i['show']['ids']['imdb'] for i in items])
shows_batch_add_file = plugin.get_setting('tv_batch_add_file_path', unicode)
if xbmcvfs.exists(shows_batch_add_file):
batch_add_file = xbmcvfs.File(shows_batch_add_file)
pre_ids = batch_add_file.read()
xids = pre_ids.split('\n')
for id in xids:
if id != '' and id != None and id not in ids:
ids = ids + str(id) + '\n'
batch_add_file.close()
xbmcvfs.delete(shows_batch_add_file)
batch_add_file = xbmcvfs.File(shows_batch_add_file, 'w')
batch_add_file.write(str(ids))
batch_add_file.close()
xbmc.executebuiltin('RunPlugin(plugin://plugin.video.openmeta/tv/batch_add_to_library)')
示例14: open_file
# 需要導入模塊: import xbmcvfs [as 別名]
# 或者: from xbmcvfs import File [as 別名]
def open_file(path, flags='r'):
"""Open a file (using xbmcvfs)"""
from xbmcvfs import File
fdesc = File(path, flags)
yield fdesc
fdesc.close()
示例15: exists
# 需要導入模塊: import xbmcvfs [as 別名]
# 或者: from xbmcvfs import File [as 別名]
def exists(path):
"""Whether the path exists (using xbmcvfs)"""
# File or folder (folder must end with slash or backslash)
from xbmcvfs import exists as vfsexists
return vfsexists(from_unicode(path))