Add scheduled sync, disk space awareness, and subtitle downloads

- auto-sync daemon: background thread checks every hour and syncs followed
  channels for users with sync_interval_hours set (6/12/24h options)
- disk stats: /api/stats now returns total/used/free/download bytes;
  Stats page shows a disk usage bar
- subtitles: subtitle_langs setting (e.g. "en,sv") passed through all
  download paths; yt-dlp writes .srt files alongside the video
- Settings page: sync interval dropdown + subtitle languages input

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-26 20:36:50 +02:00
parent 3abbd5749e
commit ea99b74ba8
9 changed files with 150 additions and 6 deletions

View File

@@ -127,6 +127,7 @@ def create_download(
user_settings = db.query(UserSettings).filter_by(user_id=current_user.id).first()
default_quality = user_settings.preferred_quality if user_settings else "best"
quality = body.quality if body.quality in ytdlp.QUALITY_FORMATS else default_quality
subtitle_langs = (user_settings.subtitle_langs or "") if user_settings else ""
_DL_SELECT = """
SELECT d.id, d.status, d.progress_percent, d.resolution,
@@ -155,7 +156,7 @@ def create_download(
ytdlp.start_download,
video.youtube_video_id, dl.id,
_on_progress, _on_complete, _on_error,
quality,
quality, subtitle_langs,
)
row = db.execute(text(_DL_SELECT), {"id": dl.id}).mappings().first()
@@ -190,6 +191,11 @@ def _get_quality(db, user_id: int) -> str:
return s.preferred_quality if s else "best"
def _get_subtitle_langs(db, user_id: int) -> str:
s = db.query(UserSettings).filter_by(user_id=user_id).first()
return (s.subtitle_langs or "") if s else ""
@router.post("/channel/{channel_id}", status_code=202)
def download_channel_videos(
channel_id: int,
@@ -198,6 +204,7 @@ def download_channel_videos(
current_user: User = Depends(get_current_user),
):
quality = _get_quality(db, current_user.id)
subtitle_langs = _get_subtitle_langs(db, current_user.id)
rows = db.execute(
text("""
SELECT v.id, v.youtube_video_id
@@ -216,7 +223,7 @@ def download_channel_videos(
db.flush()
background_tasks.add_task(
ytdlp.start_download, row["youtube_video_id"], dl.id,
_on_progress, _on_complete, _on_error, quality,
_on_progress, _on_complete, _on_error, quality, subtitle_langs,
)
count += 1
db.commit()
@@ -230,6 +237,7 @@ def download_following_videos(
current_user: User = Depends(get_current_user),
):
quality = _get_quality(db, current_user.id)
subtitle_langs = _get_subtitle_langs(db, current_user.id)
rows = db.execute(
text("""
SELECT v.id, v.youtube_video_id