2021-03-15 15:35:24 +01:00
|
|
|
import xbmc
|
|
|
|
import xbmcgui
|
|
|
|
import xbmcaddon
|
|
|
|
import xbmcvfs
|
|
|
|
import json
|
|
|
|
import random
|
|
|
|
import sys
|
|
|
|
|
|
|
|
ADDON = xbmcaddon.Addon()
|
|
|
|
CWD = ADDON.getAddonInfo('path').decode('utf-8')
|
|
|
|
#CWD = ADDON.getAddonInfo('path') # for kodi 19
|
|
|
|
|
2021-03-15 16:33:10 +01:00
|
|
|
def list_programs(cinematic_path):
|
|
|
|
dirs, files = xbmcvfs.listdir(cinematic_path)
|
2021-03-15 16:54:39 +01:00
|
|
|
programs = {}
|
2021-03-15 16:33:10 +01:00
|
|
|
for filename in files:
|
|
|
|
if filename.endswith('.json'):
|
2021-03-15 16:54:39 +01:00
|
|
|
filehandle = xbmcvfs.File(cinematic_path + filename)
|
|
|
|
program_json = filehandle.read()
|
|
|
|
filehandle.close()
|
|
|
|
program_data = json.loads(program_json)
|
|
|
|
programs[program_data['name']] = filename
|
2021-03-15 16:33:10 +01:00
|
|
|
return programs
|
|
|
|
|
2021-03-15 16:54:39 +01:00
|
|
|
def show_dialog(programs):
|
|
|
|
entries = programs.keys()
|
|
|
|
dialog = xbmcgui.Dialog()
|
|
|
|
ret = dialog.select('Cinematic: Select a program', entries)
|
|
|
|
del dialog
|
|
|
|
return programs[entries[ret]]
|
|
|
|
|
2021-03-15 15:35:24 +01:00
|
|
|
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)):
|
|
|
|
files[i] = location + files[i]
|
|
|
|
return files
|
|
|
|
|
|
|
|
def trailers_from_net(count, genre, rating):
|
|
|
|
files = []
|
|
|
|
for i in range(count):
|
|
|
|
files.append("TODO: find trailer %d" % i)
|
|
|
|
return files
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
for arg in sys.argv[1:]:
|
|
|
|
(name, value) = arg.split('=')
|
|
|
|
if name == 'dbid':
|
|
|
|
dbid = int(value)
|
|
|
|
|
2021-03-15 16:33:10 +01:00
|
|
|
cinematic_path = ADDON.getSettingString('cinematic_path')
|
|
|
|
programs = list_programs(cinematic_path)
|
2021-03-15 16:54:39 +01:00
|
|
|
program_file = cinematic_path + show_dialog(programs)
|
2021-03-15 15:35:24 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
print('=== playlist')
|
|
|
|
for filename in filelist:
|
|
|
|
print(" * %s" % filename)
|