Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
Mélanie Chauvel
funkwhale
Commits
b1e8d4ca
Verified
Commit
b1e8d4ca
authored
5 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Fix #936: Support byYear filtering in Subsonic API (#936)
parent
52a70445
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/funkwhale_api/subsonic/views.py
+30
-0
30 additions, 0 deletions
api/funkwhale_api/subsonic/views.py
api/tests/subsonic/test_views.py
+29
-0
29 additions, 0 deletions
api/tests/subsonic/test_views.py
changes/changelog.d/936.enhancement
+1
-0
1 addition, 0 deletions
changes/changelog.d/936.enhancement
with
60 additions
and
0 deletions
api/funkwhale_api/subsonic/views.py
+
30
−
0
View file @
b1e8d4ca
"""
Documentation of Subsonic API can be found at http://www.subsonic.org/pages/api.jsp
"""
import
datetime
import
functools
...
...
@@ -427,7 +430,34 @@ class SubsonicViewSet(viewsets.GenericViewSet):
Q
(
tagged_items__tag__name
=
genre
)
|
Q
(
artist__tagged_items__tag__name
=
genre
)
)
elif
type
==
"
byYear
"
:
try
:
boundaries
=
[
int
(
data
.
get
(
"
fromYear
"
,
0
)),
int
(
data
.
get
(
"
toYear
"
,
99999999
)),
]
except
(
TypeError
,
ValueError
):
return
response
.
Response
(
{
"
error
"
:
{
"
code
"
:
10
,
"
message
"
:
"
Invalid fromYear or toYear parameter
"
,
}
}
)
# because, yeah, the specification explicitly state that fromYear can be greater
# than toYear, to indicate reverse ordering…
# http://www.subsonic.org/pages/api.jsp#getAlbumList2
from_year
=
min
(
boundaries
)
to_year
=
max
(
boundaries
)
queryset
=
queryset
.
filter
(
release_date__year__gte
=
from_year
,
release_date__year__lte
=
to_year
)
if
boundaries
[
0
]
<=
boundaries
[
1
]:
queryset
=
queryset
.
order_by
(
"
release_date
"
)
else
:
queryset
=
queryset
.
order_by
(
"
-release_date
"
)
try
:
offset
=
int
(
data
[
"
offset
"
])
except
(
TypeError
,
KeyError
,
ValueError
):
...
...
This diff is collapsed.
Click to expand it.
api/tests/subsonic/test_views.py
+
29
−
0
View file @
b1e8d4ca
...
...
@@ -469,6 +469,35 @@ def test_get_album_list2_by_genre(f, db, logged_in_api_client, factories):
}
@pytest.mark.parametrize
(
"
params, expected
"
,
[
({
"
type
"
:
"
byYear
"
,
"
fromYear
"
:
1902
,
"
toYear
"
:
1903
},
[
2
,
3
]),
# Because why not, it's supported in Subsonic API…
# http://www.subsonic.org/pages/api.jsp#getAlbumList2
({
"
type
"
:
"
byYear
"
,
"
fromYear
"
:
1903
,
"
toYear
"
:
1902
},
[
3
,
2
]),
],
)
def
test_get_album_list2_by_year
(
params
,
expected
,
db
,
logged_in_api_client
,
factories
):
albums
=
[
factories
[
"
music.Album
"
](
playable
=
True
,
release_date
=
datetime
.
date
(
1900
+
i
,
1
,
1
)
)
for
i
in
range
(
5
)
]
url
=
reverse
(
"
api:subsonic-get_album_list2
"
)
base_params
=
{
"
f
"
:
"
json
"
}
base_params
.
update
(
params
)
response
=
logged_in_api_client
.
get
(
url
,
base_params
)
assert
response
.
status_code
==
200
assert
response
.
data
==
{
"
albumList2
"
:
{
"
album
"
:
serializers
.
get_album_list2_data
([
albums
[
i
]
for
i
in
expected
])
}
}
@pytest.mark.parametrize
(
"
f
"
,
[
"
json
"
])
@pytest.mark.parametrize
(
"
tags_field
"
,
...
...
This diff is collapsed.
Click to expand it.
changes/changelog.d/936.enhancement
0 → 100644
+
1
−
0
View file @
b1e8d4ca
Support byYear filtering in Subsonic API (#936)
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