refactor program selection
This commit is contained in:
parent
038271f57f
commit
e501098f66
22
addon.py
22
addon.py
@ -12,12 +12,23 @@ CWD = ADDON.getAddonInfo('path').decode('utf-8')
|
|||||||
|
|
||||||
def list_programs(cinematic_path):
|
def list_programs(cinematic_path):
|
||||||
dirs, files = xbmcvfs.listdir(cinematic_path)
|
dirs, files = xbmcvfs.listdir(cinematic_path)
|
||||||
programs = []
|
programs = {}
|
||||||
for filename in files:
|
for filename in files:
|
||||||
if filename.endswith('.json'):
|
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
|
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):
|
def files_from_dir(count, location):
|
||||||
print("fetching %d files from %s" % (count, location))
|
print("fetching %d files from %s" % (count, location))
|
||||||
dirs, files = xbmcvfs.listdir(location)
|
dirs, files = xbmcvfs.listdir(location)
|
||||||
@ -40,12 +51,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
cinematic_path = ADDON.getSettingString('cinematic_path')
|
cinematic_path = ADDON.getSettingString('cinematic_path')
|
||||||
programs = list_programs(cinematic_path)
|
programs = list_programs(cinematic_path)
|
||||||
|
program_file = cinematic_path + show_dialog(programs)
|
||||||
dialog = xbmcgui.Dialog()
|
|
||||||
ret = dialog.select('Cinematic: Select a program', programs)
|
|
||||||
del dialog
|
|
||||||
|
|
||||||
program_file = cinematic_path + programs[ret]
|
|
||||||
|
|
||||||
filehandle = xbmcvfs.File(program_file)
|
filehandle = xbmcvfs.File(program_file)
|
||||||
program_json = filehandle.read()
|
program_json = filehandle.read()
|
||||||
|
Loading…
Reference in New Issue
Block a user