Skip to content

Commit

Permalink
Expose 'source_address' and 'verbose' options for yt-dlp (#796)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyCA authored Sep 25, 2023
1 parent 8d8dbb6 commit f7e92f4
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ Here is a list of all the environment variables you can use to further customize
| `UPLOAD_FILE_SIZE_LIMIT` | Maximum allowed upload file size (in megabytes). Default is `100`. |
| `YOUTUBE_API_KEY` | YouTube Data API key. |
| `YOUTUBE_LENGTH_LIMIT` | Maximum allowed YouTube track length (in minutes). Default is `30`. |
| `YOUTUBEDL_SOURCE_ADDR` | Client-side IP address for `yt-dlp` to bind to. If you are facing 403 Forbidden errors, try setting this to `0.0.0.0` to force all connections through IPv4. |
| `YOUTUBEDL_VERBOSE` | Set to `1` to enable verbose logging for `yt-dlp`. |
## Using cloud storage (Azure Storage, AWS S3, etc.)
Expand Down
12 changes: 9 additions & 3 deletions api/youtubedl.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def get_file_ext(url):
# Always use the best audio quality available
'format': 'bestaudio/best',
'forcefilename': True,
'noplaylist': True
'noplaylist': True,
'source_address': settings.YOUTUBEDL_SOURCE_ADDR,
'verbose': settings.YOUTUBEDL_VERBOSE
}
# Try up to 3 times as youtubedl tends to be flakey
for _ in range(settings.YOUTUBE_MAX_RETRIES):
Expand All @@ -45,7 +47,9 @@ def get_meta_info(url):
opts = {
'format': 'bestaudio/best',
'forcefilename': True,
'noplaylist': True
'noplaylist': True,
'source_address': settings.YOUTUBEDL_SOURCE_ADDR,
'verbose': settings.YOUTUBEDL_VERBOSE
}
# Try up to 3 times, as youtubedl tends to be flakey
for _ in range(settings.YOUTUBE_MAX_RETRIES):
Expand Down Expand Up @@ -103,7 +107,9 @@ def download_audio(url, dir_path):
'forcefilename': True,
'outtmpl': str(dir_path),
'cachedir': False,
'noplaylist': True
'noplaylist': True,
'source_address': settings.YOUTUBEDL_SOURCE_ADDR,
'verbose': settings.YOUTUBEDL_VERBOSE
}

# Retry mechanism is handled on Celery's side
Expand Down
2 changes: 2 additions & 0 deletions django_react/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
UPLOAD_FILE_SIZE_LIMIT = int(os.getenv('UPLOAD_FILE_SIZE_LIMIT', 100)) * 1024 * 1024
YOUTUBE_LENGTH_LIMIT = int(os.getenv('YOUTUBE_LENGTH_LIMIT', 30)) * 60
YOUTUBE_MAX_RETRIES = 3
YOUTUBEDL_SOURCE_ADDR = os.getenv('YOUTUBEDL_SOURCE_ADDR', None)
YOUTUBEDL_VERBOSE = bool(int(os.getenv('YOUTUBEDL_VERBOSE', '0')))

# Application definition
INSTALLED_APPS = [
Expand Down
2 changes: 2 additions & 0 deletions django_react/settings_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
UPLOAD_FILE_SIZE_LIMIT = int(os.getenv('UPLOAD_FILE_SIZE_LIMIT', 100)) * 1024 * 1024
YOUTUBE_LENGTH_LIMIT = int(os.getenv('YOUTUBE_LENGTH_LIMIT', 30)) * 60
YOUTUBE_MAX_RETRIES = 3
YOUTUBEDL_SOURCE_ADDR = os.getenv('YOUTUBEDL_SOURCE_ADDR', None)
YOUTUBEDL_VERBOSE = bool(int(os.getenv('YOUTUBEDL_VERBOSE', '0')))

# Application definition
INSTALLED_APPS = [
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ x-celery-env: &celery-env
- PYTORCH_NO_CUDA_MEMORY_CACHING
- DEMUCS_SEGMENT_SIZE
- YOUTUBE_LENGTH_LIMIT
- YOUTUBEDL_SOURCE_ADDR
- YOUTUBEDL_VERBOSE
services:
redis:
image: redis:6.0-buster
Expand Down Expand Up @@ -77,6 +79,8 @@ services:
- YOUTUBE_API_KEY
- UPLOAD_FILE_SIZE_LIMIT
- YOUTUBE_LENGTH_LIMIT
- YOUTUBEDL_SOURCE_ADDR
- YOUTUBEDL_VERBOSE
depends_on:
- redis
- frontend
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ x-celery-env: &celery-env
- D3NET_OPENVINO
- D3NET_OPENVINO_THREADS
- YOUTUBE_LENGTH_LIMIT
- YOUTUBEDL_SOURCE_ADDR
- YOUTUBEDL_VERBOSE
services:
redis:
image: redis:6.0-buster
Expand Down Expand Up @@ -74,6 +76,8 @@ services:
- YOUTUBE_API_KEY
- UPLOAD_FILE_SIZE_LIMIT
- YOUTUBE_LENGTH_LIMIT
- YOUTUBEDL_SOURCE_ADDR
- YOUTUBEDL_VERBOSE
depends_on:
- redis
- frontend
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ whitenoise==6.5.0
xumx-spleeterweb==0.2.4
yapf==0.40.1
youtube-title-parse==1.0.0
yt-dlp @ git+https://github.com/JeffreyCA/yt-dlp@3f3011bbd117cbc22f12fce1b8373f30f4f8b931
yt-dlp @ git+https://github.com/JeffreyCA/yt-dlp@488aa3f9b83838a933803e6426238a04bccd7fa6
nnabla-ext-cuda110==1.26.0; sys_platform == 'linux'
python-magic==0.4.27; sys_platform == 'linux'
python-magic-bin==0.4.14; sys_platform != 'linux'

0 comments on commit f7e92f4

Please sign in to comment.