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):
|
|
|
|
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
|
|
|
|
|
2021-03-15 21:02:42 +01:00
|
|
|
def conduct_program(program_file, feature):
|
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)
|
2021-03-15 17:13:26 +01:00
|
|
|
program = []
|
2021-03-15 15:35:24 +01:00
|
|
|
for item in program_data['items']:
|
|
|
|
settings = item['settings']
|
|
|
|
if settings['source'] == 'file':
|
2021-03-15 17:13:26 +01:00
|
|
|
entry = {'type': 'video', 'data': settings['location']}
|
|
|
|
program.append(entry)
|
2021-03-15 15:35:24 +01:00
|
|
|
elif settings['source'] == 'dir':
|
2021-03-15 17:13:26 +01:00
|
|
|
for location in files_from_dir(settings['count'], settings['location']):
|
|
|
|
entry = {'type': 'video', 'data': location}
|
|
|
|
program.append(entry)
|
2021-03-15 15:35:24 +01:00
|
|
|
elif settings['source'] == 'trailer':
|
|
|
|
genre = 'TODO: find feature genre'
|
|
|
|
rating = 'TODO: find feature rating'
|
2021-03-15 17:13:26 +01:00
|
|
|
for location in trailers_from_net(settings['count'], genre, rating):
|
|
|
|
entry = {'type': 'video', 'data': location}
|
|
|
|
program.append(entry)
|
2021-03-15 15:35:24 +01:00
|
|
|
elif settings['source'] == 'feature':
|
2021-03-15 21:02:42 +01:00
|
|
|
entry = {'type': 'video', 'data': feature['file']}
|
2021-03-15 17:13:26 +01:00
|
|
|
program.append(entry)
|
|
|
|
return program
|
|
|
|
|
2021-03-15 21:02:42 +01:00
|
|
|
def get_feature(movieid):
|
|
|
|
query = '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": {"movieid": %s, "properties": ["file", "mpaa", "genre"]}, "id": "1"}' % movieid
|
|
|
|
json_response = xbmc.executeJSONRPC(query)
|
|
|
|
response = json.loads(json_response)
|
|
|
|
feature = {
|
|
|
|
'label': response['result']['moviedetails']['label'],
|
|
|
|
'file': response['result']['moviedetails']['file'],
|
|
|
|
'mpaa': response['result']['moviedetails']['mpaa'],
|
|
|
|
'genre': response['result']['moviedetails']['genre']
|
|
|
|
}
|
|
|
|
return feature
|
|
|
|
|
2021-03-15 17:13:26 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
for arg in sys.argv[1:]:
|
|
|
|
(name, value) = arg.split('=')
|
|
|
|
if name == 'dbid':
|
2021-03-15 21:02:42 +01:00
|
|
|
movieid = int(value)
|
2021-03-15 17:13:26 +01:00
|
|
|
|
|
|
|
cinematic_path = ADDON.getSettingString('cinematic_path')
|
2021-03-15 21:02:42 +01:00
|
|
|
feature = get_feature(movieid)
|
|
|
|
print(feature)
|
2021-03-15 17:13:26 +01:00
|
|
|
programs = list_programs(cinematic_path)
|
|
|
|
program_file = cinematic_path + show_dialog(programs)
|
2021-03-15 21:02:42 +01:00
|
|
|
program = conduct_program(program_file, feature)
|
2021-03-15 15:35:24 +01:00
|
|
|
|
|
|
|
print('=== playlist')
|
2021-03-15 17:13:26 +01:00
|
|
|
for entry in program:
|
|
|
|
print(" * [%s] -- %s" % (entry['type'], entry['data']))
|