本文整理汇总了Python中xbmcvfs.listdir方法的典型用法代码示例。如果您正苦于以下问题:Python xbmcvfs.listdir方法的具体用法?Python xbmcvfs.listdir怎么用?Python xbmcvfs.listdir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xbmcvfs
的用法示例。
在下文中一共展示了xbmcvfs.listdir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_folder
# 需要导入模块: import xbmcvfs [as 别名]
# 或者: from xbmcvfs import listdir [as 别名]
def delete_folder(path=None):
''' Delete objects from kodi cache
'''
LOG.debug("--[ delete folder ]")
delete_path = path is not None
path = path or xbmc.translatePath('special://temp/emby').decode('utf-8')
dirs, files = xbmcvfs.listdir(path)
delete_recursive(path, dirs)
for file in files:
xbmcvfs.delete(os.path.join(path, file.decode('utf-8')))
if delete_path:
xbmcvfs.delete(path)
LOG.warn("DELETE %s", path)
示例2: unzip
# 需要导入模块: import xbmcvfs [as 别名]
# 或者: from xbmcvfs import listdir [as 别名]
def unzip(path, dest, folder=None):
''' Unzip file. zipfile module seems to fail on android with badziperror.
'''
path = urllib.quote_plus(path)
root = "zip://" + path + '/'
if folder:
xbmcvfs.mkdir(os.path.join(dest, folder))
dest = os.path.join(dest, folder)
root = get_zip_directory(root, folder)
dirs, files = xbmcvfs.listdir(root)
if dirs:
unzip_recursive(root, dirs, dest)
for file in files:
unzip_file(os.path.join(root, file.decode('utf-8')), os.path.join(dest, file.decode('utf-8')))
LOG.warn("Unzipped %s", path)
示例3: delete_nodes
# 需要导入模块: import xbmcvfs [as 别名]
# 或者: from xbmcvfs import listdir [as 别名]
def delete_nodes(self):
''' Remove node and children files.
'''
path = xbmc.translatePath("special://profile/library/video/").decode('utf-8')
dirs, files = xbmcvfs.listdir(path)
for file in files:
if file.startswith('emby'):
self.delete_node(os.path.join(path, file.decode('utf-8')))
for directory in dirs:
if directory.startswith('emby'):
_, files = xbmcvfs.listdir(os.path.join(path, directory.decode('utf-8')))
for file in files:
self.delete_node(os.path.join(path, directory.decode('utf-8'), file.decode('utf-8')))
xbmcvfs.rmdir(os.path.join(path, directory.decode('utf-8')))
示例4: get_previously_exported_items
# 需要导入模块: import xbmcvfs [as 别名]
# 或者: from xbmcvfs import listdir [as 别名]
def get_previously_exported_items():
"""Return a list of movie or tvshow VideoIds for items that were exported in
the old storage format"""
result = []
videoid_pattern = re.compile('video_id=(\\d+)')
for folder in _lib_folders(FOLDER_MOVIES) + _lib_folders(FOLDER_TV):
for filename in xbmcvfs.listdir(folder)[1]:
filepath = g.py2_decode(makeLegalFilename('/'.join([folder, filename])))
if filepath.endswith('.strm'):
common.debug('Trying to migrate {}', filepath)
try:
# Only get a VideoId from the first file in each folder.
# For shows, all episodes will result in the same VideoId
# and movies only contain one file
result.append(
_get_root_videoid(filepath, videoid_pattern))
except MetadataNotAvailable:
common.warn('Metadata not available, item skipped')
except (AttributeError, IndexError):
common.warn('Item does not conform to old format')
break
return result
示例5: grab_log
# 需要导入模块: import xbmcvfs [as 别名]
# 或者: from xbmcvfs import listdir [as 别名]
def grab_log(file=False, old=False, wizard=False):
if wizard:
if os.path.exists(CONFIG.WIZLOG):
return CONFIG.WIZLOG if file else tools.read_from_file(CONFIG.WIZLOG)
else:
return False
logsfound = []
for item in [file for file in os.listdir(CONFIG.LOGPATH) if os.path.basename(file).startswith('kodi')]:
if item.endswith('.log'):
if (old and 'old' in item) or (not old and 'old' not in item):
logsfound.append(os.path.join(CONFIG.LOGPATH, item))
if len(logsfound) > 0:
logsfound.sort(key=lambda f: os.path.getmtime(f))
if file:
return logsfound[-1]
else:
return tools.read_from_file(logsfound[-1])
else:
return False
示例6: check_for_fm
# 需要导入模块: import xbmcvfs [as 别名]
# 或者: from xbmcvfs import listdir [as 别名]
def check_for_fm():
if not xbmc.getCondVisibility('System.HasAddon(script.kodi.android.update)'):
from resources.libs.gui import addon_menu
addon_menu.install_from_kodi('script.kodi.android.update')
try:
updater = xbmcaddon.Addon('script.kodi.android.update')
except RuntimeError as e:
return False
fm = int(updater.getSetting('File_Manager'))
apps = xbmcvfs.listdir('androidapp://sources/apps/')[1]
if fm == 0 and 'com.android.documentsui' not in apps:
dialog = xbmcgui.Dialog()
choose = dialog.yesno(CONFIG.ADDONTITLE, 'It appears your device has no default file manager. Would you like to set one now?')
if not choose:
dialog.ok(CONFIG.ADDONTITLE, 'If an APK downloads, but doesn\'t open for installation, try changing your file manager in {}\'s "Install Settings".'.format(CONFIG.ADDONTITLE))
else:
from resources.libs import install
install.choose_file_manager()
return True
示例7: library_getnfo_tmdbid
# 需要导入模块: import xbmcvfs [as 别名]
# 或者: from xbmcvfs import listdir [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
示例8: _rotate_file
# 需要导入模块: import xbmcvfs [as 别名]
# 或者: from xbmcvfs import listdir [as 别名]
def _rotate_file():
newdate = ndate = pykodi.get_infolabel('System.Date(yyyy-mm-dd)')
count = 0
while _exists(newdate):
count += 1
newdate = ndate + '.' + str(count)
if not xbmcvfs.copy(_get_filepath(), _get_filepath(newdate)):
log("Could not copy latest report to new filename", xbmc.LOGWARNING, 'reporting')
return False
if not xbmcvfs.delete(_get_filepath()):
log("Could not delete old copy of latest report", xbmc.LOGWARNING, 'reporting')
return False
# delete old reports
_, files = xbmcvfs.listdir(settings.datapath)
reportfiles = sorted(f[:-4] for f in files if f.startswith(REPORT_NAME))
while len(reportfiles) > REPORT_COUNT:
filename = reportfiles[0] + '.txt'
if not xbmcvfs.delete(settings.datapath + filename):
log("Could not delete old report '{0}'".format(filename), xbmc.LOGWARNING, 'reporting')
return False
del reportfiles[0]
report_startup()
return True
示例9: getextra
# 需要导入模块: import xbmcvfs [as 别名]
# 或者: from xbmcvfs import listdir [as 别名]
def getextra(self, path, exacttypes, thumbs=False):
arttype = 'thumb' if thumbs else 'fanart'
extradir = 'extrathumbs' if thumbs else 'extrafanart'
sep = get_pathsep(path)
missing, nextno = getopentypes(exacttypes, arttype)
path += extradir + sep
_, files = xbmcvfs.listdir(path)
files.sort(key=natural_sort)
result = {}
for filename in files:
check_filename = filename.lower()
if not check_filename.endswith(ARTWORK_EXTS):
continue
popped = missing.pop(0) if missing else None
nexttype = popped if popped else format_arttype(arttype, nextno)
result[nexttype] = self.buildimage(path + filename, extradir + sep + filename)
if not popped:
nextno += 1
return result
示例10: get_exact_images
# 需要导入模块: import xbmcvfs [as 别名]
# 或者: from xbmcvfs import listdir [as 别名]
def get_exact_images(self, mediaitem):
path = find_central_infodir(mediaitem)
if not path:
return {}
_, files = xbmcvfs.listdir(path)
result = {}
for filename in files:
check_filename = filename.lower()
if not check_filename.endswith(ARTWORK_EXTS):
continue
arttype = os.path.splitext(check_filename)[0]
if not arttype.isalnum() or len(arttype) > ARTTYPE_MAXLENGTH:
continue
if settings.identify_alternatives and arttype in self.alttypes.keys():
arttype = self.alttypes[arttype]
if arttype in result.keys():
continue
result[arttype] = self.buildimage(path + filename, filename, True)
return result
示例11: walk_vfs
# 需要导入模块: import xbmcvfs [as 别名]
# 或者: from xbmcvfs import listdir [as 别名]
def walk_vfs(top, topdown=True, onerror=None):
"""
Lista un directorio de manera recursiva
Como xmbcvfs no tiene esta función, se copia la lógica de libsmb(samba) para realizar la previa al Walk
"""
top = encode(top)
dirs, nondirs = xbmcvfs.listdir(top)
if topdown:
yield top, dirs, nondirs
for name in dirs:
if isinstance(name, unicode):
name = name.encode("utf8")
if PY3: name = name.decode("utf8")
elif PY3 and isinstance(name, bytes):
name = name.decode("utf8")
elif not PY3:
name = unicode(name, "utf8")
new_path = "/".join(top.split("/") + [name])
for x in walk_vfs(new_path, topdown, onerror):
yield x
if not topdown:
yield top, dirs, nondirs
示例12: listdir
# 需要导入模块: import xbmcvfs [as 别名]
# 或者: from xbmcvfs import listdir [as 别名]
def listdir(path, silent=False, vfs=True):
"""
Lista un directorio
@param path: Directorio a listar, debe ser un str "UTF-8"
@type path: str
@rtype: str
@return: contenido de un directorio
"""
path = encode(path)
try:
if xbmc_vfs and vfs:
dirs, files = xbmcvfs.listdir(path)
return dirs + files
elif path.lower().startswith("smb://"):
return decode(samba.listdir(path))
else:
return decode(os.listdir(path))
except:
logger.error("ERROR al leer el directorio: %s" % path)
if not silent:
logger.error(traceback.format_exc())
return False
示例13: find
# 需要导入模块: import xbmcvfs [as 别名]
# 或者: from xbmcvfs import listdir [as 别名]
def find(path):
path = xbmc.translatePath(path)
all_dirs = []
all_files = []
dirs, files = xbmcvfs.listdir(path)
for file in files:
file_path = os.path.join(path,file)
all_files.append(file_path)
for dir in dirs:
dir_path = os.path.join(path,dir)
all_dirs.append(dir_path)
new_dirs, new_files = find(os.path.join(path, dir))
for new_dir in new_dirs:
new_dir_path = os.path.join(path,dir,new_dir)
all_dirs.append(new_dir_path)
for new_file in new_files:
new_file = os.path.join(path,dir,new_file)
all_files.append(new_file)
return all_dirs, all_files
示例14: get_play_count
# 需要导入模块: import xbmcvfs [as 别名]
# 或者: from xbmcvfs import listdir [as 别名]
def get_play_count(filename):
# Obtaining playback counter
play_count = False
if not filename or sqlite is None:
return play_count
# get path to database and determine videobase filename
basepath = xbmc.translatePath("special://database")
for basefile in xbmcvfs.listdir(basepath)[1]:
if 'MyVideos' in basefile:
videobase = basefile
# connect to database
db = sqlite.connect(os.path.join(basepath, videobase))
try:
sqlcur = db.execute('SELECT playCount FROM files WHERE strFilename like ?', ('%'+filename+'%',))
res_playCount = sqlcur.fetchall()
if res_playCount:
# check in the result data for at the least one played current file
if any(plcount > 0 for plcount in res_playCount):
play_count = True
except:
print 'Error connection to table file. Database is may be busy'
db.close()
return play_count
示例15: update_library
# 需要导入模块: import xbmcvfs [as 别名]
# 或者: from xbmcvfs import listdir [as 别名]
def update_library():
folder_path = plugin.get_setting('tv_library_folder', unicode)
if not xbmcvfs.exists(folder_path):
return
library_folder = setup_library(folder_path)
try:
shows = xbmcvfs.listdir(library_folder)[0]
except:
shows = []
clean_needed = False
updated = 0
for id in shows:
try:
id = int(id)
with TVDB.session.cache_disabled():
if add_tvshow_to_library(library_folder, TVDB[id]):
clean_needed = True
except:
continue
updated += 1
if clean_needed:
plugin.setProperty('plugin.video.openmeta.clean_library', 'true')
if updated > 0:
tools.scan_library(path=plugin.get_setting('tv_library_folder', unicode))