major refactor
This commit is contained in:
0
admin/mpr/media_assets/management/__init__.py
Normal file
0
admin/mpr/media_assets/management/__init__.py
Normal file
54
admin/mpr/media_assets/management/commands/loadbuiltins.py
Normal file
54
admin/mpr/media_assets/management/commands/loadbuiltins.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# Import builtin presets from schema
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from admin.mpr.media_assets.models import TranscodePreset
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent.parent.parent.parent))
|
||||
from core.schema.models import BUILTIN_PRESETS
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Load builtin transcode presets"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
created_count = 0
|
||||
updated_count = 0
|
||||
|
||||
for preset_data in BUILTIN_PRESETS:
|
||||
name = preset_data["name"]
|
||||
defaults = {
|
||||
"description": preset_data.get("description", ""),
|
||||
"is_builtin": True,
|
||||
"container": preset_data.get("container", "mp4"),
|
||||
"video_codec": preset_data.get("video_codec", "libx264"),
|
||||
"video_bitrate": preset_data.get("video_bitrate"),
|
||||
"video_crf": preset_data.get("video_crf"),
|
||||
"video_preset": preset_data.get("video_preset"),
|
||||
"resolution": preset_data.get("resolution"),
|
||||
"framerate": preset_data.get("framerate"),
|
||||
"audio_codec": preset_data.get("audio_codec", "aac"),
|
||||
"audio_bitrate": preset_data.get("audio_bitrate"),
|
||||
"audio_channels": preset_data.get("audio_channels"),
|
||||
"audio_samplerate": preset_data.get("audio_samplerate"),
|
||||
"extra_args": preset_data.get("extra_args", []),
|
||||
}
|
||||
|
||||
preset, created = TranscodePreset.objects.update_or_create(
|
||||
name=name, defaults=defaults
|
||||
)
|
||||
|
||||
if created:
|
||||
created_count += 1
|
||||
self.stdout.write(self.style.SUCCESS(f"Created: {name}"))
|
||||
else:
|
||||
updated_count += 1
|
||||
self.stdout.write(f"Updated: {name}")
|
||||
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
f"Done: {created_count} created, {updated_count} updated"
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user