def setUp(self): self.filename = get_temp_copy( os.path.join(DATA_DIR, "sample.oggtheora")) self.audio = OggTheora(self.filename) self.audio2 = OggTheora( os.path.join(DATA_DIR, "sample_length.oggtheora")) self.audio3 = OggTheora( os.path.join(DATA_DIR, "sample_bitrate.oggtheora"))
def setUp(self): original = os.path.join("tests", "data", "sample.oggtheora") fd, self.filename = mkstemp(suffix='.ogg') os.close(fd) shutil.copy(original, self.filename) self.audio = OggTheora(self.filename) self.audio2 = OggTheora( os.path.join("tests", "data", "sample_length.oggtheora")) self.audio3 = OggTheora( os.path.join("tests", "data", "sample_bitrate.oggtheora"))
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()
def test_prefer_theora_over_vorbis(self): header = ( b"OggS\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\xe1x\x06\x0f" b"\x00\x00\x00\x00)S'\xf4\x01*\x80theora\x03\x02\x01\x006\x00\x1e" b"\x00\x03V\x00\x01\xe0\x00\x00\x00\x00\x00\x18\x00\x00\x00\x01" b"\x00\x00\x00\x00\x00\x00\x00&%\xa0\x00\xc0OggS\x00\x02\x00\x00" b"\x00\x00\x00\x00\x00\x00d#\xa8\x1f\x00\x00\x00\x00]Y\xc0\xc0" b"\x01\x1e\x01vorbis\x00\x00\x00\x00\x02\x80\xbb\x00\x00\x00\x00" b"\x00\x00\x00\xee\x02\x00\x00\x00\x00\x00\xb8\x01") fileobj = cBytesIO(header) filename = "not-identifiable.ext" self.failUnless(OggVorbis.score(filename, fileobj, header) < OggTheora.score(filename, fileobj, header))
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 test_module_delete(self): delete(self.filename) self.scan_file() self.failIf(OggTheora(self.filename).tags)
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')