Fixes for default preset.

This commit is contained in:
ArabCoders 2024-12-17 18:43:09 +03:00
parent 45227be6bf
commit fcb2eda4ba
9 changed files with 77 additions and 77 deletions

3
.vscode/launch.json vendored
View file

@ -34,7 +34,8 @@
"YTP_TEMP_PATH": "${workspaceFolder}/var/tmp", "YTP_TEMP_PATH": "${workspaceFolder}/var/tmp",
"YTP_URL_HOST": "http://localhost:8081", "YTP_URL_HOST": "http://localhost:8081",
"YTP_LOG_LEVEL": "DEBUG", "YTP_LOG_LEVEL": "DEBUG",
"YTP_DEBUG": "false", "YTP_DEBUG": "true",
"YTP_YTDL_DEBUG": "true",
} }
}, },
{ {

View file

@ -111,7 +111,7 @@ class DataStore:
return None return None
async def test(self) -> bool: async def test(self) -> bool:
await self.connection.execute('SELECT "id" FROM "history" LIMIT 1').fetchone() self.connection.execute('SELECT "id" FROM "history" LIMIT 1').fetchone()
return True return True
def _updateStoreItem(self, type: str, item: ItemDTO) -> None: def _updateStoreItem(self, type: str, item: ItemDTO) -> None:

View file

@ -70,7 +70,7 @@ class Download:
self.output_template_chapter = info.output_template_chapter self.output_template_chapter = info.output_template_chapter
self.output_template = info.output_template self.output_template = info.output_template
self.preset = info.preset self.preset = info.preset
self.ytdl_opts = get_opts(self.preset, info.ytdlp_config if info.ytdlp_config else {}) self.ytdl_opts = info.ytdlp_config if info.ytdlp_config else {}
self.info = info self.info = info
self.id = info._id self.id = info._id
self.default_ytdl_opts = config.ytdl_options self.default_ytdl_opts = config.ytdl_options
@ -121,7 +121,7 @@ class Download:
'break_on_existing': True, 'break_on_existing': True,
'progress_hooks': [self._progress_hook], 'progress_hooks': [self._progress_hook],
'postprocessor_hooks': [self._postprocessor_hook], 'postprocessor_hooks': [self._postprocessor_hook],
**mergeConfig(self.default_ytdl_opts, self.ytdl_opts), **get_opts(self.preset, mergeConfig(self.default_ytdl_opts, self.ytdl_opts)),
} }
if 'format' not in params and self.default_ytdl_opts.get('format', None): if 'format' not in params and self.default_ytdl_opts.get('format', None):

View file

@ -209,7 +209,7 @@ class DownloadQueue:
): ):
ytdlp_config = ytdlp_config if ytdlp_config else {} ytdlp_config = ytdlp_config if ytdlp_config else {}
LOG.info(f"Adding url '{url}' to folder '{folder}' with the following options 'Preset: {preset=}' 'Naming: {output_template}', 'Cookies: {ytdlp_cookies}' 'YTConfig: {ytdlp_config}'.") LOG.info(f"Adding url '{url}' to folder '{folder}' with the following options 'Preset: {preset}' 'Naming: {output_template}', 'Cookies: {ytdlp_cookies}' 'YTConfig: {ytdlp_config}'.")
if isinstance(ytdlp_config, str): if isinstance(ytdlp_config, str):
try: try:

View file

@ -32,33 +32,33 @@ def get_opts(preset: str, ytdl_opts: dict) -> dict:
opts = copy.deepcopy(ytdl_opts) opts = copy.deepcopy(ytdl_opts)
if 'default' == preset: if 'default' == preset:
LOG.debug("Using default preset.")
return opts return opts
from .config import Config from .config import Config
presets = Config.get_instance().presets presets = Config.get_instance().presets
if preset not in presets: found = False
for _preset in presets:
if _preset['name'] == preset:
found = True
preset_opts = _preset
break
if not found:
LOG.error(f"Preset '{preset}' is not defined in the presets.") LOG.error(f"Preset '{preset}' is not defined in the presets.")
return opts return opts
preset_opts = presets[preset]
opts['format'] = preset_opts.get('format') opts['format'] = preset_opts.get('format')
if 'postprocessors' in preset_opts: if 'postprocessors' in preset_opts:
if 'postprocessors' not in opts: opts['postprocessors'] = preset_opts['postprocessors']
opts['postprocessors'] = []
opts['postprocessors'].extend(preset_opts['postprocessors'])
if 'args' in preset_opts: if 'args' in preset_opts:
for ignored_key in IGNORED_KEYS: for key, value in preset_opts['args'].items():
for key, value in preset_opts['args'].items(): opts[key] = value
if key == ignored_key:
continue
opts[key] = value
LOG.debug(f"Using preset '{preset}', altered options: {opts}")
return opts return opts

View file

@ -66,43 +66,50 @@ class Config:
ytdlp_version: str = YTDLP_VERSION ytdlp_version: str = YTDLP_VERSION
tasks: list = [] tasks: list = []
presets: list = [ presets: list = [
{'name': 'default', 'format': 'default', 'postprocessors': [],
'args': {}},
{'name': 'Video - 1080p h264/acc', 'format': 'bv[height<=1080][ext=mp4]+ba[ext=m4a]/b[ext=mp4]/b[ext=webm]',
'args': {'format_sort': ['vcodec:h264'], }, },
{'name': 'Video - 720p h264/acc', 'format': 'bv[height<=720][ext=mp4]+ba[ext=m4a]/b[ext=mp4]/b[ext=webm]',
'args': {'format_sort': ['vcodec:h264'], }, },
{ {
'name': 'Default - Use default yt-dlp format', 'name': 'Audio - Best audio [MP3]',
'format': 'default', 'format': 'bestaudio/best',
'postprocessors': [], 'postprocessors': [
'args': {} {
}, "key": "FFmpegExtractAudio",
# { "preferredcodec": "mp3",
# 'name': 'Audio - Best audio [MP3]', "preferredquality": "5",
# 'format': 'bestaudio', "nopostoverwrites": False
# 'postprocessors': [ },
# {'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', 'preferredquality': 'best'}, {
# {"key": "FFmpegThumbnailsConvertor", "format": "jpg", "when": "before_dl"}, "key": "FFmpegMetadata",
# {'key': 'FFmpegMetadata'}, "add_chapters": True,
# {'key': 'EmbedThumbnail'}, "add_metadata": True,
# ], "add_infojson": "if_exists"
# 'args': { },
# 'writethumbnail': True {
# } "key": "EmbedThumbnail",
# }, "already_have_thumbnail": False
{ },
'name': 'Video - 1080p h264/acc', {
'format': 'bv[height<=1080][ext=mp4]+ba[ext=m4a]/b[ext=mp4]/b[ext=webm]', "key": "FFmpegConcat",
"only_multi_video": True,
"when": "playlist"
}
],
'args': { 'args': {
'format_sort': [ "outtmpl": {
'vcodec:h264' "pl_thumbnail": ""
], },
}, "ignoreerrors": "only_download",
}, "retries": 10,
{ "fragment_retries": 10,
'name': 'Video - 720p h264/acc', "writethumbnail": True,
'format': 'bv[height<=720][ext=mp4]+ba[ext=m4a]/b[ext=mp4]/b[ext=webm]', "extract_flat": "discard_in_playlist",
'args': { "final_ext": "mp3",
'format_sort': [ }
'vcodec:h264' }
],
},
},
] ]
_manual_vars: tuple = ('temp_path', 'config_path', 'download_path',) _manual_vars: tuple = ('temp_path', 'config_path', 'download_path',)
@ -119,7 +126,7 @@ class Config:
'ytdlp_version', 'version', 'url_host', 'started', 'url_prefix', 'ytdlp_version', 'version', 'url_host', 'started', 'url_prefix',
) )
@staticmethod @ staticmethod
def get_instance(): def get_instance():
""" Static access method. """ """ Static access method. """
return Config() if not Config.__instance else Config.__instance return Config() if not Config.__instance else Config.__instance
@ -207,7 +214,7 @@ class Config:
LOG.error(f"Error starting debugpy server at '0.0.0.0:{self.debugpy_port}'. {e}") LOG.error(f"Error starting debugpy server at '0.0.0.0:{self.debugpy_port}'. {e}")
optsFile: str = os.path.join(self.config_path, 'ytdlp.json') optsFile: str = os.path.join(self.config_path, 'ytdlp.json')
if os.path.exists(optsFile) and os.path.getsize(optsFile) > 0: if os.path.exists(optsFile) and os.path.getsize(optsFile) > 4:
LOG.info(f"Loading yt-dlp custom options from '{optsFile}'.") LOG.info(f"Loading yt-dlp custom options from '{optsFile}'.")
(opts, status, error) = load_file(optsFile, dict) (opts, status, error) = load_file(optsFile, dict)

View file

@ -101,12 +101,12 @@
<div v-if="item.thumbnail && false === hideThumbnail" class="card-image"> <div v-if="item.thumbnail && false === hideThumbnail" class="card-image">
<figure class="image is-3by1"> <figure class="image is-3by1">
<template v-if="item.status === 'finished'"> <template v-if="item.status === 'finished'">
<NuxtLink v-tooltip="`Play: ${item.title}`" :href="makeDownload(config, item, 'm3u8')" <a v-tooltip="`Play: ${item.title}`" :href="makeDownload(config, item, 'm3u8')"
@click.prevent="playVideo(item)"> @click.prevent="playVideo(item)">
<img <img
:src="config.app.url_host + config.app.url_prefix + 'thumbnail?url=' + encodePath(item.thumbnail)" :src="config.app.url_host + config.app.url_prefix + 'thumbnail?url=' + encodePath(item.thumbnail)"
:alt="item.title" /> :alt="item.title" />
</NuxtLink> </a>
</template> </template>
<template v-else> <template v-else>
<NuxtLink target="_blank" :href="item.url" v-tooltip="`Open: ${item.title} link`"> <NuxtLink target="_blank" :href="item.url" v-tooltip="`Open: ${item.title} link`">
@ -403,16 +403,7 @@ const requeueIncomplete = () => {
if ('finished' === item.status) { if ('finished' === item.status) {
continue; continue;
} }
reQueueItem(item)
emits('deleteItem', 'completed', key);
emits('addItem', {
url: item.url,
format: item.preset,
folder: item.folder,
ytdlp_config: item.ytdlp_config,
ytdlp_cookies: item.ytdlp_cookies,
output_template: item.output_template,
});
} }
} }
@ -428,8 +419,7 @@ const reQueueItem = item => {
socket.emit('item_delete', item._id) socket.emit('item_delete', item._id)
socket.emit('add_url', { socket.emit('add_url', {
url: item.url, url: item.url,
format: item.format, preset: item.preset,
quality: item.quality,
folder: item.folder, folder: item.folder,
ytdlp_config: item.ytdlp_config, ytdlp_config: item.ytdlp_config,
ytdlp_cookies: item.ytdlp_cookies, ytdlp_cookies: item.ytdlp_cookies,

View file

@ -20,7 +20,7 @@
<div class="control is-expanded"> <div class="control is-expanded">
<div class="select is-fullwidth"> <div class="select is-fullwidth">
<select id="preset" class="is-fullwidth" :disabled="!socket.isConnected" v-model="selectedPreset"> <select id="preset" class="is-fullwidth" :disabled="!socket.isConnected" v-model="selectedPreset">
<option v-for="item in config.presets" :key="item.name" :value="item.format"> <option v-for="item in config.presets" :key="item.name" :value="item.name">
{{ item.name }} {{ item.name }}
</option> </option>
</select> </select>
@ -135,7 +135,7 @@ const config = useConfigStore();
const socket = useSocketStore(); const socket = useSocketStore();
const toast = useToast(); const toast = useToast();
const selectedPreset = useStorage('selectedPreset', 'default') const selectedPreset = useStorage('selectedPreset', '')
const ytdlpConfig = useStorage('ytdlp_config', '') const ytdlpConfig = useStorage('ytdlp_config', '')
const ytdlpCookies = useStorage('ytdlp_cookies', '') const ytdlpCookies = useStorage('ytdlp_cookies', '')
const output_template = useStorage('output_template', null) const output_template = useStorage('output_template', null)
@ -166,8 +166,8 @@ const resetConfig = () => {
ytdlpConfig.value = ''; ytdlpConfig.value = '';
ytdlpCookies.value = ''; ytdlpCookies.value = '';
output_template.value = null; output_template.value = null;
url.value = ''; url.value = null;
downloadPath.value = ''; downloadPath.value = null;
showAdvanced.value = false; showAdvanced.value = false;
toast.success('Local configuration has been reset.'); toast.success('Local configuration has been reset.');
@ -186,6 +186,11 @@ const statusHandler = async data => {
url.value = ''; url.value = '';
} }
onMounted(() => socket.on('status', statusHandler)) onMounted(() => {
socket.on('status', statusHandler)
if ('' === selectedPreset.value) {
selectedPreset.value = 'default'
}
})
onUnmounted(() => socket.off('status', statusHandler)) onUnmounted(() => socket.off('status', statusHandler))
</script> </script>

View file

@ -44,7 +44,6 @@ export const useSocketStore = defineStore('socket', () => {
socket.value.on('completed', stream => { socket.value.on('completed', stream => {
const item = JSON.parse(stream); const item = JSON.parse(stream);
console.log(item)
if (true === stateStore.has('queue', item._id)) { if (true === stateStore.has('queue', item._id)) {
stateStore.remove('queue', item._id); stateStore.remove('queue', item._id);
} }
@ -56,7 +55,6 @@ export const useSocketStore = defineStore('socket', () => {
const id = JSON.parse(stream); const id = JSON.parse(stream);
if (true !== stateStore.has('queue', id)) { if (true !== stateStore.has('queue', id)) {
console.log(stream)
return return
} }
@ -71,7 +69,6 @@ export const useSocketStore = defineStore('socket', () => {
const id = JSON.parse(stream); const id = JSON.parse(stream);
if (true !== stateStore.has('history', id)) { if (true !== stateStore.has('history', id)) {
console.log(stream)
return return
} }