Transcodage auto m4a vers mp3
This commit is contained in:
parent
00f1922095
commit
c81a8377fd
2 changed files with 25 additions and 1 deletions
|
|
@ -1,7 +1,7 @@
|
|||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin
|
||||
|
||||
from beesgospel.models import Agenda, Chant, Document, Membre, User
|
||||
from beesgospel.models import Agenda, Chant, ChantDoc, Document, Membre, User
|
||||
|
||||
|
||||
@admin.register(Agenda)
|
||||
|
|
@ -33,6 +33,11 @@ class ChantAdmin(admin.ModelAdmin):
|
|||
ordering = ["titre"]
|
||||
|
||||
|
||||
@admin.register(ChantDoc)
|
||||
class ChantDocAdmin(admin.ModelAdmin):
|
||||
list_display = ["titre", "chant", "fichier", "lien"]
|
||||
|
||||
|
||||
@admin.register(User)
|
||||
class UserAdmin(UserAdmin):
|
||||
list_display = ["email", "is_active", "is_staff", "last_login"]
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import os
|
||||
import subprocess
|
||||
from secrets import token_hex
|
||||
|
||||
from django import forms
|
||||
|
|
@ -75,6 +77,23 @@ class ChantDocForm(BootstrapMixin, forms.ModelForm):
|
|||
raise forms.ValidationError("Vous ne pouvez pas indiquer à la fois un fichier et un lien")
|
||||
return data
|
||||
|
||||
def save(self, **kwargs):
|
||||
is_new = not self.instance.pk
|
||||
instance = super().save(**kwargs)
|
||||
if is_new and instance.fichier and instance.fichier.name.endswith(".m4a"):
|
||||
old_path = instance.fichier.path
|
||||
try:
|
||||
subprocess.run([
|
||||
"ffmpeg", "-i", old_path, "-q:a", "6", old_path.replace(".m4a", ".mp3"),
|
||||
], check=True)
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
else:
|
||||
instance.fichier.name = instance.fichier.name.replace(".m4a", ".mp3")
|
||||
instance.save()
|
||||
os.unlink(old_path)
|
||||
return instance
|
||||
|
||||
|
||||
class ChantEditForm(BootstrapMixin, forms.ModelForm):
|
||||
class Meta:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue