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) name = models.CharField(max_length=200, unique=True)
link = models.URLField(blank=True) link = models.URLField(blank=True)
meta = models.JSONField(blank=True, null=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): def get_absolute_url(self):
return reverse("music:album", kwargs={"slug": self.slug}) return reverse("music:album", kwargs={"slug": self.slug})

View File

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

View File

@ -126,6 +126,16 @@ def update_album_info(album: AlbumModel) -> None:
"description": search_album.description, "description": search_album.description,
"type": search_album.type, "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 = [] authors = []
if search_album.artists: if search_album.artists:
for x in 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)) authors.append(Author.objects.get(name=x.name))
except Author.DoesNotExist: except Author.DoesNotExist:
authors.append(Author.objects.create(name=x.name)) authors.append(Author.objects.create(name=x.name))
album.authors.set(authors) album.authors.set([x.id for x in authors])
album.meta = data album.save()
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)
def update_author_info(author: Author) -> None: def update_author_info(author: Author) -> None: