def getLocalChannelLogo(channel_name):
logo_path = xbmcaddon.Addon().getSetting('logoPath')
if not logo_path == '' and xbmcvfs.exists(logo_path):
dirs, files = xbmcvfs.listdir(logo_path)
for f in files:
if f.lower().endswith('.png'):
if channel_name.lower().replace(' ', '') == os.path.basename(f).lower().replace('.png', '').replace(' ', ''):
return os.path.join(logo_path, f)
return None
python类listdir()的实例源码
backuprestore.py 文件源码
项目:script.skin.helper.skinbackup
作者: marcelveldt
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def restore(self, filename="", silent=False):
'''restore skin settings from file'''
if not filename:
filename = self.get_restorefilename()
progressdialog = None
if not silent:
progressdialog = xbmcgui.DialogProgress(self.addon.getLocalizedString(32006))
progressdialog.create(self.addon.getLocalizedString(32007))
if filename and xbmcvfs.exists(filename):
# create temp path
temp_path = self.create_temp()
if not filename.endswith("zip"):
# assume that passed filename is actually a skinsettings file
skinsettingsfile = filename
else:
# copy zip to temp directory and unzip
skinsettingsfile = temp_path + "guisettings.txt"
if progressdialog:
progressdialog.update(0, "unpacking backup...")
zip_temp = u'%sskinbackup-%s.zip' % (ADDON_DATA, datetime.now().strftime('%Y-%m-%d-%H-%M'))
copy_file(filename, zip_temp, True)
unzip_fromfile(zip_temp, temp_path)
delete_file(zip_temp)
# copy skinshortcuts preferences
self.restore_skinshortcuts(temp_path)
# restore any custom skin images or themes
for directory in ["custom_images/", "themes/"]:
custom_images_folder = u"special://profile/addon_data/%s/%s" % (xbmc.getSkinDir(), directory)
custom_images_folder_temp = temp_path + directory
if xbmcvfs.exists(custom_images_folder_temp):
for file in xbmcvfs.listdir(custom_images_folder_temp)[1]:
xbmcvfs.copy(custom_images_folder_temp + file,
custom_images_folder + file)
# restore guisettings
if xbmcvfs.exists(skinsettingsfile):
self.restore_guisettings(skinsettingsfile, progressdialog)
# cleanup temp
recursive_delete_dir(temp_path)
progressdialog.close()
if not silent:
xbmcgui.Dialog().ok(self.addon.getLocalizedString(32006), self.addon.getLocalizedString(32009))
def remove_show(self, title):
"""Removes the DB entry & the strm files for the show given
Parameters
----------
title : :obj:`str`
Title of the show
Returns
-------
bool
Delete successfull
"""
title = re.sub(r'[?|$|!|:|#]', r'', title)
label = self.series_label
rep_str = self.db[label][title]['alt_title'].encode('utf-8')
folder = re.sub(
pattern=r'[?|$|!|:|#]',
repl=r'',
string=rep_str)
progress = xbmcgui.DialogProgress()
progress.create(self.kodi_helper.get_local_string(1210), title)
time.sleep(0.5)
del self.db[self.series_label][title]
self._update_local_db(filename=self.db_filepath, db=self.db)
show_dir = self.kodi_helper.check_folder_path(
path=os.path.join(self.tvshow_path, folder))
if xbmcvfs.exists(show_dir):
show_files = xbmcvfs.listdir(show_dir)[1]
episode_count_total = len(show_files)
step = round(100.0 / episode_count_total, 1)
percent = 100 - step
for filename in show_files:
progress.update(int(percent))
xbmcvfs.delete(os.path.join(show_dir, filename))
percent = percent - step
time.sleep(0.05)
xbmcvfs.rmdir(show_dir)
return True
return False
time.sleep(1)
progress.close()
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.kodi_helper.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.kodi_helper.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