Django应用程序,用于上传和转换音频文件(mp3、wav和ogg格式)
项目描述
Django-Audiofield
Django-Audiofield是一个简单的应用程序,允许上传、管理和转换不同音频格式(mp3、wav & ogg)的音频文件,同时也使得在Django应用程序中播放音频文件变得简单。
我们使用HTML5和Flash音频播放器 SoundManager2
安装
安装Django-Audiofield
python setup.py install
依赖项
在Debian上安装依赖项
apt-get -y install libsox-fmt-mp3 libsox-fmt-all mpg321 dir2ogg ffmpeg
注意:对于Debian版本7(Wheezy)和更早版本,将ffmpeg替换为libav-tools
在Redhat/CentOS上安装依赖项
yum -y install python-setuptools libsox-fmt-mp3 libsox-fmt-all mpg321 dir2ogg
在Redhat/CentOS上安装avconv
git clone git://git.libav.org/libav.git cd libav sudo ./configure --disable-yasm sudo make sudo make install
设置
在您的settings.py文件中
# Set Following variable MEDIA_ROOT = '' MEDIA_URL = '' In MIDDLEWARE_CLASSES add 'audiofield.middleware.threadlocals.ThreadLocals' In INSTALLED_APPS add 'audiofield' # Frontend widget values # 0-Keep original, 1-Mono, 2-Stereo CHANNEL_TYPE_VALUE = 0 # 0-Keep original, 8000-8000Hz, 16000-16000Hz, 22050-22050Hz, # 44100-44100Hz, 48000-48000Hz, 96000-96000Hz FREQ_TYPE_VALUE = 8000 # 0-Keep original, 1-Convert to MP3, 2-Convert to WAV, 3-Convert to OGG CONVERT_TYPE_VALUE = 0
用法
在您的models.py文件中添加以下行
from django.conf import settings from audiofield.fields import AudioField import os.path # Add the audio field to your model audio_file = AudioField(upload_to='your/upload/dir', blank=True, ext_whitelist=(".mp3", ".wav", ".ogg"), help_text=("Allowed type - .mp3, .wav, .ogg")) # Add this method to your model def audio_file_player(self): """audio player tag for admin""" if self.audio_file: file_url = settings.MEDIA_URL + str(self.audio_file) player_string = '<audio src="%s" controls>Your browser does not support the audio element.</audio>' % (file_url) return player_string audio_file_player.allow_tags = True audio_file_player.short_description = ('Audio file player')
在您的admin.py文件中添加以下行
from your_app.models import your_model_name # add 'audio_file_player' tag to your admin view list_display = (..., 'audio_file_player', ...) actions = ['custom_delete_selected'] def custom_delete_selected(self, request, queryset): #custom delete code n = queryset.count() for i in queryset: if i.audio_file: if os.path.exists(i.audio_file.path): os.remove(i.audio_file.path) i.delete() self.message_user(request, ("Successfully deleted %d audio files.") % n) custom_delete_selected.short_description = "Delete selected items" def get_actions(self, request): actions = super(AudioFileAdmin, self).get_actions(request) del actions['delete_selected'] return actions
然后执行以下命令以创建表并收集静态文件
./manage.py syncdb ./manage.py collectstatic
创建audiofield.log文件
touch /var/log/audio-field.log
贡献
如果您发现了一个错误,实现了一个功能,或自定义了模板并认为它有用,那么请考虑做出贡献。补丁、拉取请求或只是建议都欢迎!
源代码: http://github.com/Star2Billing/django-audiofield
错误跟踪器:https://github.com/Star2Billing/django-audiofield/issues
文档
文档可在‘Read the Docs’上找到:http://django-audiofield.readthedocs.org
致谢
Django-audiofield 是 Star2Billing 赞助的社区项目,更多信息请访问 http://www.star2billing.com 或通过电子邮件联系我们 info@star2billing.com
许可证
Django-Audiofield 采用 MIT 许可,请参阅 MIT-LICENSE.txt。
待办事项
使用 pydub (http://pydub.com) 将音频转换从 django-audiofield 中分离出来
与 django-storage (http://django-storages.readthedocs.org/) 集成
支持更多格式
项目详情
django-audiofield-0.10.1.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 10608885b60465ce6a95d2309f260fcbd1c52e12233b3a15b1056de9e14a7030 |
|
MD5 | e4882722bcb65da812818f30107986a7 |
|
BLAKE2b-256 | d68fefaf9eeb932da45d964a30fb8881c244f18079a4dea74a6124a94b50399c |