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 import os
40 import string
41 import datetime
42 from mutagen.oggvorbis import OggVorbis
43 from tools import *
44
45
47 """An OGG file object"""
48
50 self.media = media
51 self.ogg = OggVorbis(self.media)
52 self.item_id = ''
53 self.source = self.media
54 self.options = {}
55 self.bitrate_default = '192'
56 self.cache_dir = os.sep + 'tmp'
57 self.keys2ogg = {'title': 'title',
58 'artist': 'artist',
59 'album': 'album',
60 'date': 'date',
61 'comment': 'comment',
62 'genre': 'genre',
63 'copyright': 'copyright',
64 }
65 self.info = self.ogg.info
66 self.bitrate = int(str(self.info.bitrate)[:-3])
67 self.length = datetime.timedelta(0,self.info.length)
68 self.metadata = self.get_file_metadata()
69 self.description = self.get_description()
70 self.mime_type = self.get_mime_type()
71 self.media_info = get_file_info(self.media)
72 self.file_name = self.media_info[0]
73 self.file_title = self.media_info[1]
74 self.file_ext = self.media_info[2]
75 self.extension = self.get_file_extension()
76 self.size = os.path.getsize(media)
77
78
81
84
86 return 'application/ogg'
87
90
92 try:
93 file_out1, file_out2 = os.popen4('ogginfo "'+self.dest+'"')
94 info = []
95 for line in file_out2.readlines():
96 info.append(clean_word(line[:-1]))
97 self.info = info
98 return self.info
99 except:
100 raise IOError('ExporterError: file does not exist.')
101
103 self.cache_dir = path
104
113
115 try:
116 os.system('oggdec -o "'+self.cache_dir+os.sep+self.item_id+
117 '.wav" "'+self.source+'"')
118 return self.cache_dir+os.sep+self.item_id+'.wav'
119 except:
120 raise IOError('ExporterError: decoder is not compatible.')
121
127
129 """Get process options and return arguments for the encoder"""
130 args = []
131 if not options is None:
132 self.options = options
133 if not ('verbose' in self.options and self.options['verbose'] != '0'):
134 args.append('-Q ')
135 if 'ogg_bitrate' in self.options:
136 args.append('-b '+self.options['ogg_bitrate'])
137 elif 'ogg_quality' in self.options:
138 args.append('-q '+self.options['ogg_quality'])
139 else:
140 args.append('-b '+self.bitrate_default)
141 else:
142 args.append('-Q -b '+self.bitrate_default)
143
144 for tag in self.metadata.keys():
145 value = clean_word(self.metadata[tag])
146 args.append('-c %s="%s"' % (tag, value))
147 if tag in self.dub2args_dict.keys():
148 arg = self.dub2args_dict[tag]
149 args.append('-c %s="%s"' % (arg, value))
150
151 return args
152