Define the audio formats tuple in python backend
This commit is contained in:
parent
eca44aa950
commit
6936292218
|
|
@ -1,5 +1,7 @@
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
|
AUDIO_FORMATS = ("m4a", "mp3", "opus", "wav")
|
||||||
|
|
||||||
def get_format(format: str, quality: str) -> str:
|
def get_format(format: str, quality: str) -> str:
|
||||||
"""
|
"""
|
||||||
Returns format for download
|
Returns format for download
|
||||||
|
|
@ -23,7 +25,7 @@ def get_format(format: str, quality: str) -> str:
|
||||||
# Quality is irrelevant in this case since we skip the download
|
# Quality is irrelevant in this case since we skip the download
|
||||||
return "bestaudio/best"
|
return "bestaudio/best"
|
||||||
|
|
||||||
if format in ("m4a", "mp3", "opus", "wav"):
|
if format in AUDIO_FORMATS:
|
||||||
# Audio quality needs to be set post-download, set in opts
|
# Audio quality needs to be set post-download, set in opts
|
||||||
return "bestaudio/best"
|
return "bestaudio/best"
|
||||||
|
|
||||||
|
|
@ -59,12 +61,14 @@ def get_opts(format: str, quality: str, ytdl_opts: dict) -> dict:
|
||||||
if "postprocessors" not in opts:
|
if "postprocessors" not in opts:
|
||||||
opts["postprocessors"] = []
|
opts["postprocessors"] = []
|
||||||
|
|
||||||
if format in ("m4a", "mp3", "opus", "wav"):
|
if format in AUDIO_FORMATS:
|
||||||
opts["postprocessors"].append({
|
opts["postprocessors"].append({
|
||||||
"key": "FFmpegExtractAudio",
|
"key": "FFmpegExtractAudio",
|
||||||
"preferredcodec": format,
|
"preferredcodec": format,
|
||||||
"preferredquality": 0 if quality == "best" else quality,
|
"preferredquality": 0 if quality == "best" else quality,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
#Audio formats without thumbnail
|
||||||
if format not in ("wav"):
|
if format not in ("wav"):
|
||||||
opts["writethumbnail"] = True
|
opts["writethumbnail"] = True
|
||||||
opts["postprocessors"].append({"key": "FFmpegThumbnailsConvertor", "format": "jpg", "when": "before_dl"})
|
opts["postprocessors"].append({"key": "FFmpegThumbnailsConvertor", "format": "jpg", "when": "before_dl"})
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import asyncio
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
from dl_formats import get_format, get_opts
|
from dl_formats import get_format, get_opts, AUDIO_FORMATS
|
||||||
|
|
||||||
log = logging.getLogger('ytdl')
|
log = logging.getLogger('ytdl')
|
||||||
|
|
||||||
|
|
@ -234,7 +234,7 @@ class DownloadQueue:
|
||||||
if not self.queue.exists(entry['id']):
|
if not self.queue.exists(entry['id']):
|
||||||
dl = DownloadInfo(entry['id'], entry['title'], entry.get('webpage_url') or entry['url'], quality, format, folder)
|
dl = DownloadInfo(entry['id'], entry['title'], entry.get('webpage_url') or entry['url'], quality, format, folder)
|
||||||
# Keep consistent with frontend
|
# Keep consistent with frontend
|
||||||
base_directory = self.config.DOWNLOAD_DIR if (quality != 'audio' and format not in ("m4a", "mp3", "opus", "wav")) else self.config.AUDIO_DOWNLOAD_DIR
|
base_directory = self.config.DOWNLOAD_DIR if (quality != 'audio' and format not in AUDIO_FORMATS) else self.config.AUDIO_DOWNLOAD_DIR
|
||||||
if folder:
|
if folder:
|
||||||
if not self.config.CUSTOM_DIRS:
|
if not self.config.CUSTOM_DIRS:
|
||||||
return {'status': 'error', 'msg': f'A folder for the download was specified but CUSTOM_DIRS is not true in the configuration.'}
|
return {'status': 'error', 'msg': f'A folder for the download was specified but CUSTOM_DIRS is not true in the configuration.'}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue