remove the reload file option and consolidate code
This commit is contained in:
parent
afbf8b07d6
commit
91aaa9f425
|
|
@ -61,7 +61,6 @@ Certain values can be set via environment variables, using the `-e` parameter on
|
||||||
* __DEFAULT_OPTION_PLAYLIST_ITEM_LIMIT__: Maximum number of playlist items that can be downloaded. Defaults to `0` (no limit).
|
* __DEFAULT_OPTION_PLAYLIST_ITEM_LIMIT__: Maximum number of playlist items that can be downloaded. Defaults to `0` (no limit).
|
||||||
* __YTDL_OPTIONS__: Additional options to pass to yt-dlp, in JSON format. [See available options here](https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/YoutubeDL.py#L220). They roughly correspond to command-line options, though some do not have exact equivalents here, for example `--recode-video` has to be specified via `postprocessors`. Also note that dashes are replaced with underscores. You may find [this script](https://github.com/yt-dlp/yt-dlp/blob/master/devscripts/cli_to_api.py) helpful for converting from command line options to `YTDL_OPTIONS`.
|
* __YTDL_OPTIONS__: Additional options to pass to yt-dlp, in JSON format. [See available options here](https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/YoutubeDL.py#L220). They roughly correspond to command-line options, though some do not have exact equivalents here, for example `--recode-video` has to be specified via `postprocessors`. Also note that dashes are replaced with underscores. You may find [this script](https://github.com/yt-dlp/yt-dlp/blob/master/devscripts/cli_to_api.py) helpful for converting from command line options to `YTDL_OPTIONS`.
|
||||||
* __YTDL_OPTIONS_FILE__: A path to a JSON file that will be loaded and used for populating `YTDL_OPTIONS` above. Please note that if both `YTDL_OPTIONS_FILE` and `YTDL_OPTIONS` are specified, the options in `YTDL_OPTIONS` take precedence.
|
* __YTDL_OPTIONS_FILE__: A path to a JSON file that will be loaded and used for populating `YTDL_OPTIONS` above. Please note that if both `YTDL_OPTIONS_FILE` and `YTDL_OPTIONS` are specified, the options in `YTDL_OPTIONS` take precedence.
|
||||||
* __YTDL_OPTIONS_FILE_RELOAD__:Reload `YTDL_OPTIONS` when file is modified. Defaults to `false`.
|
|
||||||
* __ROBOTS_TXT__: A path to a `robots.txt` file mounted in the container
|
* __ROBOTS_TXT__: A path to a `robots.txt` file mounted in the container
|
||||||
* __DOWNLOAD_MODE__ :This flag controls how downloads are scheduled and executed. Options are `sequential`, `concurrent`, and `limited`. Defaults to `limited`:
|
* __DOWNLOAD_MODE__ :This flag controls how downloads are scheduled and executed. Options are `sequential`, `concurrent`, and `limited`. Defaults to `limited`:
|
||||||
* `sequential`: Downloads are processed one at a time. A new download won’t start until the previous one has finished. This mode is useful for conserving system resources or ensuring downloads occur in a strict order.
|
* `sequential`: Downloads are processed one at a time. A new download won’t start until the previous one has finished. This mode is useful for conserving system resources or ensuring downloads occur in a strict order.
|
||||||
|
|
|
||||||
32
app/main.py
32
app/main.py
|
|
@ -42,7 +42,6 @@ class Config:
|
||||||
'DEFAULT_OPTION_PLAYLIST_ITEM_LIMIT' : '0',
|
'DEFAULT_OPTION_PLAYLIST_ITEM_LIMIT' : '0',
|
||||||
'YTDL_OPTIONS': '{}',
|
'YTDL_OPTIONS': '{}',
|
||||||
'YTDL_OPTIONS_FILE': '',
|
'YTDL_OPTIONS_FILE': '',
|
||||||
'YTDL_OPTIONS_FILE_RELOAD': 'false',
|
|
||||||
'ROBOTS_TXT': '',
|
'ROBOTS_TXT': '',
|
||||||
'HOST': '0.0.0.0',
|
'HOST': '0.0.0.0',
|
||||||
'PORT': '8081',
|
'PORT': '8081',
|
||||||
|
|
@ -57,7 +56,7 @@ class Config:
|
||||||
'ENABLE_ACCESSLOG': 'false',
|
'ENABLE_ACCESSLOG': 'false',
|
||||||
}
|
}
|
||||||
|
|
||||||
_BOOLEAN = ('DOWNLOAD_DIRS_INDEXABLE', 'CUSTOM_DIRS', 'CREATE_CUSTOM_DIRS', 'DELETE_FILE_ON_TRASHCAN', 'DEFAULT_OPTION_PLAYLIST_STRICT_MODE', 'HTTPS', 'ENABLE_ACCESSLOG','YTDL_OPTIONS_FILE_RELOAD')
|
_BOOLEAN = ('DOWNLOAD_DIRS_INDEXABLE', 'CUSTOM_DIRS', 'CREATE_CUSTOM_DIRS', 'DELETE_FILE_ON_TRASHCAN', 'DEFAULT_OPTION_PLAYLIST_STRICT_MODE', 'HTTPS', 'ENABLE_ACCESSLOG')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
for k, v in self._DEFAULTS.items():
|
for k, v in self._DEFAULTS.items():
|
||||||
|
|
@ -82,30 +81,17 @@ class Config:
|
||||||
log.error('YTDL_OPTIONS is invalid')
|
log.error('YTDL_OPTIONS is invalid')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if self.YTDL_OPTIONS_FILE:
|
success,_ = self.load_ytdl_options_file(True)
|
||||||
log.info(f'Loading yt-dlp custom options from "{self.YTDL_OPTIONS_FILE}"')
|
if not success:
|
||||||
if not os.path.exists(self.YTDL_OPTIONS_FILE):
|
|
||||||
log.error(f'File "{self.YTDL_OPTIONS_FILE}" not found')
|
|
||||||
sys.exit(1)
|
|
||||||
try:
|
|
||||||
with open(self.YTDL_OPTIONS_FILE) as json_data:
|
|
||||||
opts = json.load(json_data)
|
|
||||||
assert isinstance(opts, dict)
|
|
||||||
except (json.decoder.JSONDecodeError, AssertionError):
|
|
||||||
log.error('YTDL_OPTIONS_FILE contents is invalid')
|
|
||||||
sys.exit(1)
|
|
||||||
self.YTDL_OPTIONS.update(opts)
|
|
||||||
|
|
||||||
if self.YTDL_OPTIONS_FILE_RELOAD and not self.YTDL_OPTIONS_FILE:
|
|
||||||
log.error('YTDL_OPTIONS_FILE_RELOAD is enabled but YTDL_OPTIONS_FILE is not set. ')
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def load_ytdl_options_file(self) -> tuple[bool, str]:
|
def load_ytdl_options_file(self, allow_empty_path=False) -> tuple[bool, str]:
|
||||||
msg = ''
|
msg = ''
|
||||||
if not self.YTDL_OPTIONS_FILE:
|
if not self.YTDL_OPTIONS_FILE:
|
||||||
msg='YTDL_OPTIONS_FILE is not set'
|
msg='YTDL_OPTIONS_FILE is not set'
|
||||||
log.error(msg)
|
if not allow_empty_path:
|
||||||
return (False, msg)
|
log.error(msg)
|
||||||
|
return (allow_empty_path, msg)
|
||||||
log.info(f'Loading yt-dlp custom options from "{self.YTDL_OPTIONS_FILE}"')
|
log.info(f'Loading yt-dlp custom options from "{self.YTDL_OPTIONS_FILE}"')
|
||||||
if not os.path.exists(self.YTDL_OPTIONS_FILE):
|
if not os.path.exists(self.YTDL_OPTIONS_FILE):
|
||||||
msg = f'File "{self.YTDL_OPTIONS_FILE}" not found'
|
msg = f'File "{self.YTDL_OPTIONS_FILE}" not found'
|
||||||
|
|
@ -184,7 +170,7 @@ async def watch_files():
|
||||||
log.info(f'Starting Watch File: {path_to_watch}')
|
log.info(f'Starting Watch File: {path_to_watch}')
|
||||||
asyncio.create_task(_watch_files())
|
asyncio.create_task(_watch_files())
|
||||||
|
|
||||||
if config.YTDL_OPTIONS_FILE_RELOAD:
|
if config.YTDL_OPTIONS_FILE:
|
||||||
app.on_startup.append(lambda app: watch_files())
|
app.on_startup.append(lambda app: watch_files())
|
||||||
|
|
||||||
@routes.post(config.URL_PREFIX + 'add')
|
@routes.post(config.URL_PREFIX + 'add')
|
||||||
|
|
@ -259,7 +245,7 @@ async def connect(sid, environ):
|
||||||
await sio.emit('configuration', serializer.encode(config), to=sid)
|
await sio.emit('configuration', serializer.encode(config), to=sid)
|
||||||
if config.CUSTOM_DIRS:
|
if config.CUSTOM_DIRS:
|
||||||
await sio.emit('custom_dirs', serializer.encode(get_custom_dirs()), to=sid)
|
await sio.emit('custom_dirs', serializer.encode(get_custom_dirs()), to=sid)
|
||||||
if config.YTDL_OPTIONS_FILE_RELOAD:
|
if config.YTDL_OPTIONS_FILE:
|
||||||
await sio.emit('ytdl_options_changed', serializer.encode(get_options_update_time()), to=sid)
|
await sio.emit('ytdl_options_changed', serializer.encode(get_options_update_time()), to=sid)
|
||||||
|
|
||||||
def get_custom_dirs():
|
def get_custom_dirs():
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue