mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2024-11-24 21:43:44 +03:00
fixed music
This commit is contained in:
parent
fbddd3c1dc
commit
07640962fa
17
akarpov/music/migrations/0014_alter_album_authors.py
Normal file
17
akarpov/music/migrations/0014_alter_album_authors.py
Normal 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"),
|
||||||
|
),
|
||||||
|
]
|
|
@ -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})
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user