Debian Codegraph @

xl/metadata/wav.py

raw
1 # Copyright (C) 2008-2010 Adam Olsen
2 # Copyright (C) 2025 Johannes Sasongko <johannes sasongko org>
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 #
18 #
19 # The developers of the Exaile media player hereby grant permission
20 # for non-GPL compatible GStreamer and Exaile plugins to be used and
21 # distributed together with GStreamer and Exaile. This permission is
22 # above and beyond the permissions granted by the GPL license by which
23 # Exaile is covered. If you modify this code, you may extend this
24 # exception to your version of the code, but you are not obligated to
25 # do so. If you do not wish to do so, delete this exception statement
26 # from your version.
27
28
29 import wave, logging
30
31 logger = logging.getLogger(__name__)
32
33 from xl.metadata._base import BaseFormat, NotReadable
34
35
36 class WavFormat(BaseFormat):
37 writable = False
38
39 def load(self):
40 try:
41 fp = open(self.loc, 'rb')
42 except IOError:
43 raise NotReadable
44
45 try:
46 with wave.open(fp) as f:
47 nchannels, sampwidth, framerate, nframes = f.getparams()[:4]
48 except Exception as e:
49 logger.info("Error reading: %s. Error: %s.", self.loc, e)
50 else:
51 bitrate = framerate * nchannels * sampwidth * 8
52 length = nframes / framerate
53 self.mutagen = {'__bitrate': bitrate, '__length': length}