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 import Album, Artist, Track
logger = logging.getLogger(__name__)
class EndpointError(Exception):
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 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):
class SimilarRadio(RelatedObjectRadio):
model = Track
......@@ -254,6 +257,27 @@ class SimilarRadio(RelatedObjectRadio):
return random.choice([c[0] for c in next_candidates])
class SimilarRadio(RelatedObjectRadio):
model = Track
def get_regex(self):
related_mbid = str(self.session.related_object.mbid)
if not related_mbid:"No mbid found for the related object.")
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))
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