summaryrefslogtreecommitdiff
blob: b22687d2fb0569df64b5f57f1fb7d4adf4bd0add (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
--- edna.py.orig	2007-01-31 19:25:14.000000000 +0000
+++ edna.py	2007-01-31 20:55:09.000000000 +0000
@@ -64,6 +64,12 @@
   oggSupport = 'no'
 
 try:
+  from mutagen.flac import FLAC
+  flacSupport = True
+except ImportError:
+  flacSupport = False
+
+try:
   import cStringIO
   StringIO = cStringIO
 except ImportError:
@@ -920,6 +926,9 @@
     if ext == '.ogg':
       info = OggInfo(fullpath)
       self.__dict__.update(info.__dict__)
+    elif ext == '.flac':
+      info = FlacInfo(fullpath)
+      self.__dict__.update(info.__dict__)
     else:
       info = MP3Info.MP3Info(open(fullpath, 'rb'))
       self.__dict__.update(info.__dict__)
@@ -1001,6 +1010,45 @@
             self.transcoded = val
     self.valid = 1
 
+class FlacInfo:
+	def __init__(self, name):
+		# Setup the defaults
+		self.valid = 0
+		self.total_time = 0
+		self.samplerate = 'unknown'
+		self.bitrate = 'unknown'
+		self.mode = ''
+		self.mode_extension = ''
+		
+		if not flacSupport: return
+		
+		mflac = FLAC(name)
+		streaminfo = mflac.metadata_blocks[0]
+		
+		self.samplerate = streaminfo.sample_rate
+		self.total_time = streaminfo.length
+		self.bitrate =int(round((streaminfo.bits_per_sample * streaminfo.total_samples) / streaminfo.length))
+		self.filesize = os.path.getsize(name) / (1024 ** 2)
+		
+		for key, val in mflac.tags:
+			if key == 'TITLE':
+				self.title = val
+			elif key == 'ARTIST':
+				self.artist = val
+			elif key == 'ALBUM':
+				self.album = val
+			elif key == 'DATE':
+				self.year = val
+			elif key == 'GENRE':
+				self.genre = val
+			elif key == 'VENDOR':
+				self.vendor = val
+			elif key == 'TRACKNUMBER':
+				self.track = val
+			elif key == 'DESCRIPTION':
+				self.comment = val
+		
+		self.valid = 1
 
 def _usable_file(fname):
   return fname[0] != '.'
@@ -1044,6 +1092,7 @@
   '.avi' : 'video/x-msvideo',
   '.mpg' : 'video/mpeg',
   '.ogg' : 'application/x-ogg',
+  '.flac' : 'audio/x-flac',
   '.m4a' : 'audio/mp4',
   '.mp4' : 'video/mp4',  
   }