示例#1
0
	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')
示例#2
0
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
示例#3
0
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
示例#4
0
 def test_module_delete(self):
     delete(self.filename)
     self.scan_file()
     self.failIf(OggSpeex(self.filename).tags)
示例#5
0
    def cleanAllTags(self, db, element, path_normalizado):
        """ Method to clean all rating and playcount tags from the file"""
        try:
            # Get the audio tagging format of the current element
            format = self._check_recognized_format(path_normalizado)
            if format is None:
                raise Exception("Unrecognized format")
            else:
                needsave = False
                if format == "id3v2":
                    audio = ID3(path_normalizado)
                    if audio.has_key('POPM'):
                        audio.delall('POPM')
                        needsave = True
                    if audio.has_key('PCNT'):
                        audio.delall('PCNT')
                        needsave = True
                    if audio.has_key(u'TXXX:FMPS_Rating'):
                        audio.delall(u'TXXX:FMPS_Rating')
                        needsave = True
                    if audio.has_key(u'TXXX:FMPS_Playcount'):
                        audio.delall(u'TXXX:FMPS_Playcount')
                        needsave = True

                elif format == "oggvorbis":
                    audio = OggVorbis(path_normalizado)
                    if audio.has_key('FMPS_RATING'):
                        del audio['FMPS_RATING']
                        needsave = True
                    if audio.has_key('FMPS_PLAYCOUNT'):
                        del audio['FMPS_PLAYCOUNT']
                        needsave = True

                elif format == "flac":
                    audio = FLAC(path_normalizado)
                    if audio.has_key('FMPS_RATING'):
                        del audio['FMPS_RATING']
                        needsave = True
                    if audio.has_key('FMPS_PLAYCOUNT'):
                        del audio['FMPS_PLAYCOUNT']
                        needsave = True

                elif format == "mp4":
                    audio = MP4(path_normalizado)
                    if audio.has_key('----:com.apple.iTunes:FMPS_Rating'):
                        del audio['----:com.apple.iTunes:FMPS_Rating']
                        needsave = True
                    if audio.has_key('----:com.apple.iTunes:FMPS_Playcount'):
                        del audio['----:com.apple.iTunes:FMPS_Playcount']
                        needsave = True

                elif format == "musepack":
                    audio = Musepack(path_normalizado)
                    if audio.has_key('FMPS_RATING'):
                        del audio['FMPS_RATING']
                        needsave = True
                    if audio.has_key('FMPS_PLAYCOUNT'):
                        del audio['FMPS_PLAYCOUNT']
                        needsave = True

                elif format == "oggspeex":
                    audio = OggSpeex(path_normalizado)
                    if audio.has_key('FMPS_RATING'):
                        del audio['FMPS_RATING']
                        needsave = True
                    if audio.has_key('FMPS_PLAYCOUNT'):
                        del audio['FMPS_PLAYCOUNT']
                        needsave = True

                if needsave:
                    audio.save()
                    self.num_cleaned += 1
                else:
                    self.num_already_done += 1

        except Exception, e:
            self.num_failed += 1
            print(e, path_normalizado)
示例#6
0
 def _restore_db_from_oggspeex(self, pathSong):
     audio = OggSpeex(pathSong)
     return self._restore_db_from_vcomment(audio)
示例#7
0
 def _save_db_to_oggspeex(self, pathSong, dbrating, dbcount):
     audio = OggSpeex(pathSong)
     self._save_db_to_vcomment(audio, dbrating, dbcount)
示例#8
0
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')