Skip to content

Commit

Permalink
Merge pull request #672 from tcely/patch-3
Browse files Browse the repository at this point in the history
Adjustments for downloading delays
  • Loading branch information
meeb authored Feb 2, 2025
2 parents 5e1da4e + da8aa06 commit 4902a44
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
6 changes: 3 additions & 3 deletions tubesync/sync/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ def download_media(
'writethumbnail': True,
'check_formats': False,
'overwrites': None,
'sleep_interval': 30,
'max_sleep_interval': 600,
'sleep_interval_requests': 30,
'sleep_interval': 10 + int(settings.DOWNLOAD_MEDIA_DELAY / 20),
'max_sleep_interval': settings.DOWNLOAD_MEDIA_DELAY,
'sleep_interval_requests': 5,
'paths': opts.get('paths', dict()),
'postprocessor_args': opts.get('postprocessor_args', dict()),
'postprocessor_hooks': opts.get('postprocessor_hooks', list()),
Expand Down
3 changes: 0 additions & 3 deletions tubesync/tubesync/local_settings.py.container
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ else:


DEFAULT_THREADS = 1
MAX_BACKGROUND_TASK_ASYNC_THREADS = 8
BACKGROUND_TASK_ASYNC_THREADS = int(os.getenv('TUBESYNC_WORKERS', DEFAULT_THREADS))
if BACKGROUND_TASK_ASYNC_THREADS > MAX_BACKGROUND_TASK_ASYNC_THREADS:
BACKGROUND_TASK_ASYNC_THREADS = MAX_BACKGROUND_TASK_ASYNC_THREADS


MEDIA_ROOT = CONFIG_BASE_DIR / 'media'
Expand Down
24 changes: 24 additions & 0 deletions tubesync/tubesync/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@
RENAME_SOURCES = None


# WARNING WARNING WARNING
# Below this line, the logic and formulas must remain as they are.
# Changing them is very likely to break the software in weird ways.
# To change anything, you should adjust a variable above or in the
# 'local_settings.py' file instead.
# You have been warned!

try:
from .local_settings import *
except ImportError as e:
Expand All @@ -189,5 +196,22 @@
sys.exit(1)


try:
MAX_RUN_TIME = int(str(MAX_RUN_TIME), base=10)
except:
# fall back to the default value from:
# https://github.com/django-background-tasks/django-background-tasks/blob/12c8f328e4ba704bd7d91534bb6569e70197b949/background_task/settings.py#L28
MAX_RUN_TIME = 3600

# Tasks scheduled with `background_task` need a chance to finish
if MAX_RUN_TIME < 600:
MAX_RUN_TIME = 600

DOWNLOAD_MEDIA_DELAY = 60 + (MAX_RUN_TIME / 20)

if BACKGROUND_TASK_ASYNC_THREADS > MAX_BACKGROUND_TASK_ASYNC_THREADS:
BACKGROUND_TASK_ASYNC_THREADS = MAX_BACKGROUND_TASK_ASYNC_THREADS


from .dbutils import patch_ensure_connection
patch_ensure_connection()

0 comments on commit 4902a44

Please sign in to comment.