def add_replay_gain(cls, filenames, progress=None): """Adds ReplayGain values to a list of filename strings. All the filenames must be of this AudioFile type. Raises ValueError if some problem occurs during ReplayGain application. """ track_names = [track.filename for track in open_files(filenames) if isinstance(track, cls)] if (progress is not None): progress(0, 1) if ((len(track_names) > 0) and BIN.can_execute(BIN['vorbisgain'])): devnull = file(os.devnull, 'ab') sub = subprocess.Popen([BIN['vorbisgain'], '-q', '-a'] + track_names, stdout=devnull, stderr=devnull) sub.wait() devnull.close() if (progress is not None): progress(1, 1)
def add_replay_gain(cls, filenames, progress=None): """adds ReplayGain values to a list of filename strings all the filenames must be of this AudioFile type raises ValueError if some problem occurs during ReplayGain application """ import subprocess import os from . import open_files track_names = [track.filename for track in open_files(filenames) if isinstance(track, cls)] if (progress is not None): progress(0, 1) #helpfully, aacgain is flag-for-flag compatible with mp3gain if ((len(track_names) > 0) and (BIN.can_execute(BIN['aacgain']))): devnull = file(os.devnull, 'ab') sub = subprocess.Popen([BIN['aacgain'], '-k', '-q', '-r'] + track_names, stdout=devnull, stderr=devnull, creationflags=0x08000000) sub.wait() devnull.close() if (progress is not None): progress(1, 1)
def to_pcm(self): #if mpg123 is available, use that for decoding if (BIN.can_execute(BIN["mpg123"])): sub = subprocess.Popen([BIN["mpg123"],"-qs",self.filename], stdout=subprocess.PIPE, stderr=file(os.devnull,"a")) return PCMReader(sub.stdout, sample_rate=self.sample_rate(), channels=self.channels(), bits_per_sample=16, channel_mask=int(ChannelMask.from_channels(self.channels())), process=sub, big_endian=BIG_ENDIAN) else: #if not, use LAME for decoding if (self.filename.endswith("." + self.SUFFIX)): if (BIG_ENDIAN): endian = ['-x'] else: endian = [] sub = subprocess.Popen([BIN['lame']] + endian + \ ["--decode","-t","--quiet", self.filename,"-"], stdout=subprocess.PIPE) return PCMReader(sub.stdout, sample_rate=self.sample_rate(), channels=self.channels(), bits_per_sample=16, channel_mask=int(ChannelMask.from_channels(self.channels())), process=sub) else: import tempfile from audiotools import TempWaveReader #copy our file to one that ends with .mp3 tempmp3 = tempfile.NamedTemporaryFile(suffix='.' + self.SUFFIX) f = open(self.filename,'rb') transfer_data(f.read,tempmp3.write) f.close() tempmp3.flush() #decode the mp3 file to a WAVE file wave = tempfile.NamedTemporaryFile(suffix='.wav') returnval = subprocess.call([BIN['lame'],"--decode","--quiet", tempmp3.name,wave.name]) tempmp3.close() if (returnval == 0): #return WAVE file as a stream wave.seek(0,0) return TempWaveReader(wave) else: return PCMReaderError(None, sample_rate=self.sample_rate(), channels=self.channels(), bits_per_sample=16)
def open_db(filename): """Given a filename string, returns UndoDB or OldUndoDB. If the file doesn't exist, this uses UndoDB by default. Otherwise, detect OldUndoDB if xdelta is installed.""" if (BIN.can_execute(BIN["xdelta"])): db = whichdb.whichdb(filename) if ((db is not None) and (db != '')): return OldUndoDB(filename) else: return UndoDB(filename) else: return UndoDB(filename)
def add_replay_gain(cls, filenames): track_names = [track.filename for track in open_files(filenames) if isinstance(track,cls)] if ((len(track_names) > 0) and (BIN.can_execute(BIN['mp3gain']))): devnull = file(os.devnull,'ab') sub = subprocess.Popen([BIN['mp3gain'],'-f','-k','-q','-r'] + \ track_names, stdout=devnull, stderr=devnull) sub.wait() devnull.close()
def open_db(filename): """given a filename string, returns UndoDB or OldUndoDB if the file doesn't exist, this uses UndoDB by default otherwise, detect OldUndoDB if xdelta is installed""" if (BIN.can_execute(BIN["xdelta"])): db = whichdb.whichdb(filename) if ((db is not None) and (db != '')): return OldUndoDB(filename) else: return UndoDB(filename) else: return UndoDB(filename)
def add_replay_gain(cls, filenames): """Adds ReplayGain values to a list of filename strings. All the filenames must be of this AudioFile type. Raises ValueError if some problem occurs during ReplayGain application. """ track_names = [track.filename for track in open_files(filenames) if isinstance(track, cls)] if ((len(track_names) > 0) and (BIN.can_execute(BIN['mp3gain']))): devnull = file(os.devnull, 'ab') sub = subprocess.Popen([BIN['mp3gain'], '-f', '-k', '-q', '-r'] + \ track_names, stdout=devnull, stderr=devnull) sub.wait() devnull.close()
def add_replay_gain(cls, filenames, progress=None): """adds ReplayGain values to a list of filename strings all the filenames must be of this AudioFile type raises ValueError if some problem occurs during ReplayGain application """ track_names = [track.filename for track in open_files(filenames) if isinstance(track, cls)] if progress is not None: progress(0, 1) if (len(track_names) > 0) and BIN.can_execute(BIN["vorbisgain"]): devnull = file(os.devnull, "ab") sub = subprocess.Popen([BIN["vorbisgain"], "-q", "-a"] + track_names, stdout=devnull, stderr=devnull) sub.wait() devnull.close() if progress is not None: progress(1, 1)
def add_replay_gain(cls, filenames, progress=None): """Adds ReplayGain values to a list of filename strings. All the filenames must be of this AudioFile type. Raises ValueError if some problem occurs during ReplayGain application. """ track_names = [track.filename for track in open_files(filenames) if isinstance(track, cls)] if progress is not None: progress(0, 1) # helpfully, aacgain is flag-for-flag compatible with mp3gain if (len(track_names) > 0) and (BIN.can_execute(BIN["aacgain"])): devnull = file(os.devnull, "ab") sub = subprocess.Popen([BIN["aacgain"], "-k", "-q", "-r"] + track_names, stdout=devnull, stderr=devnull) sub.wait() devnull.close() if progress is not None: progress(1, 1)
def supports_to_pcm(cls): """returns True if all necessary components are available to support the .to_pcm() method""" return BIN.can_execute(BIN["neroAacDec"])
try: sub = subprocess.Popen( [BIN["neroAacEnc"], "-q", compression, "-if", wave_filename, "-of", filename], stdout=devnull, stderr=devnull, ) if sub.wait() != 0: raise EncodingError(u"neroAacEnc unable to write file") else: return cls(filename) finally: devnull.close() if BIN.can_execute(BIN["neroAacEnc"]) and BIN.can_execute(BIN["neroAacDec"]): M4AAudio = M4AAudio_nero else: M4AAudio = M4AAudio_faac class M4ACovr(Image): """A subclass of Image to store M4A 'covr' atoms.""" def __init__(self, image_data): self.image_data = image_data img = Image.new(image_data, u"", 0) Image.__init__( self,
[ BIN["neroAacEnc"], "-q", compression, "-if", wave_filename, "-of", filename ], stdout=subprocess.DEVNULL if hasattr(subprocess, "DEVNULL") else open(os.devnull, "wb"), stderr=subprocess.DEVNULL if hasattr(subprocess, "DEVNULL") else open(os.devnull, "wb")) if sub.wait() != 0: raise EncodingError(u"neroAacEnc unable to write file") else: return cls(filename) if BIN.can_execute(BIN["neroAacEnc"]) and BIN.can_execute(BIN["neroAacDec"]): M4AAudio = M4AAudio_nero else: M4AAudio = M4AAudio_faac class InvalidALAC(InvalidFile): pass class ALACAudio(M4ATaggedAudio, AudioFile): """an Apple Lossless audio file""" SUFFIX = "m4a" NAME = "alac" DESCRIPTION = u"Apple Lossless"
def supports_from_pcm(cls): """returns True if all necessary components are available to support the .from_pcm() classmethod""" return BIN.can_execute(BIN["neroAacEnc"])
def supports_to_pcm(cls): """returns True if all necessary components are available to support the .to_pcm() method""" return BIN.can_execute(BIN["speexdec"])
def supports_from_pcm(cls): """returns True if all necessary components are available to support the .from_pcm() classmethod""" return BIN.can_execute(BIN["speexenc"])
def can_add_replay_gain(cls): """returns True if we have the necessary binaries to add ReplayGain""" return BIN.can_execute(BIN["vorbisgain"])
def can_add_replay_gain(cls): """Returns True if we have the necessary binaries to add ReplayGain.""" return BIN.can_execute(BIN['vorbisgain'])
def can_add_replay_gain(cls): return BIN.can_execute(BIN['mp3gain'])
def to_pcm(self): """Returns a PCMReader object containing the track's PCM data.""" #if mpg123 is available, use that for decoding if (BIN.can_execute(BIN["mpg123"])): sub = subprocess.Popen([BIN["mpg123"], "-qs", self.filename], stdout=subprocess.PIPE, stderr=file(os.devnull, "a")) return PCMReader(sub.stdout, sample_rate=self.sample_rate(), channels=self.channels(), bits_per_sample=16, channel_mask=int(ChannelMask.from_channels( self.channels())), process=sub, big_endian=BIG_ENDIAN) else: #if not, use LAME for decoding if (self.filename.endswith("." + self.SUFFIX)): if (BIG_ENDIAN): endian = ['-x'] else: endian = [] sub = subprocess.Popen([BIN['lame']] + endian + \ ["--decode", "-t", "--quiet", self.filename, "-"], stdout=subprocess.PIPE) return PCMReader( sub.stdout, sample_rate=self.sample_rate(), channels=self.channels(), bits_per_sample=16, channel_mask=int(self.channel_mask()), process=sub) else: import tempfile from audiotools import TempWaveReader #copy our file to one that ends with .mp3 tempmp3 = tempfile.NamedTemporaryFile(suffix='.' + self.SUFFIX) f = open(self.filename, 'rb') transfer_data(f.read, tempmp3.write) f.close() tempmp3.flush() #decode the mp3 file to a WAVE file wave = tempfile.NamedTemporaryFile(suffix='.wav') returnval = subprocess.call([BIN['lame'], "--decode", "--quiet", tempmp3.name, wave.name]) tempmp3.close() if (returnval == 0): #return WAVE file as a stream wave.seek(0, 0) return TempWaveReader(wave) else: return PCMReaderError( error_message=u"lame exited with error", sample_rate=self.sample_rate(), channels=self.channels(), channel_mask=int(self.channel_mask()), bits_per_sample=16)
def can_add_replay_gain(cls): """Returns True if we have the necessary binaries to add ReplayGain.""" return BIN.can_execute(BIN['mp3gain'])