本文整理汇总了Python中xbmcvfs.listdir函数的典型用法代码示例。如果您正苦于以下问题:Python listdir函数的具体用法?Python listdir怎么用?Python listdir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了listdir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getOfflineFileList
def getOfflineFileList(cachePath):
localFiles = []
#workaround for this issue: https://github.com/xbmc/xbmc/pull/8531
if xbmcvfs.exists(cachePath) or os.path.exists(cachePath):
dirs,files = xbmcvfs.listdir(cachePath)
for dir in dirs:
subdir,subfiles = xbmcvfs.listdir(str(cachePath) + '/' + str(dir))
for file in subfiles:
if bool(re.search('\.stream\.mp4', file)):
try:
nameFile = xbmcvfs.File(str(cachePath) + '/' + str(dir) + '/' + str(dir) + '.name')
filename = nameFile.read()
nameFile.close()
except:
filename = file
try:
nameFile = xbmcvfs.File(str(cachePath) + '/' + str(dir) + '/' + str(os.path.splitext(file)[0]) + '.resolution')
resolution = nameFile.read()
nameFile.close()
except:
resolution = file
offlineFile = offlinefile.offlinefile(filename, str(cachePath) + '/' + str(dir) +'.jpg', resolution.rstrip(), str(cachePath) + '/' + str(dir) + '/' + str(os.path.splitext(file)[0]) + '.mp4')
localFiles.append(offlineFile)
return localFiles
示例2: parser_check
def parser_check():
dirs,files = xbmcvfs.listdir(base_dir)
if not dirs:
dirpackages,filespackages = xbmcvfs.listdir(parser_packages_folder)
if filespackages:
for fich in filespackages:
shutil.copyfile(os.path.join(parser_packages_folder,fich), os.path.join(parser_core_folder,fich))
xbmc.sleep(100)
import tarfile
if tarfile.is_tarfile(os.path.join(parser_core_folder,fich)):
download_tools().extract(os.path.join(parser_core_folder,fich),parser_core_folder)
download_tools().remove(os.path.join(parser_core_folder,fich))
else:
dirsuserdata,files = xbmcvfs.listdir(parser_folder)
for fich in files:
dictionary_module = eval(readfile(os.path.join(parser_folder,fich)))
if "url" in dictionary_module.keys():
add_new_parser(dictionary_module["url"])
else:
xbmcvfs.copy(os.path.join(parser_packages_folder,fich.replace('.txt','.tar.gz')),os.path.join(parser_core_folder,fich.replace('.txt','.tar.gz')))
import tarfile
if tarfile.is_tarfile(os.path.join(parser_core_folder,fich.replace('.txt','.tar.gz'))):
download_tools().extract(os.path.join(parser_core_folder,fich.replace('.txt','.tar.gz')),parser_core_folder)
download_tools().remove(os.path.join(parser_core_folder,fich.replace('.txt','.tar.gz')))
else: pass
return
示例3: delete_cache
def delete_cache(cls):
# Remove all existing textures first
path = xbmc.translatePath('special://thumbnails/').decode('utf-8')
if xbmcvfs.exists(path):
dirs, ignore_files = xbmcvfs.listdir(path)
for directory in dirs:
ignore_dirs, files = xbmcvfs.listdir(path + directory)
for file_ in files:
if os.path.supports_unicode_filenames:
filename = os.path.join(path + directory.decode('utf-8'),
file_.decode('utf-8'))
else:
filename = os.path.join(path.encode('utf-8') + directory, file_)
xbmcvfs.delete(filename)
log.debug("deleted: %s", filename)
# remove all existing data from texture DB
with DatabaseConn('texture') as cursor_texture:
cursor_texture.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"')
rows = cursor_texture.fetchall()
for row in rows:
table_name = row[0]
if table_name != "version":
cursor_texture.execute("DELETE FROM " + table_name)
示例4: CleanExpired
def CleanExpired(self):
#delete files more than an hour old
self.Notification('Hulu Library','Removing Expired Content')
#delete old tv show files
dir = xbmc.makeLegalFilename(TV_SHOWS_PATH)
dirs, trash = xbmcvfs.listdir(dir)
for show in dirs:
show = xbmc.makeLegalFilename(os.path.join(dir, show))
trash, files = xbmcvfs.listdir(show)
for file in files:
path = xbmc.makeLegalFilename(os.path.join(show,file))
if (sys.platform == 'win32'): path = path.replace('smb:','')
if (time.mktime(time.strptime(time.ctime(os.path.getmtime(path)))) < (time.mktime(time.localtime()) - 3600)): xbmcvfs.delete(path)
#delete old movie files
dir = xbmc.makeLegalFilename(MOVIE_PATH)
trash, movies = xbmcvfs.listdir(dir)
for movie in movies:
path = xbmc.makeLegalFilename(os.path.join(dir, movie))
if (sys.platform == 'win32'): path = path.replace('smb:','')
if time.mktime(time.strptime(time.ctime(os.path.getmtime(path)))) < (time.mktime(time.localtime()) - 3600): xbmcvfs.delete(path)
xbmc.log(path)
self.Notification('Hulu Library','Expired Content Removed')
示例5: Download
def Download(url,lang):
try: rmtree(__temp__)
except: pass
try: os.makedirs(__temp__)
except: pass
subtitle_list = []
exts = [".srt", ".sub", ".smi", ".ssa", ".ass" ]
log( sys._getframe().f_code.co_name ,"Download page: %s" % (url))
try:
req = urllib2.Request(url)
req.add_header('User-Agent', UserAgent)
socket = urllib2.urlopen(req)
data = socket.read()
soup = BeautifulSoup(data, 'html.parser')
url = soup.find("li", class_="dlsub").a.get('href').encode('utf-8')
if url[:4] != 'http':
url = ZIMUKU_BASE + url
log( sys._getframe().f_code.co_name ,"Download links: %s" % (url))
req = urllib2.Request(url)
req.add_header('User-Agent', UserAgent)
socket = urllib2.urlopen(req)
data = socket.read()
socket.close()
soup = BeautifulSoup(data, 'html.parser')
links = soup.find("div", {"class":"clearfix"}).find_all('a')
except:
log( sys.exc_info()[2].tb_frame.f_code.co_name, "(%d) [%s]" % (
sys.exc_info()[2].tb_lineno,
sys.exc_info()[1]
))
return []
filename, data = DownloadLinks(links, url)
if len(data) < 1024:
return []
tempfile = os.path.join(__temp__, "subtitles%s" % os.path.splitext(filename)[1])
with open(tempfile, "wb") as subFile:
subFile.write(data)
subFile.close()
xbmc.sleep(500)
if data[:4] == 'Rar!' or data[:2] == 'PK':
xbmc.executebuiltin(('XBMC.Extract("%s","%s")' % (tempfile,__temp__,)).encode('utf-8'), True)
path = __temp__
dirs, files = xbmcvfs.listdir(path)
if len(dirs) > 0:
path = os.path.join(__temp__, dirs[0].decode('utf-8'))
dirs, files = xbmcvfs.listdir(path)
list = []
for subfile in files:
if (os.path.splitext( subfile )[1] in exts):
list.append(subfile.decode('utf-8'))
if len(list) == 1:
subtitle_list.append(os.path.join(path, list[0]))
else:
sel = xbmcgui.Dialog().select('请选择压缩包中的字幕', list)
if sel == -1:
sel = 0
subtitle_list.append(os.path.join(path, list[sel]))
return subtitle_list
示例6: listFilesInPath
def listFilesInPath(path, allFilesList=None):
#used for easy matching of studio logos
if not allFilesList:
allFilesList = {}
dirs, files = xbmcvfs.listdir(path)
for file in files:
file = file.decode("utf-8")
name = file.split(".png")[0].lower()
if not allFilesList.has_key(name):
allFilesList[name] = path + file
for dir in dirs:
dirs2, files2 = xbmcvfs.listdir(os.path.join(path,dir)+os.sep)
for file in files2:
file = file.decode("utf-8")
dir = dir.decode("utf-8")
name = dir + "/" + file.split(".png")[0].lower()
if not allFilesList.has_key(name):
if "/" in path:
sep = "/"
else:
sep = "\\"
allFilesList[name] = path + dir + sep + file
#return the list
return allFilesList
示例7: merge_epg
def merge_epg():
# code from enen92. thank you
print '[Rytec EPG Downloader]: merge epg'
xml_path = get_xml_path()
temp = os.path.join(xml_path,'temp')
if not os.path.isdir(temp):
os.mkdir(temp)
out = os.path.join(xml_path,'merged_epg.xml')
if xbmcvfs.exists(out): os.remove(out)
print '[Rytec EPG Downloader]: start extracting files'
dirs, files = xbmcvfs.listdir(os.path.join(xml_path))
for f in files:
if f.endswith('.gz'):
inF = gzip.GzipFile(os.path.join(xml_path,f), 'rb')
s = inF.read()
inF.close()
outF = file(os.path.join(temp,f.replace('.gz','.xml')),'wb')
outF.write(s)
outF.close()
print '[Rytec EPG Downloader]: extracting files done'
print '[Rytec EPG Downloader]: start merging files'
dirs, xmltv_list = xbmcvfs.listdir(os.path.join(temp))
i=1
total = len(xmltv_list)
for xmltv in xmltv_list:
if xmltv.endswith('.xml'):
if i==1:
f = open(os.path.join(temp,xmltv), "r")
text = f.read()
f.close()
with open(out, "a") as myfile:
myfile.write(text.replace('</tv>',''))
elif i==total:
o = open(out,"a")
f = open(os.path.join(temp,xmltv),"r")
lines = f.readlines()
f.close()
li = 0
for line in lines:
if li == 0 or li == 1: pass
else: o.write(line)
li += 1
o.close()
else:
o = open(out,"a")
f = open(os.path.join(temp,xmltv),"r")
lines = f.readlines()
total_lines = len(lines)
f.close()
li = 0
for line in lines:
if li == 0 or li == 1: pass
elif li == (total_lines -1): pass
else: o.write(line)
li += 1
o.close()
os.remove(os.path.join(temp,xmltv))
i += 1
print '[Rytec EPG Downloader]: merging files done'
示例8: Download
def Download(url,lang):
try: shutil.rmtree(__temp__)
except: pass
try: os.makedirs(__temp__)
except: pass
subtitle_list = []
exts = [".srt", ".sub", ".txt", ".smi", ".ssa", ".ass" ]
try:
socket = urllib.request.urlopen( url )
data = socket.read()
soup = BeautifulSoup(data)
id = soup.find("button", class_="btn btn-danger btn-sm").get("sid").encode('utf-8')
url = "http://www.subhd.com/ajax/down_ajax"
values = {'sub_id':id}
data = urllib.parse.urlencode(values)
req = urllib.request.Request(url, data)
response = urllib.request.urlopen(req)
data = response.read()
match = re.compile('"url":"([^"]+)"').search(data)
url = SUBHD_BASE + match.group(1).replace(r'\/','/').decode("unicode-escape").encode('utf-8')
socket = urllib.request.urlopen( url )
data = socket.read()
socket.close()
except:
return []
if len(data) < 1024:
return []
if data[:4] == 'Rar!':
zip = os.path.join(__temp__,"subtitles.rar")
elif data[:2] == 'PK':
zip = os.path.join(__temp__,"subtitles.zip")
else:
zip = os.path.join(__temp__,"subtitles.srt")
with open(zip, "wb") as subFile:
subFile.write(data)
subFile.close()
xbmc.sleep(500)
if not zip.endswith('.srt'):
xbmc.executebuiltin(('XBMC.Extract("%s","%s")' % (zip,__temp__,)).encode('utf-8'), True)
path = __temp__
dirs, files = xbmcvfs.listdir(path)
if len(dirs) > 0:
path = os.path.join(__temp__, dirs[0].decode('utf-8'))
dirs, files = xbmcvfs.listdir(path)
list = []
for subfile in files:
if (os.path.splitext( subfile )[1] in exts):
list.append(subfile.decode('utf-8'))
if len(list) == 1:
subtitle_list.append(os.path.join(path, list[0]))
else:
sel = xbmcgui.Dialog().select('请选择压缩包中的字幕', list)
if sel == -1:
sel = 0
subtitle_list.append(os.path.join(path, list[sel]))
return subtitle_list
示例9: delete_files
def delete_files(source, match, del_empty=False):
# delete files from source if match
dirs, files = xbmcvfs.listdir(source)
for f in files:
if match in f:
f = os.path.join(source, f)
xbmcvfs.delete(f)
# delete source directory if empty
if del_empty and len(xbmcvfs.listdir(source)) == 0:
xbmcvfs.rmdir(source)
示例10: __delete_files_alt
def __delete_files_alt(source, match, del_empty):
# delete files from source if match
dirs, files = xbmcvfs.listdir(source)
for f in files:
if match == os.path.splitext(f)[0]:
f = os.path.join(source, f)
xbmcvfs.delete(f)
# delete source directory if empty
if del_empty and len(xbmcvfs.listdir(source)) == 0:
xbmcvfs.rmdir(source)
示例11: Download
def Download(id,lang):
try: rmtree(__temp__)
except: pass
try: os.makedirs(__temp__)
except: pass
subtitle_list = []
exts = [".srt", ".sub", ".smi", ".ssa", ".ass" ]
url = DOWNLOAD_API % (id)
try:
socket = urllib.urlopen( url )
data = socket.read()
socket.close()
soup = BeautifulSoup(data)
url = soup.find("a", class_="down_ink download_link").get('href').encode('utf-8')
socket = urllib.urlopen( url )
#filename = socket.headers['Content-Disposition'].split('filename=')[1]
#if filename[0] == '"' or filename[0] == "'":
# filename = filename[1:-1]
filename = os.path.basename(url)
data = socket.read()
socket.close()
except:
return []
if len(data) < 1024:
return []
tempfile = os.path.join(__temp__, "subtitles%s" % os.path.splitext(filename)[1])
with open(tempfile, "wb") as subFile:
subFile.write(data)
subFile.close()
xbmc.sleep(500)
if data[:4] == 'Rar!' or data[:2] == 'PK':
xbmc.executebuiltin(('XBMC.Extract("%s","%s")' % (tempfile,__temp__,)).encode('utf-8'), True)
path = __temp__
dirs, files = xbmcvfs.listdir(path)
if ('__MACOSX') in dirs:
dirs.remove('__MACOSX')
if len(dirs) > 0:
path = os.path.join(__temp__, dirs[0].decode('utf-8'))
dirs, files = xbmcvfs.listdir(path)
list = []
for subfile in files:
if (os.path.splitext( subfile )[1] in exts):
list.append(subfile.decode('utf-8'))
if len(list) == 1:
subtitle_list.append(os.path.join(path, list[0]))
elif len(list) > 1:
sel = xbmcgui.Dialog().select('请选择压缩包中的字幕', list)
if sel == -1:
sel = 0
subtitle_list.append(os.path.join(path, list[sel]))
return subtitle_list
示例12: clear_parser_trace
def clear_parser_trace():
dirs,files = xbmcvfs.listdir(parser_core_folder)
import shutil
for directory in dirs:
shutil.rmtree(os.path.join(parser_core_folder,directory))
dirs,files = xbmcvfs.listdir(parser_packages_folder)
for fich in files:
xbmcvfs.delete(os.path.join(parser_packages_folder,fich))
dirs,files = xbmcvfs.listdir(parser_folder)
for fich in files:
xbmcvfs.delete(os.path.join(parser_folder,fich))
xbmc.executebuiltin("Notification(%s,%s,%i,%s)" % (translate(40000),translate(70007),1,addonpath+"/icon.png"))
示例13: __delete_files_alt
def __delete_files_alt(source, match, del_empty):
# delete files from source if match
dirs, files = xbmcvfs.listdir(source)
for f in files:
if os.path.splitext(f)[0].startswith(match):
f = os.path.join(source, f)
if not xbmcvfs.delete(f):
raise ValueError('xbmcvfs.delete', f)
# delete source directory if empty
if del_empty and len(xbmcvfs.listdir(source)) == 0:
if not xbmcvfs.rmdir(source):
raise ValueError('xbmcvfs.rmdir', source)
示例14: DownloadID
def DownloadID(id):
if xbmcvfs.exists(__temp__):
rmtree(__temp__)
xbmc.sleep(50)
xbmcvfs.mkdirs(__temp__)
subtitle_list = []
if id.startswith('999999'):
url = 'http://sub.makedie.me/download/%06d/%s' %(int(id[6:]), 'XBMC.SUBTITLE')
else:
url = 'http://shooter.cn/files/file3.php?hash=duei7chy7gj59fjew73hdwh213f&fileid=%s' % (id)
socket = urllib.urlopen( url )
data = socket.read()
url = 'http://file0.shooter.cn%s' % (CalcFileHash(data))
#log(sys._getframe().f_code.co_name ,"url is %s" % (url))
socket = urllib.urlopen( url )
data = socket.read()
socket.close()
header = data[:4]
if header == 'Rar!':
zipext = ".rar"
else: # header == 'PK':
zipext = ".zip"
zipname = 'SUBPACK%s' % (zipext)
zip = os.path.join( __temp__, zipname)
with open(zip, "wb") as subFile:
subFile.write(data)
subFile.close()
xbmc.sleep(500)
dirs, files = xbmcvfs.listdir(__temp__) # refresh xbmc folder cache
xbmc.executebuiltin(('XBMC.Extract("%s","%s")' % (zip,__temp__,)).encode('utf-8'), True)
path = __temp__
dirs, files = xbmcvfs.listdir(path)
list = CheckSubList(files)
if not list and len(dirs) > 0:
path = os.path.join(__temp__, dirs[0].decode('utf-8'))
dirs, files = xbmcvfs.listdir(path)
list = CheckSubList(files)
if list:
filename = list[0].decode('utf-8')
else:
filename = ''
if len(list) > 1:
dialog = xbmcgui.Dialog()
sel = dialog.select(__language__(32006), list)
if sel != -1:
filename = list[sel].decode('utf-8')
if filename:
filepath = os.path.join(path, filename)
ChangeFileEndcoding(filepath)
subtitle_list.append(filepath)
return subtitle_list
示例15: updatedb_from_exported
def updatedb_from_exported(self):
"""Adds movies and shows from exported media to the local db
Returns
-------
bool
Process finished
"""
tv_show_path = self.tvshow_path
db_filepath = self.db_filepath
if xbmcvfs.exists(self.nx_common.check_folder_path(self.movie_path)):
movies = xbmcvfs.listdir(self.movie_path)
for video in movies[0]:
folder = os.path.join(self.movie_path, video)
file = xbmcvfs.listdir(folder)
year = int(str(file[1]).split("(", 1)[1].split(")", 1)[0])
alt_title = unicode(video.decode('utf-8'))
title = unicode(video.decode('utf-8'))
movie_meta = '%s (%d)' % (title, year)
if self.movie_exists(title=title, year=year) is False:
self.db[self.movies_label][movie_meta] = {
'alt_title': alt_title}
self._update_local_db(filename=db_filepath, db=self.db)
if xbmcvfs.exists(self.nx_common.check_folder_path(tv_show_path)):
shows = xbmcvfs.listdir(tv_show_path)
for video in shows[0]:
show_dir = os.path.join(tv_show_path, video)
title = unicode(video.decode('utf-8'))
alt_title = unicode(video.decode('utf-8'))
show_meta = '%s' % (title)
if self.show_exists(title) is False:
self.db[self.series_label][show_meta] = {
'seasons': [],
'episodes': [],
'alt_title': alt_title}
episodes = xbmcvfs.listdir(show_dir)
for episode in episodes[1]:
file = str(episode).split(".")[0]
season = int(str(file).split("S")[1].split("E")[0])
episode = int(str(file).split("E")[1])
episode_meta = 'S%02dE%02d' % (season, episode)
episode_exists = self.episode_exists(
title=title,
season=season,
episode=episode)
if episode_exists is False:
self.db[self.series_label][title]['episodes'].append(episode_meta)
self._update_local_db(
filename=self.db_filepath,
db=self.db)
return True