Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
api
Manage
Activity
Members
Labels
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
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
funkwhale
api
Commits
c6de0539
Commit
c6de0539
authored
8 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Should now download org vorbis files
parent
e6058a32
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
funkwhale_api/downloader/downloader.py
+6
-6
6 additions, 6 deletions
funkwhale_api/downloader/downloader.py
funkwhale_api/downloader/tests/test_downloader.py
+5
-2
5 additions, 2 deletions
funkwhale_api/downloader/tests/test_downloader.py
with
11 additions
and
8 deletions
funkwhale_api/downloader/downloader.py
+
6
−
6
View file @
c6de0539
...
@@ -3,26 +3,26 @@ import requests
...
@@ -3,26 +3,26 @@ import requests
import
json
import
json
from
urllib.parse
import
quote_plus
from
urllib.parse
import
quote_plus
import
youtube_dl
import
youtube_dl
from
django.conf
import
settings
import
glob
def
download
(
def
download
(
url
,
url
,
target_directory
,
target_directory
=
settings
.
MEDIA_ROOT
,
name
=
"
%(id)s
"
,
name
=
"
%(id)s
.%(ext)s
"
,
extension
=
'
vorbis
'
,
extension
=
'
vorbis
'
,
bitrate
=
192
):
bitrate
=
192
):
target_path
=
os
.
path
.
join
(
target_directory
,
'
{}.ogg
'
.
format
(
name
)
)
target_path
=
os
.
path
.
join
(
target_directory
,
name
)
ydl_opts
=
{
ydl_opts
=
{
'
format
'
:
'
bestaudio/best
'
,
'
quiet
'
:
True
,
'
quiet
'
:
True
,
'
outtmpl
'
:
target_path
,
'
outtmpl
'
:
target_path
,
'
postprocessors
'
:
[{
'
postprocessors
'
:
[{
'
key
'
:
'
FFmpegExtractAudio
'
,
'
key
'
:
'
FFmpegExtractAudio
'
,
'
preferredcodec
'
:
extension
,
'
preferredcodec
'
:
extension
,
'
preferredquality
'
:
str
(
bitrate
),
}],
}],
}
}
_downloader
=
youtube_dl
.
YoutubeDL
(
ydl_opts
)
_downloader
=
youtube_dl
.
YoutubeDL
(
ydl_opts
)
info
=
_downloader
.
extract_info
(
url
)
info
=
_downloader
.
extract_info
(
url
)
info
[
'
audio_file_path
'
]
=
target_path
%
{
'
id
'
:
info
[
'
id
'
]}
info
[
'
audio_file_path
'
]
=
target_path
.
format
(
**
info
)
return
info
return
info
This diff is collapsed.
Click to expand it.
funkwhale_api/downloader/tests/test_downloader.py
+
5
−
2
View file @
c6de0539
...
@@ -3,8 +3,11 @@ from test_plus.test import TestCase
...
@@ -3,8 +3,11 @@ from test_plus.test import TestCase
from
..
import
downloader
from
..
import
downloader
from
funkwhale_api.utils.tests
import
TMPDirTestCaseMixin
from
funkwhale_api.utils.tests
import
TMPDirTestCaseMixin
class
TestDownloader
(
TMPDirTestCaseMixin
,
TestCase
):
class
TestDownloader
(
TMPDirTestCaseMixin
,
TestCase
):
def
test_can_download_audio_from_youtube_url
(
self
):
def
test_can_download_audio_from_youtube_url
_to_vorbis
(
self
):
data
=
downloader
.
download
(
'
https://www.youtube.com/watch?v=tPEE9ZwTmy0
'
,
target_directory
=
self
.
download_dir
)
data
=
downloader
.
download
(
'
https://www.youtube.com/watch?v=tPEE9ZwTmy0
'
,
target_directory
=
self
.
download_dir
)
self
.
assertTrue
(
os
.
path
.
exists
(
data
[
'
audio_file_path
'
]))
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
download_dir
,
'
tPEE9ZwTmy0.ogg
'
))
)
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