Exemple #1
0
    def encode(cls, fp):
        """Compress and base64-encode a raw fingerprint"""
        # TODO: error handling
        efp_obj_ptr = ffi.new('char **')
        fp_obj = ffi.new('int32_t[]', fp)
        assert lib.groove_fingerprinter_encode(fp_obj, len(fp), efp_obj_ptr) == 0

        # copy the result to python and free the c obj
        result = ffi.string(efp_obj_ptr[0])
        lib.groove_fingerprinter_dealloc(efp_obj_ptr[0])

        return result
Exemple #2
0
    def get_tags(self, flags=0):
        """Get the tags for an encoder

        Args:
            flags (int)  Bitmask of tag flags

        Returns:
            A dictionary of `name: value` pairs. Both `name` and `value` will
            be type `bytes`.
        """
        # Have to make a GrooveTag** so cffi doesn't try to sizeof GrooveTag
        gtag_ptr = ffi.new('struct GrooveTag **')
        gtag = gtag_ptr[0]
        tags = OrderedDict()
        while True:
            gtag = lib.groove_encoder_metadata_get(self._obj, b'', gtag, flags)
            if gtag == ffi.NULL:
                break

            key = ffi.string(lib.groove_tag_key(gtag))
            value = ffi.string(lib.groove_tag_value(gtag))
            tags[key] = value

        return tags
Exemple #3
0
    def get_tags(self, flags=0):
        """Get the tags for an encoder

        Args:
            flags (int)  Bitmask of tag flags

        Returns:
            A dictionary of `name: value` pairs. Both `name` and `value` will
            be type `bytes`.
        """
        # Have to make a GrooveTag** so cffi doesn't try to sizeof GrooveTag
        gtag_ptr = ffi.new('struct GrooveTag **')
        gtag = gtag_ptr[0]
        tags = OrderedDict()
        while True:
            gtag = lib.groove_encoder_metadata_get(self._obj, b'', gtag, flags)
            if gtag == ffi.NULL:
                break

            key = ffi.string(lib.groove_tag_key(gtag))
            value = ffi.string(lib.groove_tag_value(gtag))
            tags[key] = value

        return tags
Exemple #4
0
    def list_devices(cls):
        """Get the list of available devices

        This may trigger a complete redetect of available hardware
        """
        devices = [
            Player.dummy_device,
            Player.default_device,
        ]

        device_count = lib.groove_device_count()
        for n in range(device_count):
            name = lib.groove_device_name(n)
            if name == ffi.NULL:
                continue
            name = ffi.string(name).decode('utf-8')
            devices.append(Device(n, name))

        return devices
Exemple #5
0
    def __iter__(self):
        info_obj = ffi.new('struct GrooveFingerprinterInfo *');
        while True:
            status = lib.groove_fingerprinter_info_get(self._obj, info_obj, True)
            assert status >= 0
            if status != 1 or info_obj.item == ffi.NULL:
                break

            fp_obj = info_obj.fingerprint
            fp_size_obj = info_obj.fingerprint_size

            if self.base64_encode:
                efp_obj_ptr = ffi.new('char **')
                assert lib.groove_fingerprinter_encode(fp_obj, fp_size_obj, efp_obj_ptr) == 0
                fp = ffi.string(efp_obj_ptr[0])
                lib.groove_fingerprinter_dealloc(efp_obj_ptr[0])
            else:
                fp = [int(fp_obj[n]) for n in range(fp_size_obj)]

            duration = float(info_obj.duration)
            pitem = self.playlist._pitem(info_obj.item)
            lib.groove_fingerprinter_free_info(info_obj)
            yield FingerprinterInfo(fp, duration, pitem)
Exemple #6
0
 def _from_obj(cls, obj):
     instance, created = super(File, cls)._from_obj(obj)
     if created:
         instance._filename = ffi.string(instance._obj.filename).decode()
     return instance, created
Exemple #7
0
 def short_names(self):
     """A list of short names for the format"""
     names = ffi.string(lib.groove_file_short_names(self._obj)).decode()
     return names.split(',')
Exemple #8
0
def libgroove_version():
    """libgroove version as a string"""
    return ffi.string(lib.groove_version()).decode('utf-8')
Exemple #9
0
 def getter(self):
     value = getattr(self._obj, attr)
     if value == ffi.NULL:
         return None
     return ffi.string(value).decode(encoding)
Exemple #10
0
 def _from_obj(cls, obj):
     instance, created = super(File, cls)._from_obj(obj)
     if created:
         instance._filename = ffi.string(instance._obj.filename).decode()
     return instance, created
Exemple #11
0
 def short_names(self):
     """A list of short names for the format"""
     names = ffi.string(lib.groove_file_short_names(self._obj)).decode()
     return names.split(',')
Exemple #12
0
def libgroove_version():
    """libgroove version as a string"""
    return ffi.string(lib.groove_version()).decode('utf-8')