Beispiel #1
0
def check_series_of_events(events, series, error_collector, progress_printer, no_series_error):
    """
    Get series for each event if it belongs to one. If some of them are malformed, collect their errors.

    :param events: The events of the current tenant
    :type events: list
    :param series: The series of the current tenant
    :type series: list
    :param error_collector: The error collector
    :type error_collector: ErrorCollector
    :param progress_printer: The progress printer
    :type progress_printer: ProgressPrinter
    :param no_series_error: Whether events without series are considered malformed
    :type no_series_error: bool
    :return: Map with event id and the associated series or None
    :rtype: dict
    """

    event_series_map = {}

    for count, event in enumerate(events):

        series_of_event = get_series_of_event(series, event, no_series_error)

        if isinstance(series_of_event, Malformed):
            error_collector.collect_errors(series_of_event, get_id(event))

        event_series_map[get_id(event)] = series_of_event

        progress_printer.print_progress(count+1, len(events))

    return event_series_map
Beispiel #2
0
def check_assets_of_events(events, event_series_map, series_asset_map, opencast_url, digest_login, asset_description,
                           error_collector, progress_printer):
    """
    Get ACLs or Dublin Cores of all events and put them in a dict. If some of them are malformed, collect their errors.

    :param events: The events of the current tenant
    :type events: list
    :param event_series_map: Dictionary mapping events to their series
    :type event_series_map: dict
    :param series_asset_map: Dictionary mapping series to their assets
    :type series_asset_map: dict
    :param opencast_url: The URL to an opencast instance
    :type opencast_url: str
    :param digest_login: The login data for digest authentication
    :type digest_login: DigestLogin
    :param asset_description: ACLs or Dublin Core catalogs
    :type asset_description: AssetDescription
    :param error_collector: The error collector
    :type error_collector: ErrorCollector
    :param progress_printer: The progress printer
    :type progress_printer: ProgressPrinter
    :return: Map with event ids and the associated assets
    :rtype: dict
    """

    event_asset_map = {}

    for count, event in enumerate(events):

        series_of_event = event_series_map[get_id(event)]

        if series_of_event and not isinstance(series_of_event, Malformed):
            series_asset_of_series = series_asset_map[get_id(series_of_event)]
        else:
            series_asset_of_series = None

        episode_asset, series_asset = get_assets_of_event(event, opencast_url, digest_login, series_of_event,
                                                          series_asset_of_series, asset_description)

        if isinstance(episode_asset, Malformed):
            error_collector.collect_errors(episode_asset, get_id(event))
        if isinstance(series_asset, Malformed):
            error_collector.collect_errors(series_asset, get_id(event))

        event_asset_map[get_id(event)] = (episode_asset, series_asset)

        progress_printer.print_progress(count+1, len(events))

    return event_asset_map
Beispiel #3
0
def __get_dcs_of_event(event, base_url, digest_login):
    """
    Get two lists for episode and series Dublin Core catalogs for a given event.

    :param event: The event
    :type event: dict
    :param base_url: The base URL for the request
    :type base_url: str
    :param digest_login: The login credentials for digest authentication
    :type digest_login: DigestLogin
    :return: The episode and series Dublin Core catalogs
    :rtype: list, list
    :raise RequestError:
    """

    url = '{}/admin-ng/event/{}/asset/catalog/catalogs.json'.format(base_url, get_id(event))

    response = get_request(url, digest_login, ElementDescription.EVENT.unknown(), AssetTypeDescription.BOTH.plural(),
                           AssetDescription.DC.plural())

    json_content = get_json_content(response)

    episode_dcs = [__get_asset_content(catalog, digest_login, ElementDescription.EVENT.unknown(),
                                       AssetTypeDescription.EPISODE.singular(), AssetDescription.DC.singular())
                   for catalog in json_content if "dublincore/episode" in catalog["type"]]
    series_dcs = [__get_asset_content(catalog, digest_login, ElementDescription.EVENT.unknown(),
                                      AssetTypeDescription.SERIES.singular(), AssetDescription.DC.singular())
                  for catalog in json_content if "dublincore/series" in catalog["type"]]

    return episode_dcs, series_dcs
Beispiel #4
0
def __get_dc_of_series(series, base_url, digest_login):
    """
    Get the series Dublin Core catalog for a given series.

    :param series: The series
    :type series: dict
    :param base_url: The base URL for the request
    :type base_url: str
    :param digest_login: The login credentials for digest authentication
    :type digest_login: DigestLogin
    :return: The series Dublin Core catalog
    :rtype: ElementTree.Element
    :raise RequestError:
    """

    url = '{}/series/{}.xml'.format(base_url, get_id(series))

    es = ElementDescription.SERIES
    es = es.unknown()

    response = get_request(url, digest_login, es, AssetTypeDescription.SERIES.singular(),
                           AssetDescription.DC.singular())

    series_dc = get_xml_content(response)

    return series_dc
Beispiel #5
0
def __get_acls_of_event(event, base_url, digest_login):
    """
    Get two lists for episode and series ACLs for a given event.

    :param event: The event
    :type event: dict
    :param base_url: The base URL for the request
    :type base_url: str
    :param digest_login: The login credentials for digest authentication
    :type digest_login: DigestLogin
    :return: The episode and series acls
    :rtype: list, list
    :raise RequestError:
    """

    url = '{}/admin-ng/event/{}/asset/attachment/attachments.json'.format(base_url, get_id(event))

    response = get_request(url, digest_login, ElementDescription.EVENT.unknown(), AssetTypeDescription.BOTH.plural(),
                           AssetDescription.ACL.plural())

    json_content = get_json_content(response)

    episode_acls = [__get_asset_content(acl, digest_login, ElementDescription.EVENT.unknown(),
                                        AssetTypeDescription.EPISODE.singular(), AssetDescription.ACL.singular())
                    for acl in json_content if "security-policy-episode" in acl["id"]]
    series_acls = [__get_asset_content(acl, digest_login, ElementDescription.EVENT.unknown(),
                                       AssetTypeDescription.SERIES.singular(), AssetDescription.ACL.singular())
                   for acl in json_content if "security-policy-series" in acl["id"]]

    return episode_acls, series_acls
Beispiel #6
0
def __get_acl_of_series(series, base_url, digest_login):
    """
    Get the series ACL for a given series.

    :param series: The series
    :type series: dict
    :param base_url: The base URL for the request
    :type base_url: str
    :param digest_login: The login credentials for digest authentication
    :type digest_login: DigestLogin
    :return: The series ACL
    :rtype: dict
    :raise RequestError:
    """

    url = "{}/series/{}/acl.json".format(base_url, get_id(series))

    response = get_request(url, digest_login, ElementDescription.SERIES.unknown(),
                           AssetTypeDescription.SERIES.singular(),
                           AssetDescription.ACL.singular())

    json_content = get_json_content(response)

    series_acl = json_content["acl"]

    return series_acl
Beispiel #7
0
def main():
    """
    Export video files
    """

    event_ids, series_ids = parse_args()
    digest_login = DigestLogin(user=config.digest_user,
                               password=config.digest_pw)

    # get events from all series
    if series_ids:
        print("Getting events for series.")
        events = []
        for series_id in series_ids:
            try:
                events_of_series = get_events_of_series(
                    config.url, digest_login, series_id)
                events += events_of_series
            except Exception as e:
                print("Events of series {} could not be requested: {}".format(
                    series_id, str(e)))

        if not events:
            __abort_script("No events found.")

        event_ids = [get_id(event) for event in events]

    print("Starting export process.")
    for event_id in event_ids:
        try:
            print("Exporting videos of media package {}".format(event_id))

            mp_xml = get_media_package(config.url, digest_login, event_id)

            mp = parse_manifest_from_endpoint(mp_xml, event_id, False, True)

            if config.create_series_dirs and mp.series_id:
                mp_dir = os.path.join(config.target_directory, mp.series_id,
                                      mp.id)
            else:
                mp_dir = os.path.join(config.target_directory, mp.id)
            export_videos(mp, mp_dir, config.url, digest_login,
                          config.export_archived, config.export_publications,
                          config.export_mimetypes, config.export_flavors,
                          config.stream_security)

        except Exception as e:
            print(
                "Tracks of media package {} could not be exported: {}".format(
                    event_id, str(e)))

    print("Done.")
Beispiel #8
0
def check_assets_of_series(series, opencast_url, digest_login, asset_description, error_collector, progress_printer):
    """
    Get ACLs or Dublin Cores of all series and put them in a dict. If some of them are malformed, collect their errors.

    :param series: all series
    :type series: list
    :param opencast_url: The URL to an opencast instance
    :type opencast_url: str
    :param digest_login: The login data for digest authentication
    :type digest_login: DigestLogin
    :param asset_description: ACLs or Dublin Core catalogs
    :type asset_description: AssetDescription
    :param error_collector: The error collector
    :type error_collector: ErrorCollector
    :param progress_printer: The progress printer
    :type progress_printer: ProgressPrinter
    :return: Map with series ids and the associated assets
    :rtype: dict
    """

    series_asset_map = {}

    for count, a_series in enumerate(series):

        series_asset = get_asset_of_series(a_series, opencast_url, digest_login, asset_description)

        if isinstance(series_asset, Malformed):
            error_collector.collect_errors(series_asset, get_id(a_series))

        series_asset_map[get_id(a_series)] = series_asset

        progress_printer.print_progress(count+1, len(series))

    if len(series) != len(series_asset_map.keys()):
        raise ValueError("Less series {} than series!".format(asset_description.BOTH))

    return series_asset_map
Beispiel #9
0
def get_oaipmh_record(event, repository_url, repository, digest_login,
                      base_url):
    """
    Get the oaipmh record for a given event at base_url with the given digest login.

    :param event: The event
    :type event: dict
    :param repository_url: The URL to the OAIPMH repository
    :type repository_url: str
    :param repository: The OAIPMH repository ID
    :type repository: str
    :param digest_login: The login credentials for digest authentication
    :type digest_login: DigestLogin
    :param base_url: The URL of the opencast instance
    :type base_url: str
    :return: The OAIPMH record in XML format
    :rtype: ElementTree.Element
    """

    # absolute url
    if repository_url.startswith("http"):

        url = '{}?verb=GetRecord&metadataPrefix=matterhorn-inlined&identifier={}'.format(
            repository_url.split('?')[0], get_id(event))
    # relative url
    else:
        url = '{}{}?verb=GetRecord&metadataPrefix=matterhorn-inlined&identifier={}'.format(
            base_url,
            repository_url.split('?')[0], get_id(event))

    response = get_request(
        url, digest_login,
        ElementDescription.OAIPMH.format(repository).singular())

    record = get_xml_content(response)

    return record
Beispiel #10
0
def main():
    """
    Export video files
    """

    event_ids, series_ids = parse_args()
    digest_login = DigestLogin(user=config.digest_user,
                               password=config.digest_pw)

    if not hasattr(config, 'presentation_url') or not config.presentation_url:
        config.presentation_url = config.admin_url

    # get events from all series
    if series_ids:
        print("Getting events for series.")
        events = []
        for series_id in series_ids:
            try:
                events_of_series = get_events_of_series(
                    config.admin_url, digest_login, series_id)
                events += events_of_series
            except Exception as e:
                print("Events of series {} could not be requested: {}".format(
                    series_id, str(e)))

        if not events:
            __abort_script("No events found.")

        event_ids = [get_id(event) for event in events]

    print("Starting export process.")
    for event_id in event_ids:
        try:
            print("Exporting media package {}".format(event_id))

            # get mp from search
            search_mp = None
            if config.export_search:
                search_mp_json = get_episode_from_search(
                    config.presentation_url, digest_login, event_id)
                if search_mp_json:
                    search_mp_xml = search_mp_json["ocMediapackage"]
                    search_mp = parse_manifest_from_endpoint(
                        search_mp_xml, event_id, False, False)

            # get mp from archive
            archive_mp_xml = get_media_package(config.admin_url, digest_login,
                                               event_id)
            archive_mp = parse_manifest_from_endpoint(archive_mp_xml, event_id,
                                                      False, True)

            # set target directory
            if config.create_series_dirs and archive_mp.series_id:
                mp_dir = os.path.join(config.target_directory,
                                      archive_mp.series_id, archive_mp.id)
            else:
                mp_dir = os.path.join(config.target_directory, archive_mp.id)

            # export
            export_videos(archive_mp, search_mp, mp_dir, config.admin_url,
                          digest_login, config.export_archived,
                          config.export_publications, config.export_mimetypes,
                          config.export_flavors, config.stream_security,
                          config.original_filenames)

            if config.export_catalogs:
                export_catalogs(archive_mp, mp_dir, config.admin_url,
                                digest_login, config.export_catalogs,
                                config.stream_security,
                                config.original_filenames)

        except Exception as e:
            print(
                "Tracks of media package {} could not be exported: {}".format(
                    event_id, str(e)))

    print("Done.")
Beispiel #11
0
def check_oaipmh(oaipmh_events, event_series_map, event_dc_map, event_acl_map, digest_login, error_collector,
                 opencast_url, progress_printer):
    """
    Check OAIPMH by getting all ACLs and Dublin Core catalogs from each record and comparing them with those from the
    corresponding event. Collect any errors.

    (Currently doesn't return anything since this is the last check.)

    :param oaipmh_events: All events published to OAIPMH
    :type oaipmh_events: list
    :param event_series_map: Dictionary mapping events to their series
    :type event_series_map: dict
    :param event_dc_map: Dictionary mapping events to their Dublin Core catalogs
    :type event_dc_map: dict
    :param event_acl_map: Dictionary mapping events to their ACLs
    :type event_acl_map: dict
    :param digest_login: The login data for digest authentication
    :type digest_login: DigestLogin
    :param error_collector: The error collector
    :type error_collector: ErrorCollector
    :param opencast_url: The URL to an opencast instance
    :type opencast_url: str
    :param progress_printer: The progress printer
    :type progress_printer: ProgressPrinter
    """

    for count, event in enumerate(oaipmh_events):

        series_of_event = event_series_map[get_id(event)]
        episode_dc, series_dc = event_dc_map[get_id(event)]
        episode_acl, series_acl = event_acl_map[get_id(event)]

        oaipmh_publications = get_oaipmh_publications(event)

        for oaipmh_repo, oaipmh_url in oaipmh_publications:

            # get oaipmh record
            try:
                oaipmh_record = get_oaipmh_record(event, oaipmh_url, oaipmh_repo, digest_login, opencast_url)

                # check Dublin Core catalogs of oaipmh
                oaipmh_episode_dc, oaipmh_series_dc = get_assets_of_oaipmh(oaipmh_record, episode_dc, series_dc,
                                                                           series_of_event, AssetDescription.DC,
                                                                           oaipmh_repo)

                if isinstance(oaipmh_episode_dc, Malformed):
                    error_collector.collect_errors(oaipmh_episode_dc, get_id(event))
                if isinstance(oaipmh_series_dc, Malformed):
                    error_collector.collect_errors(oaipmh_series_dc, get_id(event))

                # check acls of oaipmh
                oaipmh_episode_acl, oaipmh_series_acl = get_assets_of_oaipmh(oaipmh_record, episode_acl, series_acl,
                                                                             series_of_event, AssetDescription.ACL,
                                                                             oaipmh_repo)

                if isinstance(oaipmh_episode_acl, Malformed):
                    error_collector.collect_errors(oaipmh_episode_acl, get_id(event))
                if isinstance(oaipmh_series_acl, Malformed):
                    error_collector.collect_errors(oaipmh_series_acl, get_id(event))

            except RequestError as e:
                oaipmh_record = Malformed(errors=[e.error])
                error_collector.collect_errors(oaipmh_record, get_id(event))

        progress_printer.print_progress(count+1, len(oaipmh_events))
Beispiel #12
0
def main():
    """
    Ingest the given events into another tenant of the same OC system
    """

    event_ids, series_ids = parse_args()
    digest_login = DigestLogin(user=config.digest_user,
                               password=config.digest_pw)

    # get events from all series
    if series_ids:
        print("Getting events for series")
        events = []
        for series_id in series_ids:
            try:
                events_of_series = get_events_of_series(
                    config.source_url, digest_login, series_id)
                events += events_of_series
            except RequestError as e:
                print("Events of series {} could not be requested: {}".format(
                    series_id, e.error))
            except Exception as e:
                print("Events of series {} could not be requested: {}".format(
                    series_id, str(e)))

        if not events:
            __abort_script("No events found.")

        # check if this is correct
        print("The following events will be imported:")
        for event in events:
            print("%36s | %s" % (event["identifier"], event["title"]))
        print()

        start_process = get_yes_no_answer("Continue?")

        if not start_process:
            __abort_script("Okay, not importing anything.")

        event_ids = [get_id(event) for event in events]

    print("Starting import process.")
    for event_id in event_ids:
        try:
            mp = get_media_package(config.source_url, digest_login, event_id)

            series_id, tracks, catalogs, attachments = parse_manifest_from_endpoint(
                mp, event_id, False)

            workflow = import_mp(series_id, tracks, catalogs, attachments,
                                 config.target_url, digest_login,
                                 config.workflow_id, config.workflow_config,
                                 False, True)

            print(
                "Imported media package {} (new id: {}) and started workflow {} with id {}."
                .format(event_id, workflow.mp_id, workflow.template,
                        workflow.id))

        except MediaPackageError as e:
            print("Event {} could not be imported: {}".format(
                event_id, str(e)))
        except RequestError as e:
            print("Event {} could not be imported: {}".format(
                event_id, e.error))
        except Exception as e:
            print("Event {} could not be imported: {}".format(
                event_id, str(e)))

    print("Done.")