How to use the tinytag.tinytag.Ogg function in tinytag

To help you get started, we’ve selected a few tinytag examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github devsnd / tinytag / tinytag / tinytag.py View on Github external
# max_frm = _bytes_to_int(struct.unpack('3B', max_frm))
                #                 channels--.  bits      total samples
                # |----- samplerate -----| |-||----| |---------~   ~----|
                # 0000 0000 0000 0000 0000 0000 0000 0000 0000      0000
                # #---4---# #---5---# #---6---# #---7---# #--8-~   ~-12-#
                self.samplerate = _bytes_to_int(header[4:7]) >> 4
                self.channels = ((header[6] >> 1) & 0x07) + 1
                # bit_depth = ((header[6] & 1) << 4) + ((header[7] & 0xF0) >> 4)
                # bit_depth = (bit_depth + 1)
                total_sample_bytes = [(header[7] & 0x0F)] + list(header[8:12])
                total_samples = _bytes_to_int(total_sample_bytes)
                self.duration = float(total_samples) / self.samplerate
                if self.duration > 0:
                    self.bitrate = self.filesize / self.duration * 8 / 1024
            elif block_type == Flac.METADATA_VORBIS_COMMENT and not skip_tags:
                oggtag = Ogg(fh, 0)
                oggtag._parse_vorbis_comment(fh)
                self.update(oggtag)
            elif block_type >= 127:
                return  # invalid block type
            else:
                fh.seek(size, 1)  # seek over this block

            if is_last_block:
                return
            header_data = fh.read(4)
github devsnd / tinytag / tinytag / tinytag.py View on Github external
def _get_parser_for_filename(cls, filename, exception=False):
        mapping = {
            ('.mp3',): ID3,
            ('.oga', '.ogg', '.opus'): Ogg,
            ('.wav',): Wave,
            ('.flac',): Flac,
            ('.wma',): Wma,
            ('.m4b', '.m4a', '.mp4'): MP4,
        }
        for fileextension, tagclass in mapping.items():
            if filename.lower().endswith(fileextension):
                return tagclass
        if exception:
            raise TinyTagException('No tag reader found to support filetype! ')
github devsnd / cherrymusic / tinytag / tinytag.py View on Github external
def get(cls, filename, tags=True, duration=True):
        parser_class = None
        size = os.path.getsize(filename)
        if not size > 0:
            return TinyTag(None, 0)
        if cls == TinyTag:
            """choose which tag reader should be used by file extension"""
            mapping = {
                ('.mp3',): ID3,
                ('.oga', '.ogg', '.opus'): Ogg,
                ('.wav'): Wave,
                ('.flac'): Flac,
            }
            for fileextension, tagclass in mapping.items():
                if filename.lower().endswith(fileextension):
                    parser_class = tagclass
        else:
            # use class on which the method was invoked as parser
            parser_class = cls
        if parser_class is None:
            raise LookupError('No tag reader found to support filetype! ')
        with open(filename, 'rb') as af:
            tag = parser_class(af, size)
            tag.load(tags=tags, duration=duration)
            return tag
github devsnd / cherrymusic / tinytag / tinytag.py View on Github external
def _parse_tag(self, fh):
        # for spec, see https://xiph.org/flac/ogg_mapping.html
        header_data = fh.read(4)
        while len(header_data):
            meta_header = struct.unpack('B3B', header_data)
            size = self._bytes_to_int(meta_header[1:4])
            if meta_header[0] == 4:
                oggtag = Ogg(fh, 0)
                oggtag._parse_vorbis_comment(fh)
                self.update(oggtag)
                return
            else:
                fh.seek(size, 1)
                header_data = fh.read(4)