It seems not. :(
[pyTivo/wmcbrine/lucasnz.git] / mutagen / optimfrog.py
blob3709c1955405e90def89cc011ca2031680930a3e
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 3923 2006-10-21 15:07:13Z luks $
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/
21 """
23 __all__ = ["OptimFROG", "Open", "delete"]
25 import struct
26 from mutagen.apev2 import APEv2File, error, delete
28 class OptimFROGHeaderError(error): pass
30 class OptimFROGInfo(object):
31 """OptimFROG stream information.
33 Attributes:
34 channels - number of audio channels
35 length - file length in seconds, as a float
36 sample_rate - audio sampling rate in Hz
37 """
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
47 self.channels += 1
48 if self.sample_rate:
49 self.length = float(total_samples) / (self.channels *
50 self.sample_rate)
51 else:
52 self.length = 0.0
54 def pprint(self):
55 return "OptimFROG, %.2f seconds, %d Hz" % (self.length,
56 self.sample_rate)
58 class OptimFROG(APEv2File):
59 _Info = OptimFROGInfo
61 def score(filename, fileobj, header):
62 return (header.startswith("OFR") + filename.endswith(".ofr") +
63 filename.endswith(".ofs"))
64 score = staticmethod(score)