Commit fa25833d authored by petitminion's avatar petitminion
Browse files

Smart palylist backend implementation of acousticbrainz api

parent ef18e5ea
Pipeline #16865 failed with stages
in 1 minute
import logging
import logging.config
import re
from datetime import datetime
......@@ -12,8 +12,9 @@ from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
from funkwhale_api.music.models import Album, Artist, Track
logger = logging.getLogger(__name__)
logger = logging.getLogger("DLKJSDLKJSLKDJSLKDJLKSJDLKSJDLKSJDLKJSD")
class EndpointError(Exception):
pass
def clean_namespace_xspf(xspf_file):
"""
......
import logging
import random
from django.core.exceptions import ValidationError
......@@ -11,9 +12,11 @@ from funkwhale_api.moderation import filters as moderation_filters
from funkwhale_api.music.models import Artist, Library, Track, Upload
from funkwhale_api.tags.models import Tag
from . import filters, models
from . import filters, models, utils
from .registries import registry
logger = logging.getLogger(__name__)
class SimpleRadio(object):
related_object_field = None
......@@ -201,7 +204,7 @@ class NextNotFound(Exception):
pass
@registry.register(name="similar")
@registry.register(name="similar_history")
class SimilarRadio(RelatedObjectRadio):
model = Track
......@@ -254,6 +257,27 @@ class SimilarRadio(RelatedObjectRadio):
return random.choice([c[0] for c in next_candidates])
@registry.register(name="similar_mbid")
class SimilarRadio(RelatedObjectRadio):
model = Track
def get_regex(self):
related_mbid = str(self.session.related_object.mbid)
if not related_mbid:
logger.info(f"No mbid found for the related object.")
pass
mbids_regex = str()
mbids = utils.get_similar_tracks_mbids_from_mbid(related_mbid, "rosamerica")
for mbid in mbids:
mbids_regex = str(mbids_regex) + str(mbid + "|")
return mbids_regex
def filter_queryset(self, queryset):
queryset = super().filter_queryset(queryset)
mbids_regex = self.get_regex()
return queryset.filter(mbid__regex=r'({mbids_regex})'.format(mbids_regex=mbids_regex))
@registry.register(name="artist")
class ArtistRadio(RelatedObjectRadio):
model = Artist
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment