Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
petitminion
funkwhale
Commits
06f507a1
Commit
06f507a1
authored
3 years ago
by
petitminion
Committed by
petitminion
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Adding acousticbrainz support
parent
fadbb9a7
No related branches found
No related tags found
No related merge requests found
Pipeline
#16881
failed
3 years ago
Stage: review
Stage: lint
Stage: test
Stage: deps
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/funkwhale_api/radios/radios.py
+26
-2
26 additions, 2 deletions
api/funkwhale_api/radios/radios.py
api/funkwhale_api/radios/utils.py
+35
-0
35 additions, 0 deletions
api/funkwhale_api/radios/utils.py
front/src/components/audio/PlayButton.vue
+1
-1
1 addition, 1 deletion
front/src/components/audio/PlayButton.vue
with
62 additions
and
3 deletions
api/funkwhale_api/radios/radios.py
+
26
−
2
View file @
06f507a1
import
logging
import
random
import
random
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
...
@@ -11,9 +12,11 @@ from funkwhale_api.moderation import filters as moderation_filters
...
@@ -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.music.models
import
Artist
,
Library
,
Track
,
Upload
from
funkwhale_api.tags.models
import
Tag
from
funkwhale_api.tags.models
import
Tag
from
.
import
filters
,
models
from
.
import
filters
,
models
,
utils
from
.registries
import
registry
from
.registries
import
registry
logger
=
logging
.
getLogger
(
__name__
)
class
SimpleRadio
(
object
):
class
SimpleRadio
(
object
):
related_object_field
=
None
related_object_field
=
None
...
@@ -201,7 +204,7 @@ class NextNotFound(Exception):
...
@@ -201,7 +204,7 @@ class NextNotFound(Exception):
pass
pass
@registry.register
(
name
=
"
similar
"
)
@registry.register
(
name
=
"
similar
_history
"
)
class
SimilarRadio
(
RelatedObjectRadio
):
class
SimilarRadio
(
RelatedObjectRadio
):
model
=
Track
model
=
Track
...
@@ -254,6 +257,27 @@ class SimilarRadio(RelatedObjectRadio):
...
@@ -254,6 +257,27 @@ class SimilarRadio(RelatedObjectRadio):
return
random
.
choice
([
c
[
0
]
for
c
in
next_candidates
])
return
random
.
choice
([
c
[
0
]
for
c
in
next_candidates
])
@registry.register
(
name
=
"
similar_mbid
"
)
class
SimilarAcousticRadio
(
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
"
)
@registry.register
(
name
=
"
artist
"
)
class
ArtistRadio
(
RelatedObjectRadio
):
class
ArtistRadio
(
RelatedObjectRadio
):
model
=
Artist
model
=
Artist
...
...
This diff is collapsed.
Click to expand it.
api/funkwhale_api/radios/utils.py
0 → 100644
+
35
−
0
View file @
06f507a1
import
json
import
logging
import
requests
logger
=
logging
.
getLogger
(
__name__
)
VALID_METRICS
=
[
'
mfccs
'
,
'
mfccsw
'
,
'
gfccs
'
,
'
gfccsw
'
,
'
key
'
,
'
bpm
'
,
'
onsetrate
'
,
'
moods
'
,
'
instruments
'
,
'
dortmund
'
,
'
rosamerica
'
,
'
tzanetakis
'
]
class
EndpointError
(
Exception
):
pass
def
get_similar_tracks_mbids_from_mbid
(
mbid
,
annoy_similarity
):
if
annoy_similarity
not
in
VALID_METRICS
:
raise
AttributeError
(
"
Metric %s is not valid. Must be one of :
"
+
print
(
VALID_METRICS
))
headers
=
{
'
Content-Type
'
:
'
application/json
'
}
endpoint
=
"
acousticbrainz.org/api/v1/similarity
"
similar_tracks_mbids
=
[]
similar_tracks
=
requests
.
get
(
'
https://{endpoint}/{annoy_similarity}/?recording_ids={mbid}&remove_dups&n_neighbours=1000
'
.
format
(
endpoint
=
endpoint
,
annoy_similarity
=
annoy_similarity
,
mbid
=
mbid
),
headers
=
headers
)
if
similar_tracks
.
status_code
!=
200
:
logger
.
warning
(
"
Error while querying {endpoint!r} : {similar_tracks.content!r}
"
)
raise
EndpointError
j
=
json
.
loads
(
similar_tracks
.
content
)
for
tracks
in
j
[
'
{mbid}
'
.
format
(
mbid
=
mbid
)][
'
0
'
]:
similar_tracks_mbids
.
append
(
tracks
[
'
recording_mbid
'
])
return
similar_tracks_mbids
This diff is collapsed.
Click to expand it.
front/src/components/audio/PlayButton.vue
+
1
−
1
View file @
06f507a1
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
<button
class=
"item basic"
ref=
"playNow"
data-ref=
"playNow"
:disabled=
"!playable"
@
click.stop.prevent=
"addNext(true)"
:title=
"labels.playNow"
>
<button
class=
"item basic"
ref=
"playNow"
data-ref=
"playNow"
:disabled=
"!playable"
@
click.stop.prevent=
"addNext(true)"
:title=
"labels.playNow"
>
<i
class=
"play icon"
></i>
{{ labels.playNow }}
<i
class=
"play icon"
></i>
{{ labels.playNow }}
</button>
</button>
<button
v-if=
"track"
class=
"item basic"
:disabled=
"!playable"
@
click.stop.prevent=
"$store.dispatch('radios/start', {type: 'similar', objectId: track.id})"
:title=
"labels.startRadio"
>
<button
v-if=
"track"
class=
"item basic"
:disabled=
"!playable"
@
click.stop.prevent=
"$store.dispatch('radios/start', {type: 'similar
_history
', objectId: track.id})"
:title=
"labels.startRadio"
>
<i
class=
"feed icon"
></i><translate
translate-context=
"*/Queue/Button.Label/Short, Verb"
>
Play radio
</translate>
<i
class=
"feed icon"
></i><translate
translate-context=
"*/Queue/Button.Label/Short, Verb"
>
Play radio
</translate>
</button>
</button>
<button
v-if=
"track"
class=
"item basic"
:disabled=
"!playable"
@
click.stop=
"$store.commit('playlists/chooseTrack', track)"
>
<button
v-if=
"track"
class=
"item basic"
:disabled=
"!playable"
@
click.stop=
"$store.commit('playlists/chooseTrack', track)"
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment