2018-02-18 22:46:15 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2018-06-10 08:39:47 +00:00
|
|
|
from django.db import migrations
|
2018-02-18 22:46:15 +00:00
|
|
|
from funkwhale_api.music.utils import guess_mimetype
|
|
|
|
|
|
|
|
|
|
|
|
def populate_mimetype(apps, schema_editor):
|
|
|
|
TrackFile = apps.get_model("music", "TrackFile")
|
|
|
|
|
2018-06-09 13:36:16 +00:00
|
|
|
for tf in TrackFile.objects.filter(
|
|
|
|
audio_file__isnull=False, mimetype__isnull=True
|
|
|
|
).only("audio_file"):
|
2018-02-18 22:46:15 +00:00
|
|
|
try:
|
|
|
|
tf.mimetype = guess_mimetype(tf.audio_file)
|
|
|
|
except Exception as e:
|
2018-06-09 13:36:16 +00:00
|
|
|
print("Error on track file {}: {}".format(tf.pk, e))
|
2018-02-18 22:46:15 +00:00
|
|
|
continue
|
2018-06-09 13:36:16 +00:00
|
|
|
print("Track file {}: {}".format(tf.pk, tf.mimetype))
|
|
|
|
tf.save(update_fields=["mimetype"])
|
2018-02-18 22:46:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
def rewind(apps, schema_editor):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
2018-06-09 13:36:16 +00:00
|
|
|
dependencies = [("music", "0018_auto_20180218_1554")]
|
2018-02-18 22:46:15 +00:00
|
|
|
|
2018-06-09 13:36:16 +00:00
|
|
|
operations = [migrations.RunPython(populate_mimetype, rewind)]
|