Package deefuzzer :: Package tools :: Module ogg
[hide private]
[frames] | no frames]

Source Code for Module deefuzzer.tools.ogg

  1  #!/usr/bin/python 
  2  # -*- coding: utf-8 -*- 
  3  # 
  4  # Copyright Guillaume Pellerin (2006-2009) 
  5   
  6  # <yomguy@parisson.com> 
  7   
  8  # This software is a computer program whose purpose is to stream audio 
  9  # and video data through icecast2 servers. 
 10   
 11  # This software is governed by the CeCILL  license under French law and 
 12  # abiding by the rules of distribution of free software.  You can  use, 
 13  # modify and/ or redistribute the software under the terms of the CeCILL 
 14  # license as circulated by CEA, CNRS and INRIA at the following URL 
 15  # "http://www.cecill.info". 
 16   
 17  # As a counterpart to the access to the source code and  rights to copy, 
 18  # modify and redistribute granted by the license, users are provided only 
 19  # with a limited warranty  and the software's author,  the holder of the 
 20  # economic rights,  and the successive licensors  have only  limited 
 21  # liability. 
 22   
 23  # In this respect, the user's attention is drawn to the risks associated 
 24  # with loading,  using,  modifying and/or developing or reproducing the 
 25  # software by the user in light of its specific status of free software, 
 26  # that may mean  that it is complicated to manipulate,  and  that  also 
 27  # therefore means  that it is reserved for developers  and  experienced 
 28  # professionals having in-depth computer knowledge. Users are therefore 
 29  # encouraged to load and test the software's suitability as regards their 
 30  # requirements in conditions enabling the security of their systems and/or 
 31  # data to be ensured and,  more generally, to use and operate it in the 
 32  # same conditions as regards security. 
 33   
 34  # The fact that you are presently reading this means that you have had 
 35  # knowledge of the CeCILL license and that you accept its terms. 
 36   
 37  # Author: Guillaume Pellerin <yomguy@parisson.com> 
 38   
 39  import os 
 40  import string 
 41  import datetime 
 42  from mutagen.oggvorbis import OggVorbis 
 43  from utils import * 
 44   
 45   
46 -class Ogg(MediaBase):
47 """An OGG file object""" 48
49 - def __init__(self, media):
50 MediaBase.__init__(self) 51 52 self.description = "OGG Vorbis" 53 self.mime_type = 'audio/ogg' 54 self.extension = 'ogg' 55 self.format = 'OGG' 56 57 self.media = media 58 self.sourceobj = OggVorbis(self.media) 59 self.source = self.media 60 self.bitrate_default = '192' 61 62 self.tagdata = { 63 'title': '', 64 'artist': '', 65 'album': '', 66 'date': '', 67 'comment': '', 68 'genre': '', 69 'copyright': '' 70 } 71 72 self.info = self.sourceobj.info 73 self.bitrate = int(str(self.info.bitrate)[:-3]) 74 self.length = datetime.timedelta(0, self.info.length) 75 self.read_file_metadata() 76 self.media_info = get_file_info(self.media) 77 self.file_name = self.media_info[0] 78 self.file_title = self.media_info[1] 79 self.file_ext = self.media_info[2] 80 self.size = os.path.getsize(self.media)
81
82 - def get_file_info(self):
83 try: 84 file_out1, file_out2 = os.popen4('ogginfo "' + self.source + '"') 85 info = [] 86 for line in file_out2.readlines(): 87 info.append(clean_word(line[:-1])) 88 self.info = info 89 return self.info 90 except: 91 raise IOError('ExporterError: file does not exist.')
92
93 - def decode(self):
94 if not self.item_id: 95 raise IOError('ExporterError: Required item_id parameter not set.') 96 try: 97 p = os.path.join(self.cache_dir, (self.item_id + '.wav')) 98 os.system('oggdec -o "' + p + '" "' + self.source + '"') 99 return p 100 except: 101 raise IOError('ExporterError: decoder is not compatible.')
102
103 - def write_tags(self):
104 # self.ogg.add_tags() 105 for tag in self.metadata.keys(): 106 self.sourceobj[tag] = str(self.metadata[tag]) 107 self.sourceobj.save()
108
109 - def get_args(self, options=None):
110 """Get process options and return arguments for the encoder""" 111 args = [] 112 if options is not None: 113 self.options = options 114 if not ('verbose' in self.options and self.options['verbose'] != '0'): 115 args.append('-Q ') 116 if 'ogg_bitrate' in self.options: 117 args.append('-b ' + self.options['ogg_bitrate']) 118 elif 'ogg_quality' in self.options: 119 args.append('-q ' + self.options['ogg_quality']) 120 else: 121 args.append('-b ' + self.bitrate_default) 122 else: 123 args.append('-Q -b ' + self.bitrate_default) 124 125 for tag in self.metadata.keys(): 126 value = clean_word(self.metadata[tag]) 127 args.append('-c %s="%s"' % (tag, value)) 128 if tag in self.tagdata: 129 arg = self.tagdata[tag] 130 if arg: 131 args.append('-c %s="%s"' % (arg, value)) 132 133 return args
134