Пример #1
0
def _fingerprint_buffer(buf):
    """
    Generate a fingerprint from a media file loaded in memory as a byte
    buffer.

    :param bytes buf: A byte buffer holding a media file.
    :raise: :class:`AEError` if the buffer holds invalid data.
    :rtype: Fingerprint
    """

    lk = _AE_Lock.new(_lib)

    c_status = _AE_Status.new(_lib)
    c_buf = _AE_Buffer.new(_lib)
    c_ft = _AE_Buffer.new(_lib)

    _lib.AE_Buffer_Set(c_buf.get(), buf, len(buf))

    _lib.AE_Fingerprint_Buffer(c_buf.get(), c_ft.get(), c_status.get())
    AEError.check_status(c_status)

    data = _lib.AE_Buffer_GetData(c_ft.get())
    size = _lib.AE_Buffer_GetSize(c_ft.get())
    ft = ctypes.string_at(data, size)
    return Fingerprint(ft)
Пример #2
0
def _start_metadata_search(client, req):
    """
    Starts a metadata search. This operation does not block until the
    search is finished, it does however perform a network operation to
    initiate the search on the backend service.

    :param MetadataSearchRequest req: search parameters.
    :raise: :class:`AEError` if the search couldn’t be initiated, e.g.
            because of network issues.
    :rtype: MetadataSearchFuture
    """

    lock = _AE_Lock.new(_lib)

    c_status = _AE_Status.new(_lib)
    c_ft = _AE_Buffer.new(_lib)
    c_req = _AE_MetadataSearchRequest.new(_lib)
    c_lookup_id = ctypes.c_uint64(0)

    _lib.AE_Buffer_Set(c_ft.get(), req.fingerprint._ft,
                       len(req.fingerprint._ft))

    _lib.AE_MetadataSearchRequest_SetFingerprint(c_req.get(), c_ft.get(),
                                                 c_status.get())
    AEError.check_status(c_status)

    _lib.AE_MetadataSearch_Start(client._c_client.get(), c_req.get(),
                                 ctypes.byref(c_lookup_id), c_status.get())
    AEError.check_status(c_status)
    return MetadataSearchFuture(client, c_lookup_id.value)
Пример #3
0
def _fingerprint_file(path):
    """
    Generate a fingerprint from a file stored on a disk. The parameter to
    the function must be a path to a valid file in supported format.

    :param str path: path to the media file we're trying to fingerprint.
    :raise: :class:`AEError` if the media file is missing or invalid.
    :rtype: Fingerprint
    """
    lk = _AE_Lock.new(_lib)

    c_ft = _AE_Buffer.new(_lib)
    c_status = _AE_Status.new(_lib)

    _lib.AE_Fingerprint_File(path.encode(), c_ft.get(), c_status.get())
    AEError.check_status(c_status)

    data = _lib.AE_Buffer_GetData(c_ft.get())
    size = _lib.AE_Buffer_GetSize(c_ft.get())
    ft = ctypes.string_at(data, size)
    return Fingerprint(ft)
Пример #4
0
    def get(self):
        """
        Blocks until the search result is ready and then returns it.

        :raise: :class:`AEError` if the search couldn't be performed, e.g.
                because of network issues.
        :rtype: LicenseSearchResult
        """

        lock = _AE_Lock.new(_lib)

        c_status = _AE_Status.new(_lib)
        c_res = _AE_LicenseSearchResult.new(_lib)

        _lib.AE_LicenseSearch_Check(self._raw_c_client, self._lookup_id,
                                    c_res.get(), c_status.get())
        AEError.check_status(c_status)

        c_match = _AE_LicenseSearchMatch.new(_lib)
        c_matches_pos = ctypes.c_int(0)

        c_asset = _AE_Asset.new(_lib)

        matches = []
        while _lib.AE_LicenseSearchResult_NextMatch(
                c_res.get(), c_match.get(), ctypes.byref(c_matches_pos)):
            _lib.AE_LicenseSearchMatch_GetAsset(c_match.get(), c_asset.get())

            matches.append(LicenseSearchMatch(
                asset=_extract_asset(c_asset),
                segments=_extract_license_search_segments(c_match),
                policies=_extract_license_search_policies(c_match)))

        return LicenseSearchResult(
            lookup_id=_lib.AE_LicenseSearchResult_GetLookupID(c_res.get()),
            ugc_id=_lib.AE_LicenseSearchResult_GetUGCID(c_res.get()),
            matches=matches)