mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2024-11-28 06:53:43 +03:00
Compare commits
10 Commits
bb8454fe5b
...
25cb98b380
Author | SHA1 | Date | |
---|---|---|---|
|
25cb98b380 | ||
|
bbe08d0f43 | ||
f2f5446c18 | |||
|
f39e49ab39 | ||
|
0f465e40de | ||
8f19d51410 | |||
07640962fa | |||
fbddd3c1dc | |||
79e865bf37 | |||
75d787f460 |
|
@ -13,6 +13,11 @@
|
|||
from ..documents import FileDocument
|
||||
from .lema import lemmatize_and_remove_stopwords
|
||||
|
||||
"""
|
||||
Calculus on types of searches:
|
||||
https://new.akarpov.ru/files/FZUTFBIyfbdlDHVzxUNU
|
||||
"""
|
||||
|
||||
|
||||
class BaseSearch:
|
||||
def __init__(self, queryset: QuerySet | None = None):
|
||||
|
|
|
@ -92,9 +92,7 @@ def get_queryset(self):
|
|||
):
|
||||
return self.filter(BaseFileItem.objects.none())
|
||||
return self.filter(
|
||||
BaseFileItem.objects.cache().filter(
|
||||
user=self.request.user, parent__isnull=True
|
||||
)
|
||||
BaseFileItem.objects.filter(user=self.request.user, parent__isnull=True)
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
# Generated by Django 4.2.8 on 2023-12-18 11:44
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("music", "0012_album_meta_author_albums_author_meta"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name="author",
|
||||
name="albums",
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="album",
|
||||
name="authors",
|
||||
field=models.ManyToManyField(related_name="albums", to="music.album"),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="album",
|
||||
name="name",
|
||||
field=models.CharField(max_length=200, unique=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="author",
|
||||
name="name",
|
||||
field=models.CharField(max_length=200, unique=True),
|
||||
),
|
||||
]
|
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"),
|
||||
),
|
||||
]
|
|
@ -8,10 +8,9 @@
|
|||
|
||||
|
||||
class Author(BaseImageModel, ShortLinkModel):
|
||||
name = models.CharField(max_length=200)
|
||||
name = models.CharField(max_length=200, unique=True)
|
||||
link = models.URLField(blank=True)
|
||||
meta = models.JSONField(blank=True, null=True)
|
||||
albums = models.ManyToManyField("Album", related_name="authors")
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("music:author", kwargs={"slug": self.slug})
|
||||
|
@ -21,9 +20,10 @@ def __str__(self):
|
|||
|
||||
|
||||
class Album(BaseImageModel, ShortLinkModel):
|
||||
name = models.CharField(max_length=200)
|
||||
name = models.CharField(max_length=200, unique=True)
|
||||
link = models.URLField(blank=True)
|
||||
meta = models.JSONField(blank=True, null=True)
|
||||
authors = models.ManyToManyField("Author", related_name="albums")
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("music:album", kwargs={"slug": self.slug})
|
||||
|
|
|
@ -27,16 +27,28 @@ def load_track(
|
|||
if album and type(album) is str and album.startswith("['"):
|
||||
album = album.replace("['", "").replace("']", "")
|
||||
|
||||
re_authors = []
|
||||
if authors:
|
||||
authors = [Author.objects.get_or_create(name=x)[0] for x in authors if authors]
|
||||
else:
|
||||
authors = []
|
||||
for x in authors:
|
||||
try:
|
||||
re_authors.append(Author.objects.get(name=x))
|
||||
except Author.DoesNotExist:
|
||||
re_authors.append(Author.objects.create(name=x))
|
||||
authors = re_authors
|
||||
album_name = None
|
||||
if album:
|
||||
if type(album) is str:
|
||||
album = Album.objects.get_or_create(name=album)[0]
|
||||
album_name = album
|
||||
elif type(album) is list:
|
||||
album = Album.objects.get_or_create(name=album[0])[0]
|
||||
album_name = album[0]
|
||||
else:
|
||||
album_name = None
|
||||
if album_name:
|
||||
try:
|
||||
album = Album.objects.get(name=album_name)
|
||||
except Album.DoesNotExist:
|
||||
album = Album.objects.create(name=album_name)
|
||||
if not album_name:
|
||||
album = None
|
||||
|
||||
if sng := Song.objects.filter(
|
||||
|
@ -101,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)
|
||||
|
|
|
@ -62,8 +62,6 @@ def load_file_meta(track: int, user_id: int) -> str:
|
|||
que.delete()
|
||||
return ""
|
||||
|
||||
print("Start downloading")
|
||||
|
||||
filename = f"_{str(randint(10000, 9999999))}"
|
||||
orig_path = f"{settings.MEDIA_ROOT}/{filename}.mp3"
|
||||
album = track.albums[0]
|
||||
|
@ -76,13 +74,10 @@ def load_file_meta(track: int, user_id: int) -> str:
|
|||
except NotFoundError:
|
||||
img_pth = None
|
||||
|
||||
print("Downloaded file")
|
||||
|
||||
try:
|
||||
lyrics = track.get_lyrics("LRC").fetch_lyrics()
|
||||
except NotFoundError:
|
||||
lyrics = ""
|
||||
print("Start loading")
|
||||
song = load_track(
|
||||
orig_path,
|
||||
img_pth,
|
||||
|
@ -96,7 +91,6 @@ def load_file_meta(track: int, user_id: int) -> str:
|
|||
explicit=track.explicit,
|
||||
track_source=track.track_source,
|
||||
)
|
||||
print("Loaded")
|
||||
if os.path.exists(orig_path):
|
||||
os.remove(orig_path)
|
||||
if os.path.exists(img_pth):
|
||||
|
@ -132,31 +126,31 @@ def update_album_info(album: AlbumModel) -> None:
|
|||
"description": search_album.description,
|
||||
"type": search_album.type,
|
||||
}
|
||||
authors = []
|
||||
if search_album.artists:
|
||||
authors = [
|
||||
Author.objects.get_or_create(name=x.name)[0]
|
||||
for x in search_album.artists
|
||||
]
|
||||
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
|
||||
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:
|
||||
try:
|
||||
authors.append(Author.objects.get(name=x.name))
|
||||
except Author.DoesNotExist:
|
||||
authors.append(Author.objects.create(name=x.name))
|
||||
album.authors.set([x.id for x in authors])
|
||||
album.save()
|
||||
|
||||
|
||||
def update_author_info(author: Author) -> None:
|
||||
client = login()
|
||||
search = client.search(author.name, type_="artist") # type: Search
|
||||
|
||||
print("Loading author info " + author.name)
|
||||
|
||||
if search.artists:
|
||||
search_artist = search.artists.results[0]
|
||||
data = {
|
||||
|
@ -171,7 +165,6 @@ def update_author_info(author: Author) -> None:
|
|||
if not search_artist.cover:
|
||||
author.save()
|
||||
return
|
||||
print("Downloading image")
|
||||
search_artist.cover.download(filename=image_path)
|
||||
with open(image_path, "rb") as f:
|
||||
author.image = File(f, name=image_path.split("/")[-1])
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
set -o errexit
|
||||
set -o nounset
|
||||
|
||||
python manage.py makemigrations
|
||||
python manage.py migrate
|
||||
rm -f './celerybeat.pid'
|
||||
celery -A config.celery_app beat -l INFO
|
||||
|
|
383
poetry.lock
generated
383
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
|
@ -28,12 +28,12 @@ django-crispy-forms = "^2.1"
|
|||
crispy-bootstrap5 = "^0.7"
|
||||
django-redis = "^5.2.0"
|
||||
django-ckeditor = "^6.5.1"
|
||||
django-colorfield = "^0.8.0"
|
||||
django-colorfield = "^0.11.0"
|
||||
djangorestframework = "^3.14.0"
|
||||
django-rest-auth = "^0.9.5"
|
||||
django-cors-headers = "^4.0.0"
|
||||
drf-spectacular = "^0.26.2"
|
||||
werkzeug = {extras = ["watchdog"], version = "^2.3.4"}
|
||||
werkzeug = {extras = ["watchdog"], version = "^3.0.1"}
|
||||
ipdb = "^0.13.13"
|
||||
watchfiles = "^0.18.1"
|
||||
mypy = "^0.991"
|
||||
|
@ -77,7 +77,7 @@ pydub = "^0.25.1"
|
|||
python-mpd2 = "^3.0.5"
|
||||
yandex-music = "^2.1.1"
|
||||
pyjwt = "^2.8.0"
|
||||
rawpy = "^0.18.1"
|
||||
rawpy = "^0.19.0"
|
||||
xvfbwrapper = "^0.2.9"
|
||||
vtk = "^9.2.6"
|
||||
ffmpeg-python = "^0.2.0"
|
||||
|
|
Loading…
Reference in New Issue
Block a user