Commit 73b64b01 authored by birk's avatar birk
Browse files

Re-integrate followup-programs

parent 13636b03
......@@ -3,25 +3,31 @@ from random import shuffle
from pyglet.event import EventDispatcher
from content.api import MediaEntryParams
from system.config import Config
from content.apidata import KeywordData, PeopleData
class Program(EventDispatcher):
def __init__(self, api_, json_):
def __init__(self, api_, json_=None):
EventDispatcher.__init__(self)
self._api = api_
self._name = json_['name']
self._params = MediaEntryParams(json_.get('parameters'))
self._meta_data_white_list = json_.get('meta_data')
self._limit = int(json_.get('limit', 20))
self._meta_data_white_list = Config().meta_data_white_list
self._limit = 20
if json_:
self.parse_json(json_)
self._limit_selection = self._limit
if json_.get('limit_selection'):
self._limit_selection = int(json_.get('limit_selection'))
self._start_url = None
self._playlist = None
self.__index = None
def parse_json(self, json_):
self._name = json_['name']
self._params = MediaEntryParams(json_.get('parameters'))
self._meta_data_white_list = json_.get('meta_data')
self._limit = int(json_.get('limit', self._limit))
if json_.get('limit_selection'):
self._limit_selection = int(json_.get('limit_selection'))
def set_limit(self, limit_=0):
self._limit = limit_
......@@ -95,8 +101,8 @@ class Program(EventDispatcher):
class FollowupProgram(Program):
def __init__(self, api_, name_, meta_data_white_list_=None, limit_=0, limit_selection_=0):
super(FollowupProgram, self).__init__(api_, name_, None, meta_data_white_list_, limit_, limit_selection_)
def __init__(self, api_):
super(FollowupProgram, self).__init__(api_)
def set_reference(self, reference_program_):
print('set_reference {}'.format(reference_program_))
......@@ -140,17 +146,11 @@ class FollowupProgram(Program):
else:
self._name = str(hook)
print('---- unrecognized meta_key_id {} ----'.format(hook.meta_key_id))
self._params = MediaEntryParams(
filter_by_={"media_files": [{"key": "media_type", "value": "image"}],
"meta_data": [{"key": hook.meta_key_id, "value": hook.id}]}
)
self._params = MediaEntryParams({"filter_by": {"meta_data": [{"key": hook.meta_key_id, "value": hook.id}]}})
elif type(hook) is PeopleData:
# TODO: Maybe make do author selection?
self._name = 'Person {}'.format(hook)
self._params = MediaEntryParams(
filter_by_={"media_files": [{"key": "media_type", "value": "image"}],
"meta_data": [{"key": "any", "value": hook.id, "type": "MetaDatum::People"}]}
)
self._params = MediaEntryParams({"filter_by": {"meta_data": [{"key": "any", "value": hook.id, "type": "MetaDatum::People"}]}})
return True
else:
return False
......@@ -60,27 +60,29 @@ class Main(object):
def load_program(self):
program = None
last_program = self._dispatcher.program
while not program or not program.valid:
self._program_index = (self._program_index + 1) % len(self._programs)
program = self._programs[self._program_index]
# Decide whether to try a followup program
if self._followups and last_program and type(last_program) is not FollowupProgram:
program = FollowupProgram(self._api)
if program and program.set_reference(last_program):
print('***** load_program followup {} *****'.format(program._name))
else:
self._program_index = (self._program_index + 1) % len(self._programs)
program = self._programs[self._program_index]
print('***** load_program {} *****'.format(program._name))
# is is a followup program?
if type(program) == FollowupProgram and self._dispatcher.program:
if not program.set_reference(self._dispatcher.program):
print('--- invalid followup program ---')
break
loop = self._api.start_session()
future = asyncio.ensure_future(program.load())
loop.run_until_complete(future)
self._api.complete_session()
if program.valid:
try:
self._dispatcher.set_program(program)
self._dispatcher.start()
except AssertionError:
print('Error loading program.')
else:
print("---- invalid program ----")
if program.valid:
try:
self._dispatcher.set_program(program)
self._dispatcher.start()
except AssertionError:
print('Error loading program.')
else:
print("---- invalid program ----")
if __name__ == '__main__':
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment