Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Erin
mopidy
Commits
93a52134
Verified
Commit
93a52134
authored
Jan 27, 2019
by
Eliot Berriot
Browse files
Fixed bitrate / duration error due to API change in Funkwhale
parent
2924bcd9
Changes
3
Hide whitespace changes
Inline
Side-by-side
mopidy_funkwhale/library.py
View file @
93a52134
...
...
@@ -303,6 +303,10 @@ def convert_to_album(payload, uri_prefix="funkwhale:albums"):
def
convert_to_track
(
payload
,
uri_prefix
=
"funkwhale:tracks"
):
artist
=
convert_to_artist
(
payload
[
"artist"
])
album
=
convert_to_album
(
payload
[
"album"
])
try
:
upload
=
payload
[
"uploads"
][
0
]
except
(
KeyError
,
IndexError
):
upload
=
{}
return
models
.
Track
(
uri
=
uri_prefix
+
":%s"
%
payload
[
"id"
],
name
=
payload
[
"title"
],
...
...
@@ -310,8 +314,8 @@ def convert_to_track(payload, uri_prefix="funkwhale:tracks"):
artists
=
[
artist
],
album
=
album
,
date
=
payload
[
"album"
][
"release_date"
],
bitrate
=
(
p
ay
load
[
"bitrate"
]
or
0
)
/
1000
,
length
=
(
p
ay
load
[
"duration"
]
or
0
)
*
1000
,
bitrate
=
(
u
pload
.
get
(
"bitrate"
)
or
0
)
/
1000
,
length
=
(
u
pload
.
get
(
"duration"
)
or
0
)
*
1000
,
track_no
=
payload
[
"position"
],
)
...
...
tests/factories.py
View file @
93a52134
...
...
@@ -34,6 +34,14 @@ class AlbumJSONFactory(factory.Factory):
model
=
dict
class
UploadJSONFactory
(
factory
.
Factory
):
uuid
=
factory
.
Faker
(
"uuid4"
)
bitrate
=
factory
.
Iterator
([
i
*
1000
for
i
in
(
128
,
256
,
360
)])
class
Meta
:
model
=
dict
class
TrackJSONFactory
(
factory
.
Factory
):
id
=
factory
.
Sequence
(
int
)
mbid
=
factory
.
Faker
(
"uuid4"
)
...
...
@@ -41,9 +49,9 @@ class TrackJSONFactory(factory.Factory):
position
=
factory
.
Faker
(
"pyint"
)
duration
=
factory
.
Faker
(
"pyint"
)
creation_date
=
factory
.
Faker
(
"date"
)
bitrate
=
factory
.
Iterator
([
i
*
1000
for
i
in
(
128
,
256
,
360
)])
artist
=
factory
.
SubFactory
(
ArtistJSONFactory
)
album
=
factory
.
SubFactory
(
AlbumJSONFactory
)
uploads
=
factory
.
LazyAttribute
(
lambda
o
:
[
UploadJSONFactory
()])
class
Meta
:
model
=
dict
...
...
tests/test_library.py
View file @
93a52134
...
...
@@ -47,15 +47,13 @@ def test_convert_album_to_model():
assert
result
.
images
==
frozenset
([
payload
[
"cover"
][
"original"
]])
def
test_convert_
album
_to_model
():
def
test_convert_
track
_to_model
():
payload
=
{
"id"
:
2
,
"title"
:
"Test track"
,
"mbid"
:
str
(
uuid
.
uuid4
()),
"creation_date"
:
"2017-01-01"
,
"position"
:
12
,
"bitrate"
:
128000
,
"duration"
:
120
,
"artist"
:
{
"id"
:
43
,
"mbid"
:
str
(
uuid
.
uuid4
()),
"name"
:
"Test artist 2"
},
"album"
:
{
"id"
:
3
,
...
...
@@ -68,6 +66,7 @@ def test_convert_album_to_model():
"original"
:
"/media/albums/covers/2018/10/03/b4e94b07e-da27-4df4-ae2a-d924a9448544.jpg"
},
},
"uploads"
:
[{
"bitrate"
:
128000
,
"duration"
:
120
}],
}
result
=
mopidy_funkwhale
.
library
.
convert_to_track
(
payload
)
...
...
@@ -77,8 +76,8 @@ def test_convert_album_to_model():
assert
result
.
uri
==
"funkwhale:tracks:%s"
%
(
payload
[
"id"
],)
assert
result
.
name
==
payload
[
"title"
]
assert
result
.
date
==
payload
[
"album"
][
"release_date"
]
assert
result
.
length
==
payload
[
"duration"
]
*
1000
assert
result
.
bitrate
==
payload
[
"bitrate"
]
/
1000
assert
result
.
length
==
payload
[
"
uploads"
][
0
][
"
duration"
]
*
1000
assert
result
.
bitrate
==
payload
[
"
uploads"
][
0
][
"
bitrate"
]
/
1000
assert
result
.
album
==
mopidy_funkwhale
.
library
.
convert_to_album
(
payload
[
"album"
])
assert
result
.
artists
==
frozenset
(
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment