Skip to content

Commit

Permalink
Update Opencast client series endpoint (#641)
Browse files Browse the repository at this point in the history
* Update Opencast client series endpoint

* Add CI deps
  • Loading branch information
pnieto authored Jul 17, 2024
1 parent 46413b4 commit 453172a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 28 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ jobs:
sudo apt-get install python3-pil
sudo apt-get install python3-simplejson
sudo apt-get install python3-ldap
#sudo apt-get install python3-gst-1.0
sudo apt-get install python3-dogtail
sudo apt-get install flake8
sudo apt-get install python3-nose
Expand Down Expand Up @@ -56,7 +55,6 @@ jobs:
run: |
sudo apt-get install gstreamer1.0-plugins-base
sudo apt-get install gstreamer1.0-plugins-base-apps
#sudo apt-get install gstreamer1.0-plugins-bad
sudo apt-get install gstreamer1.0-plugins-ugly
sudo apt-get install gstreamer1.0-plugins-good
sudo apt-get install gstreamer1.0-plugins-bad-videoparsers
Expand All @@ -68,6 +66,7 @@ jobs:
sudo apt-get install gir1.2-gstreamer-1.0
sudo apt-get install gir1.2-gtk-3.0
sudo apt-get install gir1.2-gst-plugins-base-1.0
sudo pip install pyautogui
- name: Run test
run: make test-travis
25 changes: 23 additions & 2 deletions galicaster/opencast/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from collections import OrderedDict
import urllib.parse
import urllib.request, urllib.parse, urllib.error
from packaging.version import Version
from galicaster.utils.miscellaneous import get_timezone

try:
Expand All @@ -35,10 +36,12 @@
SETCONF_ENDPOINT = 'capture-admin/agents/{hostname}/configuration'
INGEST_ENDPOINT = 'ingest/addZippedMediaPackage'
ICAL_ENDPOINT = 'recordings/calendars'
SERIES_ENDPOINT = 'series/series.json'
#TODO use external API
SERIES_ENDPOINT = 'admin-ng/series/series.json'
SERVICE_REGISTRY_ENDPOINT = 'services/available.json'
SEARCH_ENDPOINT = 'search/episode.json'
WORKFLOWS_ENDPOINT = 'workflow/definitions.json'
HEALTH_ENDPOINT = 'info/health'

SEARCH_SERVICE_TYPE = 'org.opencastproject.search'
INGEST_SERVICE_TYPE = 'org.opencastproject.ingest'
Expand Down Expand Up @@ -364,10 +367,24 @@ def ingest(self, mp_file, mp_id, workflow=None, workflow_instance=None, workflow

def getseries(self, **query):
""" Get series according to the page count and offset provided"""
series_endpoint = SERIES_ENDPOINT
try:
version = Version(self.get_opencast_version())
except Exception as exc:
self.logger and self.logger.error("Getting Opencast Version %s",version)
raise Exception

return self.__call('GET', SERIES_ENDPOINT, query_params = query)
if (version < Version('6.0.0')):
self.logger and self.logger.error("Opencast %s version not suported",version)
raise Exception
if self.logger:
self.logger.info( 'Getting series from Server %s', self.server)
return self.__call('GET', series_endpoint, query_params = query)


def countSeries(self):
return self.__call('GET', 'series/count')

def get_workflows(self, server=None):
""" Get workflow names """
theServer = server or self.server
Expand All @@ -393,6 +410,10 @@ def get_workflows(self, server=None):

return workflows

def get_opencast_version(self):
info_health = json.loads(self.__call('GET', HEALTH_ENDPOINT))
return info_health['releaseId'].replace(".SNAPSHOT","")


def find_between(self, s, first, last):
try:
Expand Down
60 changes: 36 additions & 24 deletions galicaster/opencast/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

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


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

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

if not ocservice.net:
series_list = load_series_from_file()
return series_list

# Filter out keys that do not refer to a certain series property
# Also, substitute any placeholder(s) used to filter the series
Expand All @@ -49,51 +53,59 @@ def get_series():
try:
series_list = []
check_default = True
while True:
if not ocservice.net:
break

series_total = int(ocservice.client.countSeries())

for i in range(0,series_total,RESULTS_PER_PAGE):
queries['offset']=i
series_json = json.loads(ocservice.client.getseries(**queries))
for catalog in series_json['catalogs']:

if (int(series_json['count'])==0):
break

for serie in series_json['results']:
try:
series_list.append(parse_json_series(catalog))
series_list.append(parse_json_series(serie))
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

# 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

repo.save_attach('series.json', json.dumps(series_list))

except (ValueError, IOError, RuntimeError, AttributeError):
#TODO Log the exception
try:
series_list = json.load(repo.get_attach('series.json'))
except (ValueError, IOError):
#TODO Log the exception
series_list = []
series_list = load_series_from_file()

return series_list

def load_series_from_file():
try:
series_list = json.load(repo.get_attach('series.json'))
except (ValueError, IOError):
#TODO Log the exception
series_list = []

def parse_json_series(json_series):
series = {}
for term in list(json_series[NAMESP].keys()):
#{"identifier": "2886ab13-e292-4272-9361-7d055bf6c14c", "created": "2019-12-02T07:09:26Z", "title": "18/19 Better Lives"}]
for term in ['id','creation_date','title']:
try:
series[term] = json_series[NAMESP][term][0]['value']
series[term] = json_series[term]
except (KeyError, IndexError):
# Ignore non-existant items
# TODO Log the exception
pass

return (series['identifier'], series )
return (series['id'], series)


def transform(a):
Expand Down

0 comments on commit 453172a

Please sign in to comment.