1 # OptimFROG reader/tagger
3 # Copyright 2006 Lukas Lalinsky <lalinsky@gmail.com>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License version 2 as
7 # published by the Free Software Foundation.
9 # $Id: optimfrog.py 4275 2008-06-01 06:32:37Z piman $
11 """OptimFROG audio streams with APEv2 tags.
13 OptimFROG is a lossless audio compression program. Its main goal is to
14 reduce at maximum the size of audio files, while permitting bit
15 identical restoration for all input. It is similar with the ZIP
16 compression, but it is highly specialized to compress audio data.
18 Only versions 4.5 and higher are supported.
20 For more information, see http://www.losslessaudio.org/
23 __all__ = ["OptimFROG", "Open", "delete"]
26 from mutagen.apev2 import APEv2File, error, delete
28 class OptimFROGHeaderError(error): pass
30 class OptimFROGInfo(object):
31 """OptimFROG stream information.
34 channels - number of audio channels
35 length - file length in seconds, as a float
36 sample_rate - audio sampling rate in Hz
39 def __init__(self, fileobj):
40 header = fileobj.read(76)
41 if (len(header) != 76 or not header.startswith("OFR ") or
42 struct.unpack("<I", header[4:8])[0] not in [12, 15]):
43 raise OptimFROGHeaderError("not an OptimFROG file")
44 (total_samples, total_samples_high, sample_type, self.channels,
45 self.sample_rate) = struct.unpack("<IHBBI", header[8:20])
46 total_samples += total_samples_high << 32
49 self.length = float(total_samples) / (self.channels *
55 return "OptimFROG, %.2f seconds, %d Hz" % (self.length,
58 class OptimFROG(APEv2File):
61 def score(filename, fileobj, header):
62 return (header.startswith("OFR") + filename.endswith(".ofr") +
63 filename.endswith(".ofs"))
64 score = staticmethod(score)