mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-22 08:53:59 +01:00
Update mutagen to 1.45.1
This commit is contained in:
Executable → Regular
+27
-5
@@ -22,12 +22,23 @@ __all__ = ["OptimFROG", "Open", "delete"]
|
||||
|
||||
import struct
|
||||
|
||||
from ._compat import endswith
|
||||
from ._util import convert_error
|
||||
from ._util import convert_error, endswith
|
||||
from mutagen import StreamInfo
|
||||
from mutagen.apev2 import APEv2File, error, delete
|
||||
|
||||
|
||||
SAMPLE_TYPE_BITS = {
|
||||
0: 8,
|
||||
1: 8,
|
||||
2: 16,
|
||||
3: 16,
|
||||
4: 24,
|
||||
5: 24,
|
||||
6: 32,
|
||||
7: 32,
|
||||
}
|
||||
|
||||
|
||||
class OptimFROGHeaderError(error):
|
||||
pass
|
||||
|
||||
@@ -41,6 +52,8 @@ class OptimFROGInfo(StreamInfo):
|
||||
channels (`int`): number of audio channels
|
||||
length (`float`): file length in seconds, as a float
|
||||
sample_rate (`int`): audio sampling rate in Hz
|
||||
bits_per_sample (`int`): the audio sample size
|
||||
encoder_info (`mutagen.text`): encoder version, e.g. "5.100"
|
||||
"""
|
||||
|
||||
@convert_error(IOError, OptimFROGHeaderError)
|
||||
@@ -48,21 +61,30 @@ class OptimFROGInfo(StreamInfo):
|
||||
"""Raises OptimFROGHeaderError"""
|
||||
|
||||
header = fileobj.read(76)
|
||||
if (len(header) != 76 or not header.startswith(b"OFR ") or
|
||||
struct.unpack("<I", header[4:8])[0] not in [12, 15]):
|
||||
if len(header) != 76 or not header.startswith(b"OFR "):
|
||||
raise OptimFROGHeaderError("not an OptimFROG file")
|
||||
data_size = struct.unpack("<I", header[4:8])[0]
|
||||
if data_size != 12 and data_size < 15:
|
||||
raise OptimFROGHeaderError("not an OptimFROG file")
|
||||
(total_samples, total_samples_high, sample_type, self.channels,
|
||||
self.sample_rate) = struct.unpack("<IHBBI", header[8:20])
|
||||
total_samples += total_samples_high << 32
|
||||
self.channels += 1
|
||||
self.bits_per_sample = SAMPLE_TYPE_BITS.get(sample_type)
|
||||
if self.sample_rate:
|
||||
self.length = float(total_samples) / (self.channels *
|
||||
self.sample_rate)
|
||||
else:
|
||||
self.length = 0.0
|
||||
if data_size >= 15:
|
||||
encoder_id = struct.unpack("<H", header[20:22])[0]
|
||||
version = str((encoder_id >> 4) + 4500)
|
||||
self.encoder_info = "%s.%s" % (version[0], version[1:])
|
||||
else:
|
||||
self.encoder_info = ""
|
||||
|
||||
def pprint(self):
|
||||
return "OptimFROG, %.2f seconds, %d Hz" % (self.length,
|
||||
return u"OptimFROG, %.2f seconds, %d Hz" % (self.length,
|
||||
self.sample_rate)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user