Initial commit that merge both the front end and the API in the same repository
This commit is contained in:
commit
76f98b74dd
285 changed files with 51318 additions and 0 deletions
89
api/funkwhale_api/music/migrations/0001_initial.py
Normal file
89
api/funkwhale_api/music/migrations/0001_initial.py
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.conf import settings
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Album',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, auto_created=True, serialize=False, verbose_name='ID')),
|
||||
('mbid', models.UUIDField(editable=False, blank=True, null=True)),
|
||||
('creation_date', models.DateTimeField(default=django.utils.timezone.now)),
|
||||
('title', models.CharField(max_length=255)),
|
||||
('release_date', models.DateField()),
|
||||
('type', models.CharField(default='album', choices=[('album', 'Album')], max_length=30)),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Artist',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, auto_created=True, serialize=False, verbose_name='ID')),
|
||||
('mbid', models.UUIDField(editable=False, blank=True, null=True)),
|
||||
('creation_date', models.DateTimeField(default=django.utils.timezone.now)),
|
||||
('name', models.CharField(max_length=255)),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ImportBatch',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, auto_created=True, serialize=False, verbose_name='ID')),
|
||||
('creation_date', models.DateTimeField(default=django.utils.timezone.now)),
|
||||
('submitted_by', models.ForeignKey(related_name='imports', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ImportJob',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, auto_created=True, serialize=False, verbose_name='ID')),
|
||||
('source', models.URLField()),
|
||||
('mbid', models.UUIDField(editable=False)),
|
||||
('status', models.CharField(default='pending', choices=[('pending', 'Pending'), ('finished', 'finished')], max_length=30)),
|
||||
('batch', models.ForeignKey(related_name='jobs', to='music.ImportBatch')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Track',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, auto_created=True, serialize=False, verbose_name='ID')),
|
||||
('mbid', models.UUIDField(editable=False, blank=True, null=True)),
|
||||
('creation_date', models.DateTimeField(default=django.utils.timezone.now)),
|
||||
('title', models.CharField(max_length=255)),
|
||||
('album', models.ForeignKey(related_name='tracks', blank=True, null=True, to='music.Album')),
|
||||
('artist', models.ForeignKey(related_name='tracks', to='music.Artist')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='TrackFile',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, auto_created=True, serialize=False, verbose_name='ID')),
|
||||
('audio_file', models.FileField(upload_to='tracks')),
|
||||
('source', models.URLField(blank=True, null=True)),
|
||||
('duration', models.IntegerField(blank=True, null=True)),
|
||||
('track', models.ForeignKey(related_name='files', to='music.Track')),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='album',
|
||||
name='artist',
|
||||
field=models.ForeignKey(related_name='albums', to='music.Artist'),
|
||||
),
|
||||
]
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('music', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='album',
|
||||
options={'ordering': ['-creation_date']},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='artist',
|
||||
options={'ordering': ['-creation_date']},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='importbatch',
|
||||
options={'ordering': ['-creation_date']},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='track',
|
||||
options={'ordering': ['-creation_date']},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='album',
|
||||
name='cover',
|
||||
field=models.ImageField(upload_to='albums/covers/%Y/%m/%d', null=True, blank=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='trackfile',
|
||||
name='audio_file',
|
||||
field=models.FileField(upload_to='tracks/%Y/%m/%d'),
|
||||
),
|
||||
]
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('music', '0002_auto_20151215_1645'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='album',
|
||||
name='release_date',
|
||||
field=models.DateField(null=True),
|
||||
),
|
||||
]
|
||||
21
api/funkwhale_api/music/migrations/0004_track_tags.py
Normal file
21
api/funkwhale_api/music/migrations/0004_track_tags.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import taggit.managers
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('taggit', '0002_auto_20150616_2121'),
|
||||
('music', '0003_auto_20151222_2233'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='track',
|
||||
name='tags',
|
||||
field=taggit.managers.TaggableManager(verbose_name='Tags', help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag'),
|
||||
),
|
||||
]
|
||||
40
api/funkwhale_api/music/migrations/0005_deduplicate.py
Normal file
40
api/funkwhale_api/music/migrations/0005_deduplicate.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def get_duplicates(model):
|
||||
return [i['mbid'] for i in model.objects.values('mbid').annotate(idcount=models.Count('mbid')).order_by('-idcount') if i['idcount'] > 1]
|
||||
|
||||
def deduplicate(apps, schema_editor):
|
||||
Artist = apps.get_model("music", "Artist")
|
||||
Album = apps.get_model("music", "Album")
|
||||
Track = apps.get_model("music", "Track")
|
||||
|
||||
for mbid in get_duplicates(Artist):
|
||||
ref = Artist.objects.filter(mbid=mbid).order_by('pk').first()
|
||||
duplicates = Artist.objects.filter(mbid=mbid).exclude(pk=ref.pk)
|
||||
Album.objects.filter(artist__in=duplicates).update(artist=ref)
|
||||
Track.objects.filter(artist__in=duplicates).update(artist=ref)
|
||||
duplicates.delete()
|
||||
|
||||
for mbid in get_duplicates(Album):
|
||||
ref = Album.objects.filter(mbid=mbid).order_by('pk').first()
|
||||
duplicates = Album.objects.filter(mbid=mbid).exclude(pk=ref.pk)
|
||||
Track.objects.filter(album__in=duplicates).update(album=ref)
|
||||
duplicates.delete()
|
||||
|
||||
def rewind(*args, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('music', '0004_track_tags'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(deduplicate, rewind),
|
||||
]
|
||||
28
api/funkwhale_api/music/migrations/0006_unique_mbid.py
Normal file
28
api/funkwhale_api/music/migrations/0006_unique_mbid.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('music', '0005_deduplicate'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='album',
|
||||
name='mbid',
|
||||
field=models.UUIDField(null=True, editable=False, unique=True, blank=True, db_index=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='artist',
|
||||
name='mbid',
|
||||
field=models.UUIDField(null=True, editable=False, unique=True, blank=True, db_index=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='track',
|
||||
name='mbid',
|
||||
field=models.UUIDField(null=True, editable=False, unique=True, blank=True, db_index=True),
|
||||
),
|
||||
]
|
||||
19
api/funkwhale_api/music/migrations/0007_track_position.py
Normal file
19
api/funkwhale_api/music/migrations/0007_track_position.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('music', '0006_unique_mbid'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='track',
|
||||
name='position',
|
||||
field=models.PositiveIntegerField(blank=True, null=True),
|
||||
),
|
||||
]
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('music', '0007_track_position'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='album',
|
||||
name='mbid',
|
||||
field=models.UUIDField(null=True, db_index=True, unique=True, blank=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='artist',
|
||||
name='mbid',
|
||||
field=models.UUIDField(null=True, db_index=True, unique=True, blank=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='track',
|
||||
name='mbid',
|
||||
field=models.UUIDField(null=True, db_index=True, unique=True, blank=True),
|
||||
),
|
||||
]
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
import versatileimagefield.fields
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('music', '0008_auto_20160529_1456'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Lyrics',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, verbose_name='ID', serialize=False)),
|
||||
('url', models.URLField()),
|
||||
('content', models.TextField(null=True, blank=True)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Work',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, verbose_name='ID', serialize=False)),
|
||||
('mbid', models.UUIDField(unique=True, null=True, db_index=True, blank=True)),
|
||||
('creation_date', models.DateTimeField(default=django.utils.timezone.now)),
|
||||
('language', models.CharField(max_length=20)),
|
||||
('nature', models.CharField(max_length=50)),
|
||||
('title', models.CharField(max_length=255)),
|
||||
],
|
||||
options={
|
||||
'ordering': ['-creation_date'],
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='lyrics',
|
||||
name='work',
|
||||
field=models.ForeignKey(related_name='lyrics', to='music.Work', blank=True, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='track',
|
||||
name='work',
|
||||
field=models.ForeignKey(related_name='tracks', to='music.Work', blank=True, null=True),
|
||||
),
|
||||
]
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import versatileimagefield.fields
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('music', '0009_auto_20160920_1614'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='lyrics',
|
||||
name='url',
|
||||
field=models.URLField(unique=True),
|
||||
),
|
||||
]
|
||||
61
api/funkwhale_api/music/migrations/0011_rename_files.py
Normal file
61
api/funkwhale_api/music/migrations/0011_rename_files.py
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import os
|
||||
|
||||
from django.db import migrations, models
|
||||
from funkwhale_api.common.utils import rename_file
|
||||
|
||||
|
||||
def rename_files(apps, schema_editor):
|
||||
"""
|
||||
This migration script is utterly broken and made me redownload all my audio files.
|
||||
So next time -> Write some actual tests before running a migration script
|
||||
on thousand of tracks...
|
||||
"""
|
||||
return
|
||||
# TrackFile = apps.get_model("music", "TrackFile")
|
||||
# qs = TrackFile.objects.select_related(
|
||||
# 'track__album__artist', 'track__artist')
|
||||
# total = len(qs)
|
||||
#
|
||||
#
|
||||
# for i, tf in enumerate(qs):
|
||||
# try:
|
||||
# new_name = '{} - {} - {}'.format(
|
||||
# tf.track.artist.name,
|
||||
# tf.track.album.title,
|
||||
# tf.track.title,
|
||||
# )
|
||||
# except AttributeError:
|
||||
# new_name = '{} - {}'.format(
|
||||
# tf.track.artist.name,
|
||||
# tf.track.title,
|
||||
# )
|
||||
# rename_file(
|
||||
# instance=tf,
|
||||
# field_name='audio_file',
|
||||
# allow_missing_file=True,
|
||||
# new_name=new_name)
|
||||
# print('Renamed file {}/{} (new name: {})'.format(
|
||||
# i + 1, total, tf.audio_file.name
|
||||
# ))
|
||||
|
||||
|
||||
def rewind(apps, schema_editor):
|
||||
pass
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('music', '0010_auto_20160920_1742'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='trackfile',
|
||||
name='audio_file',
|
||||
field=models.FileField(upload_to='tracks/%Y/%m/%d', max_length=255),
|
||||
),
|
||||
migrations.RunPython(rename_files, rewind),
|
||||
]
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import versatileimagefield.fields
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('music', '0011_rename_files'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='album',
|
||||
name='cover',
|
||||
field=versatileimagefield.fields.VersatileImageField(null=True, blank=True, upload_to='albums/covers/%Y/%m/%d'),
|
||||
),
|
||||
]
|
||||
0
api/funkwhale_api/music/migrations/__init__.py
Normal file
0
api/funkwhale_api/music/migrations/__init__.py
Normal file
Loading…
Add table
Add a link
Reference in a new issue