Skip to content

Commit

Permalink
OPENCAST-1931 Update Galicaster to use much faster endpoint /series/a…
Browse files Browse the repository at this point in the history
…llSeriesIdTitle.json

#547
  • Loading branch information
smarquard authored and Alfro committed Jan 18, 2019
1 parent c066b5a commit bf51aef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 35 deletions.
2 changes: 1 addition & 1 deletion galicaster/opencast/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
SETCONF_ENDPOINT = 'capture-admin/agents/{hostname}/configuration'
INGEST_ENDPOINT = 'ingest/addZippedMediaPackage'
ICAL_ENDPOINT = 'recordings/calendars'
SERIES_ENDPOINT = 'series/series.json'
SERIES_ENDPOINT = 'series/allSeriesIdTitle.json'
SERVICE_REGISTRY_ENDPOINT = 'services/available.json'
SEARCH_ENDPOINT = 'search/episode.json'
WORKFLOWS_ENDPOINT = 'workflow/definitions.json'
Expand Down
53 changes: 19 additions & 34 deletions galicaster/opencast/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
import getpass


NAMESP = 'http://purl.org/dc/terms/'
DISALLOWED_QUERIES = [ 'q', 'edit', 'sort', 'startPage', 'count', 'default' ]
RESULTS_PER_PAGE = 100
MAPPINGS = { 'user': getpass.getuser() }


Expand All @@ -32,7 +30,7 @@ def get_series():
series_conf = context.get_conf().get_section('series')

# Init 'queries' dictionary
queries = {'startPage': 0, 'count': RESULTS_PER_PAGE}
queries = { }

# Filter out keys that do not refer to a certain series property
# Also, substitute any placeholder(s) used to filter the series
Expand All @@ -48,28 +46,16 @@ def get_series():

try:
series_list = []
check_default = True
while True:
if not ocservice.net:
break

series_json = json.loads(ocservice.client.getseries(**queries))
for catalog in series_json['catalogs']:
try:
series_list.append(parse_json_series(catalog))
except KeyError:
# Ignore ill-formated series
pass
if len(series_list) >= int(series_json['totalCount']):
# Check the default series is present, otherwise query for it
if 'default' in series_conf and check_default and series_conf['default'] not in dict(series_list):
check_default = False
queries = { "seriesId": series_conf['default'] }
else:
break
else:
queries['startPage'] += 1
series_json = json.loads(ocservice.client.getseries(**queries))

for catalog in series_json['series']:
try:
series_list.append(parse_json_series(catalog))
except KeyError:
# Ignore ill-formated series
pass

series_list = sorted(series_list, key=lambda series: series[1]['title']);
repo.save_attach('series.json', json.dumps(series_list))

except (ValueError, IOError, RuntimeError, AttributeError):
Expand All @@ -85,16 +71,15 @@ def get_series():

def parse_json_series(json_series):
series = {}
for term in json_series[NAMESP].iterkeys():
try:
series[term] = json_series[NAMESP][term][0]['value']
except (KeyError, IndexError):
# Ignore non-existant items
# TODO Log the exception
pass

return (series['identifier'], series )

try:
series['identifier'] = json_series['identifier']
series['title'] = json_series['title']
except (KeyError, IndexError):
# Ignore non-existant items
# TODO Log the exception
pass

return (series['identifier'], series)

def transform(a):
return a.strip()
Expand Down

0 comments on commit bf51aef

Please sign in to comment.