fixed music

This commit is contained in:
Alexander Karpov 2023-12-18 17:30:47 +03:00
parent fbddd3c1dc
commit 07640962fa
4 changed files with 31 additions and 13 deletions

View File

@ -0,0 +1,17 @@
# Generated by Django 4.2.8 on 2023-12-18 14:30
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("music", "0013_remove_author_albums_album_authors_alter_album_name_and_more"),
]
operations = [
migrations.AlterField(
model_name="album",
name="authors",
field=models.ManyToManyField(related_name="albums", to="music.author"),
),
]

View File

@ -23,7 +23,7 @@ class Album(BaseImageModel, ShortLinkModel):
name = models.CharField(max_length=200, unique=True)
link = models.URLField(blank=True)
meta = models.JSONField(blank=True, null=True)
authors = models.ManyToManyField("Album", related_name="albums")
authors = models.ManyToManyField("Author", related_name="albums")
def get_absolute_url(self):
return reverse("music:album", kwargs={"slug": self.slug})

View File

@ -113,7 +113,7 @@ def load_track(
album.save()
if authors:
song.authors.set(authors)
song.authors.set([x.id for x in authors])
# set music meta
tag = MutagenFile(song.file.path)

View File

@ -126,6 +126,16 @@ def update_album_info(album: AlbumModel) -> None:
"description": search_album.description,
"type": search_album.type,
}
album.meta = data
image_path = str(settings.MEDIA_ROOT + f"/_{str(randint(10000, 99999))}.png")
if search_album.cover_uri:
search_album.download_cover(filename=image_path)
with open(image_path, "rb") as f:
album.image = File(f, name=image_path.split("/")[-1])
album.save()
os.remove(image_path)
authors = []
if search_album.artists:
for x in search_album.artists:
@ -133,17 +143,8 @@ def update_album_info(album: AlbumModel) -> None:
authors.append(Author.objects.get(name=x.name))
except Author.DoesNotExist:
authors.append(Author.objects.create(name=x.name))
album.authors.set(authors)
album.meta = data
image_path = str(settings.MEDIA_ROOT + f"/_{str(randint(10000, 99999))}.png")
if not search_album.cover_uri:
album.save()
return
search_album.download_cover(filename=image_path)
with open(image_path, "rb") as f:
album.image = File(f, name=image_path.split("/")[-1])
album.save()
os.remove(image_path)
album.authors.set([x.id for x in authors])
album.save()
def update_author_info(author: Author) -> None: