Example #1
0
def create_videomd_metadata(filename,
                            filerel=None,
                            workspace=None,
                            streams=None):
    """Creates and returns list of videoMD XML sections.

    :filename: Video file path
    :filerel: Video file path relative to base path
    :workspace: Workspace path
    :streams: Metadata dict of streams. Will be created if None.
    :returns: List of VideoMD XML sections.
    """
    if streams is None:
        (streams, _) = scrape_file(filepath=filename,
                                   filerel=filerel,
                                   workspace=workspace,
                                   skip_well_check=True)
    fix_missing_metadata(streams, filename, ALLOW_UNAV, ALLOW_ZERO)

    videomd_dict = {}
    for index, stream_md in six.iteritems(streams):
        if stream_md['stream_type'] != 'video':
            continue

        file_data_elem = _get_file_data(stream_md)

        videomd_elem = videomd.create_videomd(file_data=file_data_elem)
        videomd_dict[six.text_type(index)] = videomd_elem

    if not videomd_dict:
        print('The file has no video streams. No VideoMD metadata created.')
        return None

    return videomd_dict
Example #2
0
def create_mix_metadata(filename, filerel=None, workspace=None):
    """Create MIX metadata XML element for an image file.

    :image: image file
    :returns: MIX XML element
    """
    streams = scrape_file(filename, filerel=filerel, workspace=workspace)
    stream_md = streams[0]
    check_missing_metadata(stream_md, filename)

    if stream_md['stream_type'] != 'image':
        print("This is not an image file. No MIX metadata created.")
        return None
    if len(streams) > 1:
        raise MixGenerationError(
            'File containing multiple images not supported. File: ', filename)

    mix_compression = nisomix.compression(
        compression_scheme=stream_md["compression"])
    if 'byte_order' not in stream_md:
        if stream_md['mimetype'] == 'image/tiff':
            raise MixGenerationError(
                'Byte order missing from TIFF image file ', filename)
        byte_order = None
    else:
        byte_order = stream_md["byte_order"]

    basic_do_info = nisomix.digital_object_information(
        byte_order=byte_order, child_elements=[mix_compression])

    photom_interpret = nisomix.photometric_interpretation(
        color_space=stream_md["colorspace"])
    img_characteristics = nisomix.image_characteristics(
        width=stream_md["width"],
        height=stream_md["height"],
        child_elements=[photom_interpret])
    img_info = nisomix.image_information(child_elements=[img_characteristics])

    bit_depth = nisomix.bits_per_sample(sample_values=stream_md["bps_value"],
                                        sample_unit=stream_md["bps_unit"])
    color_encoding = nisomix.color_encoding(
        samples_pixel=stream_md["samples_per_pixel"],
        child_elements=[bit_depth])
    img_assessment = nisomix.image_assessment_metadata(
        child_elements=[color_encoding])

    mix_root = nisomix.mix(
        child_elements=[basic_do_info, img_info, img_assessment])

    if mix_root is None:
        raise MixGenerationError('Image info could not be constructed.')

    return mix_root
Example #3
0
    def add_premis_md(
            self, filepath, attributes, filerel=None, properties=None):
        """
        Create metadata for PREMIS metadata. This method:
        - Scrapes a file
        - Creates PREMIS metadata with amd references for a file
        - Creates PREMIS metadata with amd references for streams in a file
        - Returns stream dict from scraper

        :filepath: Full path to file (including base_path)
        :attributes: The following keys
                     skip_wellformed_check: True skips well-formedness checking
                     charset: Character encoding of a file,
                     file_format: File format and version (tuple) of a file,
                     format_registry: Format registry name and value (tuple),
                     identifier: File identifier type and value (tuple),
                     checksum: Checksum algorithm and value (tuple),
                     date_created: Creation date of a file
        :filerel: Relative path from base_path to file
        :returns: Stream dict and info dict from file-scraper as a tuple
        """
        if not attributes["file_format"]:
            mimetype = None
            version = None
        else:
            mimetype = attributes["file_format"][0]
            version = attributes["file_format"][1]

        (streams, info) = scrape_file(
            filepath=filepath,
            skip_well_check=attributes["skip_wellformed_check"],
            mimetype=mimetype,
            version=version,
            charset=attributes["charset"],
            skip_json=True
        )

        # Add new properties of a file for other script files, e.g. structMap
        if properties:
            streams[0]['properties'] = properties

        premis_elem = create_premis_object(filepath, streams, **attributes)
        self.add_md(premis_elem, filerel, given_metadata_dict=streams)
        premis_list = create_streams(streams, premis_elem)

        if premis_list is not None:
            for index, premis_stream in six.iteritems(premis_list):
                self.add_md(
                    premis_stream, filerel, index, given_metadata_dict=streams)

        return (streams, info)
Example #4
0
def create_videomd_metadata(filename, filerel=None, workspace=None):
    """Creates and returns list of videoMD XML sections.
    :filename: Audio file path
    :returns: List of VideoMD XML sections.
    """
    streams = scrape_file(filename, filerel=filerel, workspace=workspace)
    fix_missing_metadata(streams, filename, ALLOW_UNAV, ALLOW_ZERO)

    videomd_dict = {}
    for index, stream_md in six.iteritems(streams):
        if stream_md['stream_type'] != 'video':
            continue

        file_data_elem = _get_file_data(stream_md)

        videomd_elem = videomd.create_videomd(file_data=file_data_elem)
        videomd_dict[six.text_type(index)] = videomd_elem

    if not videomd_dict:
        raise ValueError('Video stream info could not be constructed.')

    return videomd_dict
Example #5
0
def create_audiomd_metadata(filename,
                            filerel=None,
                            workspace=None,
                            streams=None):
    """Creates and returns list of audioMD XML sections.

    :filename: Audio file path
    :filrel: Audio file path relative to base path
    :workspace: Workspace path
    :streams: Metadata dict of streams. Will be created if None.
    :returns: Dict of AudioMD XML sections.
    """
    if streams is None:
        (streams, _) = scrape_file(filepath=filename,
                                   filerel=filerel,
                                   workspace=workspace,
                                   skip_well_check=True)
    fix_missing_metadata(streams, filename, ALLOW_UNAV, ALLOW_ZERO)

    audiomd_dict = {}
    for index, stream_md in six.iteritems(streams):
        if stream_md['stream_type'] != 'audio':
            continue
        stream_md = _fix_data_rate(stream_md)
        file_data_elem = _get_file_data(stream_md)
        audio_info_elem = _get_audio_info(stream_md)

        audiomd_elem = audiomd.create_audiomd(file_data=file_data_elem,
                                              audio_info=audio_info_elem)
        audiomd_dict[six.text_type(index)] = audiomd_elem

    if not audiomd_dict:
        print('The file has no audio streams. No AudioMD metadata created.')
        return None

    return audiomd_dict