refactor program conduction

This commit is contained in:
Ronald Schaten 2021-03-15 17:13:26 +01:00
parent e501098f66
commit c5b1c78117

View File

@ -30,7 +30,6 @@ def show_dialog(programs):
return programs[entries[ret]]
def files_from_dir(count, location):
print("fetching %d files from %s" % (count, location))
dirs, files = xbmcvfs.listdir(location)
files = random.sample(files, count)
for i in range(len(files)):
@ -43,6 +42,32 @@ def trailers_from_net(count, genre, rating):
files.append("TODO: find trailer %d" % i)
return files
def conduct_program(program_file):
filehandle = xbmcvfs.File(program_file)
program_json = filehandle.read()
filehandle.close()
program_data = json.loads(program_json)
program = []
for item in program_data['items']:
settings = item['settings']
if settings['source'] == 'file':
entry = {'type': 'video', 'data': settings['location']}
program.append(entry)
elif settings['source'] == 'dir':
for location in files_from_dir(settings['count'], settings['location']):
entry = {'type': 'video', 'data': location}
program.append(entry)
elif settings['source'] == 'trailer':
genre = 'TODO: find feature genre'
rating = 'TODO: find feature rating'
for location in trailers_from_net(settings['count'], genre, rating):
entry = {'type': 'video', 'data': location}
program.append(entry)
elif settings['source'] == 'feature':
entry = {'type': 'video', 'data': ("TODO: find feature %d" % dbid)}
program.append(entry)
return program
if __name__ == '__main__':
for arg in sys.argv[1:]:
(name, value) = arg.split('=')
@ -52,29 +77,8 @@ if __name__ == '__main__':
cinematic_path = ADDON.getSettingString('cinematic_path')
programs = list_programs(cinematic_path)
program_file = cinematic_path + show_dialog(programs)
filehandle = xbmcvfs.File(program_file)
program_json = filehandle.read()
filehandle.close()
program_data = json.loads(program_json)
print("=== conducting program %s" % program_data['name'])
filelist = []
for item in program_data['items']:
print("selecting %s" % item['name'])
settings = item['settings']
if settings['source'] == 'file':
filelist.append(settings['location'])
elif settings['source'] == 'dir':
filelist.extend(files_from_dir(settings['count'], settings['location']))
elif settings['source'] == 'trailer':
genre = 'TODO: find feature genre'
rating = 'TODO: find feature rating'
filelist.extend(trailers_from_net(settings['count'], genre, rating))
elif settings['source'] == 'feature':
filelist.append("TODO: find feature %d" % dbid)
program = conduct_program(program_file)
print('=== playlist')
for filename in filelist:
print(" * %s" % filename)
for entry in program:
print(" * [%s] -- %s" % (entry['type'], entry['data']))