mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2024-11-27 19:23:45 +03:00
Compare commits
2 Commits
6631d5586c
...
65b9381ba7
Author | SHA1 | Date | |
---|---|---|---|
|
65b9381ba7 | ||
|
9547b76432 |
|
@ -22,17 +22,9 @@ class Meta:
|
||||||
|
|
||||||
|
|
||||||
class ListAlbumSerializer(serializers.ModelSerializer):
|
class ListAlbumSerializer(serializers.ModelSerializer):
|
||||||
authors = serializers.SerializerMethodField(method_name="get_authors")
|
|
||||||
|
|
||||||
@extend_schema_field(ListAuthorSerializer(many=True))
|
|
||||||
def get_authors(self, obj):
|
|
||||||
return ListAuthorSerializer(
|
|
||||||
Author.objects.cache().filter(albums__id=obj.id), many=True
|
|
||||||
).data
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Album
|
model = Album
|
||||||
fields = ["name", "slug", "image_cropped", "authors"]
|
fields = ["name", "slug", "image_cropped"]
|
||||||
|
|
||||||
|
|
||||||
class SongSerializer(serializers.ModelSerializer):
|
class SongSerializer(serializers.ModelSerializer):
|
||||||
|
@ -141,32 +133,10 @@ class Meta:
|
||||||
|
|
||||||
class PlaylistSerializer(SetUserModelSerializer):
|
class PlaylistSerializer(SetUserModelSerializer):
|
||||||
creator = UserPublicInfoSerializer(read_only=True)
|
creator = UserPublicInfoSerializer(read_only=True)
|
||||||
images = serializers.SerializerMethodField(method_name="get_images")
|
|
||||||
|
|
||||||
@extend_schema_field(serializers.ListField(child=serializers.ImageField()))
|
|
||||||
def get_images(self, obj):
|
|
||||||
# Get distinct album images from songs
|
|
||||||
images = (
|
|
||||||
Song.objects.cache()
|
|
||||||
.filter(
|
|
||||||
playlists__id__in=PlaylistSong.objects.cache()
|
|
||||||
.filter(playlist=obj)
|
|
||||||
.values("id")
|
|
||||||
)
|
|
||||||
.values_list("album__image", flat=True)
|
|
||||||
.distinct()[:4]
|
|
||||||
)
|
|
||||||
# Build absolute URI for each image
|
|
||||||
images = [
|
|
||||||
self.context["request"].build_absolute_uri(image)
|
|
||||||
for image in images
|
|
||||||
if image
|
|
||||||
]
|
|
||||||
return images
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Playlist
|
model = Playlist
|
||||||
fields = ["name", "length", "slug", "images", "private", "creator"]
|
fields = ["name", "length", "slug", "private", "creator"]
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
"slug": {"read_only": True},
|
"slug": {"read_only": True},
|
||||||
"creator": {"read_only": True},
|
"creator": {"read_only": True},
|
||||||
|
@ -174,21 +144,13 @@ class Meta:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class FullPlaylistSerializer(PlaylistSerializer):
|
class FullPlaylistSerializer(serializers.ModelSerializer):
|
||||||
songs = serializers.SerializerMethodField(method_name="get_songs")
|
songs = ListSongSerializer(many=True, read_only=True)
|
||||||
creator = UserPublicInfoSerializer(read_only=True)
|
creator = UserPublicInfoSerializer(read_only=True)
|
||||||
|
|
||||||
@extend_schema_field(ListSongSerializer(many=True))
|
|
||||||
def get_songs(self, obj):
|
|
||||||
return ListSongSerializer(
|
|
||||||
Song.objects.cache().filter(playlists__id=obj.id),
|
|
||||||
many=True,
|
|
||||||
context=self.context,
|
|
||||||
).data
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Playlist
|
model = Playlist
|
||||||
fields = ["name", "private", "creator", "images", "songs"]
|
fields = ["name", "private", "creator", "songs"]
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
"slug": {"read_only": True},
|
"slug": {"read_only": True},
|
||||||
"creator": {"read_only": True},
|
"creator": {"read_only": True},
|
||||||
|
@ -196,8 +158,8 @@ class Meta:
|
||||||
|
|
||||||
|
|
||||||
class AddSongToPlaylistSerializer(serializers.ModelSerializer):
|
class AddSongToPlaylistSerializer(serializers.ModelSerializer):
|
||||||
song = serializers.SlugField(write_only=True)
|
song = serializers.SlugField()
|
||||||
playlist = serializers.SlugField(write_only=True)
|
playlist = serializers.SlugField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Playlist
|
model = Playlist
|
||||||
|
|
|
@ -39,70 +39,24 @@ class SongDocument(Document):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
meta = fields.ObjectField(dynamic=True)
|
meta = fields.ObjectField(dynamic=True) # Added meta field here as dynamic object
|
||||||
|
|
||||||
class Index:
|
class Index:
|
||||||
name = "songs"
|
name = "songs"
|
||||||
settings = {
|
settings = {"number_of_shards": 1, "number_of_replicas": 0}
|
||||||
"number_of_shards": 1,
|
# settings = {
|
||||||
"number_of_replicas": 0,
|
# "number_of_shards": 1,
|
||||||
"analysis": {
|
# "number_of_replicas": 0,
|
||||||
"filter": {
|
# "analysis": {
|
||||||
"russian_stop": {
|
# "analyzer": {
|
||||||
"type": "stop",
|
# "russian_icu": {
|
||||||
"stopwords": "_russian_",
|
# "type": "custom",
|
||||||
},
|
# "tokenizer": "icu_tokenizer",
|
||||||
"russian_keywords": {
|
# "filter": ["icu_folding","icu_normalizer"]
|
||||||
"type": "keyword_marker",
|
# }
|
||||||
"keywords": ["пример"],
|
# }
|
||||||
},
|
# }
|
||||||
"russian_stemmer": {
|
# } TODO
|
||||||
"type": "stemmer",
|
|
||||||
"language": "russian",
|
|
||||||
},
|
|
||||||
"autocomplete_filter": {
|
|
||||||
"type": "edge_ngram",
|
|
||||||
"min_gram": 1,
|
|
||||||
"max_gram": 20,
|
|
||||||
},
|
|
||||||
"synonym_filter": {
|
|
||||||
"type": "synonym",
|
|
||||||
"synonyms": [
|
|
||||||
"бит,трек,песня,музыка,песня,мелодия,композиция",
|
|
||||||
"певец,исполнитель,артист,музыкант",
|
|
||||||
"альбом,диск,пластинка,сборник,коллекция",
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"analyzer": {
|
|
||||||
"russian": {
|
|
||||||
"tokenizer": "standard",
|
|
||||||
"filter": [
|
|
||||||
"russian_stop",
|
|
||||||
"russian_keywords",
|
|
||||||
"russian_stemmer",
|
|
||||||
],
|
|
||||||
},
|
|
||||||
"russian_icu": {
|
|
||||||
"tokenizer": "icu_tokenizer",
|
|
||||||
"filter": [
|
|
||||||
"russian_stop",
|
|
||||||
"russian_keywords",
|
|
||||||
"russian_stemmer",
|
|
||||||
],
|
|
||||||
},
|
|
||||||
"autocomplete": {
|
|
||||||
"type": "custom",
|
|
||||||
"tokenizer": "standard",
|
|
||||||
"filter": [
|
|
||||||
"lowercase",
|
|
||||||
"autocomplete_filter",
|
|
||||||
"synonym_filter",
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
class Django:
|
class Django:
|
||||||
model = Song
|
model = Song
|
||||||
|
|
|
@ -72,16 +72,6 @@ def load_track(
|
||||||
name = search_info["title"]
|
name = search_info["title"]
|
||||||
elif not name:
|
elif not name:
|
||||||
name = process_track_name(" ".join(p_name.strip().split("-")))
|
name = process_track_name(" ".join(p_name.strip().split("-")))
|
||||||
clear_name = [
|
|
||||||
"(Official HD Video)",
|
|
||||||
"(Official Music Video)",
|
|
||||||
"(Official Video)",
|
|
||||||
"Official Video",
|
|
||||||
"Official Music Video",
|
|
||||||
"Official HD Video",
|
|
||||||
]
|
|
||||||
for c in clear_name:
|
|
||||||
name = name.replace(c, "")
|
|
||||||
|
|
||||||
if not name:
|
if not name:
|
||||||
name = orig_name
|
name = orig_name
|
||||||
|
|
|
@ -360,7 +360,6 @@ def update_author_info(author: Author) -> None:
|
||||||
|
|
||||||
|
|
||||||
def search_all_platforms(track_name: str) -> dict:
|
def search_all_platforms(track_name: str) -> dict:
|
||||||
print(track_name)
|
|
||||||
session = spotipy.Spotify(
|
session = spotipy.Spotify(
|
||||||
auth_manager=spotipy.SpotifyClientCredentials(
|
auth_manager=spotipy.SpotifyClientCredentials(
|
||||||
client_id=settings.MUSIC_SPOTIFY_ID,
|
client_id=settings.MUSIC_SPOTIFY_ID,
|
||||||
|
|
|
@ -13,9 +13,9 @@ def search_song(query):
|
||||||
ES_Q(
|
ES_Q(
|
||||||
"multi_match",
|
"multi_match",
|
||||||
query=query,
|
query=query,
|
||||||
fields=["name^5", "authors.name^3", "album.name^3"],
|
fields=["name^3", "authors.name^2", "album.name"],
|
||||||
fuzziness="AUTO",
|
fuzziness="AUTO",
|
||||||
),
|
), # Change here
|
||||||
ES_Q("wildcard", name__raw=f"*{query.lower()}*"),
|
ES_Q("wildcard", name__raw=f"*{query.lower()}*"),
|
||||||
ES_Q(
|
ES_Q(
|
||||||
"nested",
|
"nested",
|
||||||
|
@ -27,7 +27,6 @@ def search_song(query):
|
||||||
path="album",
|
path="album",
|
||||||
query=ES_Q("wildcard", album__name__raw=f"*{query.lower()}*"),
|
query=ES_Q("wildcard", album__name__raw=f"*{query.lower()}*"),
|
||||||
),
|
),
|
||||||
ES_Q("wildcard", meta__raw=f"*{query.lower()}*"),
|
|
||||||
],
|
],
|
||||||
minimum_should_match=1,
|
minimum_should_match=1,
|
||||||
)
|
)
|
||||||
|
|
|
@ -157,25 +157,22 @@ def download_from_youtube_link(link: str, user_id: int) -> Song:
|
||||||
print(f"[processing] loading {title}")
|
print(f"[processing] loading {title}")
|
||||||
|
|
||||||
info = search_all_platforms(title)
|
info = search_all_platforms(title)
|
||||||
if "album_image" in info and info["album_image"]:
|
if not info["album_image"].startswith("/"):
|
||||||
if not info["album_image"].startswith("/"):
|
r = requests.get(info["album_image"])
|
||||||
r = requests.get(info["album_image"])
|
img_pth = str(
|
||||||
img_pth = str(
|
settings.MEDIA_ROOT
|
||||||
settings.MEDIA_ROOT
|
+ f"/{info['album_image'].split('/')[-1]}_{str(randint(100, 999))}"
|
||||||
+ f"/{info['album_image'].split('/')[-1]}_{str(randint(100, 999))}"
|
)
|
||||||
)
|
with open(img_pth, "wb") as f:
|
||||||
with open(img_pth, "wb") as f:
|
f.write(r.content)
|
||||||
f.write(r.content)
|
|
||||||
|
|
||||||
im = Image.open(img_pth)
|
im = Image.open(img_pth)
|
||||||
im.save(str(f"{img_pth}.png"))
|
im.save(str(f"{img_pth}.png"))
|
||||||
|
|
||||||
os.remove(img_pth)
|
os.remove(img_pth)
|
||||||
img_pth = f"{img_pth}.png"
|
img_pth = f"{img_pth}.png"
|
||||||
else:
|
|
||||||
img_pth = info["album_image"]
|
|
||||||
else:
|
else:
|
||||||
img_pth = None
|
img_pth = info["album_image"]
|
||||||
if "genre" in info:
|
if "genre" in info:
|
||||||
song = load_track(
|
song = load_track(
|
||||||
path,
|
path,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from urllib.parse import parse_qs, urlparse
|
|
||||||
|
|
||||||
import pylast
|
import pylast
|
||||||
import spotipy
|
import spotipy
|
||||||
|
@ -55,19 +54,9 @@ def list_tracks(url, user_id):
|
||||||
|
|
||||||
elif "playlist" in url or "&list=" in url:
|
elif "playlist" in url or "&list=" in url:
|
||||||
ytmusic = ytmusicapi.YTMusic()
|
ytmusic = ytmusicapi.YTMusic()
|
||||||
|
playlist_id = url.split("=")[-1]
|
||||||
|
playlist_songs = ytmusic.get_playlist(playlist_id)["tracks"]["results"]
|
||||||
|
|
||||||
# Parse the URL and the query string
|
|
||||||
parsed_url = urlparse(url)
|
|
||||||
parsed_qs = parse_qs(parsed_url.query)
|
|
||||||
|
|
||||||
# Get the playlist ID from the parsed query string
|
|
||||||
playlist_id = parsed_qs.get("list", [None])[0]
|
|
||||||
|
|
||||||
if playlist_id:
|
|
||||||
playlist_songs = ytmusic.get_playlist(playlist_id)["tracks"]
|
|
||||||
|
|
||||||
else:
|
|
||||||
raise ValueError("No playlist ID found in the URL.")
|
|
||||||
for song in playlist_songs:
|
for song in playlist_songs:
|
||||||
process_yb.apply_async(
|
process_yb.apply_async(
|
||||||
kwargs={
|
kwargs={
|
||||||
|
|
|
@ -5,4 +5,4 @@ set -o nounset
|
||||||
|
|
||||||
/install_preview_dependencies
|
/install_preview_dependencies
|
||||||
|
|
||||||
celery -A config.celery_app worker --autoscale 20 -l INFO
|
celery -A config.celery_app worker --loglevel=info -c 5
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
FROM elasticsearch:8.11.1
|
|
||||||
|
|
||||||
# Install the ICU plugin
|
|
||||||
RUN bin/elasticsearch-plugin install https://akarpov.ru/media/analysis-icu-8.11.1.zip
|
|
|
@ -101,9 +101,7 @@ services:
|
||||||
command: /start-flower
|
command: /start-flower
|
||||||
|
|
||||||
elasticsearch:
|
elasticsearch:
|
||||||
build:
|
image: elasticsearch:8.11.1
|
||||||
context: .
|
|
||||||
dockerfile: ./compose/production/elasticsearch/Dockerfile
|
|
||||||
ports:
|
ports:
|
||||||
- "9200:9200"
|
- "9200:9200"
|
||||||
- "9300:9300"
|
- "9300:9300"
|
||||||
|
|
2540
poetry.lock
generated
2540
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user