class TWavPack(TestCase): def setUp(self): self.audio = WavPack(os.path.join("tests", "data", "silence-44-s.wv")) def test_version(self): self.failUnlessEqual(self.audio.info.version, 0x403) def test_channels(self): self.failUnlessEqual(self.audio.info.channels, 2) def test_sample_rate(self): self.failUnlessEqual(self.audio.info.sample_rate, 44100) def test_length(self): self.failUnlessAlmostEqual(self.audio.info.length, 3.68, 2) def test_not_my_file(self): self.failUnlessRaises( IOError, WavPack, os.path.join("tests", "data", "empty.ogg")) def test_pprint(self): self.audio.pprint() def test_mime(self): self.failUnless("audio/x-wavpack" in self.audio.mime)
class TWavPack(TestCase): def setUp(self): self.audio = WavPack(os.path.join("tests", "data", "silence-44-s.wv")) def test_version(self): self.failUnlessEqual(self.audio.info.version, 0x403) def test_channels(self): self.failUnlessEqual(self.audio.info.channels, 2) def test_sample_rate(self): self.failUnlessEqual(self.audio.info.sample_rate, 44100) def test_length(self): self.failUnlessAlmostEqual(self.audio.info.length, 3.68, 2) def test_not_my_file(self): self.failUnlessRaises(IOError, WavPack, os.path.join("tests", "data", "empty.ogg")) def test_pprint(self): self.audio.pprint() def test_mime(self): self.failUnless("audio/x-wavpack" in self.audio.mime)
def __init__(self, filename): with translate_errors(): audio = WavPack(filename) super(WavpackFile, self).__init__(filename, audio) self["~#length"] = audio.info.length self["~#channels"] = audio.info.channels self.sanitize(filename)
def getTrack(filename): """ Return a Track created from a WavPack file """ from mutagen.wavpack import WavPack wvFile = WavPack(filename) length = int(round(wvFile.info.length)) samplerate = int(wvFile.info.sample_rate) try: title = str(wvFile['Title'][0]) except: title = None try: album = str(wvFile['Album'][0]) except: album = None try: artist = str(wvFile['Artist'][0]) except: artist = None try: albumArtist = str(wvFile['Album Artist'][0]) except: albumArtist = None try: genre = str(wvFile['genre'][0]) except: genre = None try: trackNumber = str(wvFile['Track'][0]) except: trackNumber = None try: discNumber = str(wvFile['Disc'][0]) except: discNumber = None try: date = str(wvFile['Year'][0]) except: date = None return createFileTrack(filename, -1, length, samplerate, False, title, album, artist, albumArtist, None, genre, trackNumber, date, discNumber)
def __init__(self, filename): with translate_errors(): audio = WavPack(filename) super().__init__(filename, audio) self["~#length"] = audio.info.length self["~#channels"] = audio.info.channels self["~#samplerate"] = audio.info.sample_rate self.sanitize(filename)
def clean(self): file = self.cleaned_data.get('file', False) acceptedMime = ['audio/mpeg', 'audio/mpeg3', 'audio/x-mpeg-3', 'audio/ogg', 'application/ogg', 'audio/x-ogg', 'application/x-ogg', 'video/ogg', 'audio/wav', 'audio/x-wav', 'audio/wave', 'audio/x-pn-wav'] type = "none" if file: if file._size > 10*1024*1024: raise forms.ValidationError(file.name + ': File too large. Max Limit: 10MB') elif not file.content_type in acceptedMime: raise forms.ValidationError(file.name + ': It is not a mp3, ogg, or wav file') try: OggVorbis(file.temporary_file_path()) type = 'OGG' except: pass try: OggFLAC(file.temporary_file_path()) type = 'OGG' except: pass try: OggOpus(file.temporary_file_path()) type = 'OGG' except: pass try: OggSpeex(file.temporary_file_path()) type = 'OGG' except: pass try: OggTheora(file.temporary_file_path()) type = 'OGG' except: pass try: MP3(file.temporary_file_path()) type = 'MP3' except: pass try: WavPack(file.temporary_file_path()) type = 'WAV' except: pass if not type in ['OGG', 'MP3', 'WAV']: raise forms.ValidationError(file.name + ': Unsupported file type') return file else: raise forms.ValidationError(file.name + ': File cannot be opened')
def __init__(self, file, threshold=60, duration_distance_threshold=10000): self.file = file self.threshold = threshold self.ddt = duration_distance_threshold self.cleaner = re.compile(r"[^A-Za-z0-9 ]").sub try: self.audio = MP3(file, ID3=EasyID3) except: try: self.audio = FLAC(file) except: try: self.audio = OggVorbis(file) except: try: self.audio = OggFLAC(file) except: try: self.audio = OggTheora(file) except: try: self.audio = APEv2(file) except: try: self.audio = ASF(file) except: try: self.audio = MP4(file) except: try: self.audio = Musepack(file) except: try: self.audio = TrueAudio(file) except: try: self.audio = WavPack(file) except: raise FileTypeException( 'Unknown file type, no metadata, or file not found.' ) try: [title] = self.audio['title'] self.title = self.__clean_literal(str(title)) except: self.title = None try: [artist] = self.audio['artist'] self.artist = self.__clean_literal(str(artist)) except: self.artist = None try: [album] = self.audio['album'] self.album = self.__clean_literal(str(album)) except: self.album = None self.mbzQuery()
class TWavPackNoLength(TestCase): def setUp(self): self.audio = WavPack(os.path.join("tests", "data", "no_length.wv")) def test_version(self): self.failUnlessEqual(self.audio.info.version, 0x407) def test_channels(self): self.failUnlessEqual(self.audio.info.channels, 2) def test_sample_rate(self): self.failUnlessEqual(self.audio.info.sample_rate, 44100) def test_length(self): self.failUnlessAlmostEqual(self.audio.info.length, 3.705, 3) def test_pprint(self): self.audio.pprint() def test_mime(self): self.failUnless("audio/x-wavpack" in self.audio.mime)
class TWavPackDSD(TestCase): def setUp(self): self.audio = WavPack(os.path.join(DATA_DIR, "dsd.wv")) def test_version(self): self.failUnlessEqual(self.audio.info.version, 0x410) def test_channels(self): self.failUnlessEqual(self.audio.info.channels, 2) def test_sample_rate(self): self.failUnlessEqual(self.audio.info.sample_rate, 352800) def test_bits_per_sample(self): self.failUnlessEqual(self.audio.info.bits_per_sample, 1) def test_length(self): self.failUnlessAlmostEqual(self.audio.info.length, 0.01, 3) def test_pprint(self): self.audio.pprint() def test_mime(self): self.failUnless("audio/x-wavpack" in self.audio.mime)
def isAMusicFile(filePath): type = "none" try: OggVorbis(filePath) type = 'OGG' except: pass try: OggFLAC(filePath) type = 'OGG' except: pass try: OggOpus(filePath) type = 'OGG' except: pass try: OggSpeex(filePath) type = 'OGG' except: pass try: OggTheora(filePath) type = 'OGG' except: pass try: MP3(filePath) type = 'MP3' except: pass try: WavPack(filePath) type = 'WAV' except: pass if not type in ['OGG', 'MP3', 'WAV']: return False return True
def get_mutagen_audio (path): logging.debug("GET mutagen audio" + path) ext = get_file_extension(path) audio = None if ext == ".flac": audio = FLAC(path) if ext == ".ape": audio = MonkeysAudio(path) if ext == ".mp3": audio = MP3(path, ID3=EasyID3) if ext == ".wv": audio = WavPack(path) if ext == ".wma": audio = ASF(path) if ext == ".ogg": try: audio = OggVorbis(path) except: from mutagen.oggtheora import OggTheora try: audio = OggTheora(path) except: from mutagen.oggflac import OggFLAC try: audio = OggFLAC(path) except: from mutagen.oggspeex import OggSpeex try: audio = OggSpeex(path) except: logging.error("This file in not ogg format") if ext == ".m4a" or ext == ".mp4" or ext == ".mkv": audio = MP4(path) return audio
def setUp(self): self.audio = WavPack(os.path.join("tests", "data", "no_length.wv"))
def setUp(self): self.audio = WavPack(os.path.join("tests", "data", "silence-44-s.wv"))
def setUp(self): self.audio = WavPack(os.path.join(DATA_DIR, "dsd.wv"))
def setUp(self): self.audio = WavPack(os.path.join(DATA_DIR, "silence-44-s.wv"))
def setUp(self): self.audio = WavPack(os.path.join(DATA_DIR, "no_length.wv"))
def __init__(self, filename): audio = WavPack(filename) super(WavpackFile, self).__init__(filename, audio) self["~#length"] = int(audio.info.length) self.sanitize(filename)
def isSongValid(file): acceptedMime = [ 'audio/mp3', 'audio/mpeg', 'audio/mpeg3', 'audio/x-mpeg-3', 'audio/ogg', 'application/ogg', 'audio/x-ogg', 'application/x-ogg', 'video/ogg', 'audio/wav', 'audio/x-wav', 'audio/wave', 'audio/x-pn-wav' ] type = "none" if file: if file._size > 10 * 1024 * 1024: return ('File too large. Max Limit: 10MB') elif not file.content_type in acceptedMime: if settings.DEBUG: return ('MIMETYPE: ' + file.content_type + ' Not a mp3, ogg, or wav file') else: logger.error('MIMETYPE: ' + file.content_type + ' Not a mp3, ogg, or wav file') return ('It is not a mp3, ogg, or wav file') try: OggVorbis(file.temporary_file_path()) type = 'OGG' except: pass try: OggFLAC(file.temporary_file_path()) type = 'OGG' except: pass try: OggOpus(file.temporary_file_path()) type = 'OGG' except: pass try: OggSpeex(file.temporary_file_path()) type = 'OGG' except: pass try: OggTheora(file.temporary_file_path()) type = 'OGG' except: pass try: MP3(file.temporary_file_path()) type = 'MP3' except: pass try: WavPack(file.temporary_file_path()) type = 'WAV' except: pass if not type in ['OGG', 'MP3', 'WAV']: return ('Unsupported file type') return True else: return ('File cannot be opened')
def detect_file_codec(path): """ Try to detect codec for file """ if not os.path.isfile(path): return None name, extension = os.path.splitext(path) if extension in ('.m4a', 'caf'): from mutagen.mp4 import MP4 try: codec = MP4(path).info.codec if codec == 'alac': return codec elif codec[:4] == 'mp4a': return 'aac' except Exception as e: raise ValueError('Error detecting file {} codec: {}'.format( path, e)) if extension == '.aif': from mutagen.aiff import AIFF try: AIFF(path).info return 'aif' except Exception as e: raise ValueError('Error opening {} as aif: {}'.format(path, e)) if extension == '.flac': from mutagen.flac import FLAC try: FLAC(path).info return 'flac' except Exception as e: raise ValueError('Error opening {} as flac: {}'.format(path, e)) if extension == '.mp3': from mutagen.mp3 import MP3 try: MP3(path).info return 'mp3' except Exception as e: raise ValueError('Error opening {} as mp3: {}'.format(path, e)) if extension == '.opus': from mutagen.oggopus import OggOpus try: OggOpus(path).info return 'opus' except Exception as e: raise ValueError('Error opening {} as mp3: {}'.format(path, e)) if extension == '.ogg': from mutagen.oggvorbis import OggVorbis try: OggVorbis(path).info return 'vorbis' except Exception as e: raise ValueError('Error opening {} as ogg vorbis: {}'.format( path, e)) if extension == '.wv': from mutagen.wavpack import WavPack try: WavPack(path).info return 'wavpack' except Exception as e: raise ValueError('Error opening {} as wavpack: {}'.format(path, e)) return None