refactor program selection

This commit is contained in:
Ronald Schaten 2021-03-15 16:54:39 +01:00
parent 038271f57f
commit e501098f66

View File

@ -12,12 +12,23 @@ CWD = ADDON.getAddonInfo('path').decode('utf-8')
def list_programs(cinematic_path):
dirs, files = xbmcvfs.listdir(cinematic_path)
programs = []
programs = {}
for filename in files:
if filename.endswith('.json'):
programs.append(filename)
filehandle = xbmcvfs.File(cinematic_path + filename)
program_json = filehandle.read()
filehandle.close()
program_data = json.loads(program_json)
programs[program_data['name']] = filename
return programs
def show_dialog(programs):
entries = programs.keys()
dialog = xbmcgui.Dialog()
ret = dialog.select('Cinematic: Select a program', entries)
del dialog
return programs[entries[ret]]
def files_from_dir(count, location):
print("fetching %d files from %s" % (count, location))
dirs, files = xbmcvfs.listdir(location)
@ -40,12 +51,7 @@ if __name__ == '__main__':
cinematic_path = ADDON.getSettingString('cinematic_path')
programs = list_programs(cinematic_path)
dialog = xbmcgui.Dialog()
ret = dialog.select('Cinematic: Select a program', programs)
del dialog
program_file = cinematic_path + programs[ret]
program_file = cinematic_path + show_dialog(programs)
filehandle = xbmcvfs.File(program_file)
program_json = filehandle.read()