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
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
wxcafé
funkwhale
Commits
1cfdf31e
Verified
Commit
1cfdf31e
authored
7 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Can now stream transcoded version of audio tracks \o/
parent
ddea5f18
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/funkwhale_api/music/forms.py
+23
-0
23 additions, 0 deletions
api/funkwhale_api/music/forms.py
api/funkwhale_api/music/views.py
+40
-0
40 additions, 0 deletions
api/funkwhale_api/music/views.py
with
63 additions
and
0 deletions
api/funkwhale_api/music/forms.py
0 → 100644
+
23
−
0
View file @
1cfdf31e
from
django
import
forms
from
.
import
models
class
TranscodeForm
(
forms
.
Form
):
FORMAT_CHOICES
=
[
(
'
ogg
'
,
'
ogg
'
),
(
'
mp3
'
,
'
mp3
'
),
]
to
=
forms
.
ChoiceField
(
choices
=
FORMAT_CHOICES
)
BITRATE_CHOICES
=
[
(
64
,
'
64
'
),
(
128
,
'
128
'
),
(
256
,
'
256
'
),
]
bitrate
=
forms
.
ChoiceField
(
choices
=
BITRATE_CHOICES
,
required
=
False
)
track_file
=
forms
.
ModelChoiceField
(
queryset
=
models
.
TrackFile
.
objects
.
all
()
)
This diff is collapsed.
Click to expand it.
api/funkwhale_api/music/views.py
+
40
−
0
View file @
1cfdf31e
import
ffmpeg
import
os
import
json
import
subprocess
import
unicodedata
import
urllib
from
django.urls
import
reverse
from
django.db
import
models
,
transaction
from
django.db.models.functions
import
Length
from
django.conf
import
settings
from
django.http
import
StreamingHttpResponse
from
rest_framework
import
viewsets
,
views
,
mixins
from
rest_framework.decorators
import
detail_route
,
list_route
from
rest_framework.response
import
Response
...
...
@@ -19,6 +24,7 @@ from funkwhale_api.common.permissions import (
ConditionalAuthentication
,
HasModelPermission
)
from
taggit.models
import
Tag
from
.
import
forms
from
.
import
models
from
.
import
serializers
from
.
import
importers
...
...
@@ -183,6 +189,40 @@ class TrackFileViewSet(viewsets.ReadOnlyModelViewSet):
f
.
audio_file
.
url
)
return
response
@list_route
(
methods
=
[
'
get
'
])
def
viewable
(
self
,
request
,
*
args
,
**
kwargs
):
return
Response
({},
status
=
200
)
@list_route
(
methods
=
[
'
get
'
])
def
transcode
(
self
,
request
,
*
args
,
**
kwargs
):
form
=
forms
.
TranscodeForm
(
request
.
GET
)
if
not
form
.
is_valid
():
return
Response
(
form
.
errors
,
status
=
400
)
f
=
form
.
cleaned_data
[
'
track_file
'
]
output_kwargs
=
{
'
format
'
:
form
.
cleaned_data
[
'
to
'
]
}
args
=
(
ffmpeg
.
input
(
f
.
audio_file
.
path
)
.
output
(
'
pipe:
'
,
**
output_kwargs
)
.
get_args
()
)
# we use a generator here so the view return immediatly and send
# file chunk to the browser, instead of blocking a few seconds
def
_transcode
():
p
=
subprocess
.
Popen
(
[
'
ffmpeg
'
]
+
args
,
stdout
=
subprocess
.
PIPE
)
for
line
in
p
.
stdout
:
yield
line
response
=
StreamingHttpResponse
(
_transcode
(),
status
=
200
,
content_type
=
form
.
cleaned_data
[
'
to
'
])
return
response
class
TagViewSet
(
viewsets
.
ReadOnlyModelViewSet
):
queryset
=
Tag
.
objects
.
all
().
order_by
(
'
name
'
)
...
...
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