-
-
Notifications
You must be signed in to change notification settings - Fork 1
feat(wistia): add subtitle download support #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kovyrin
wants to merge
13
commits into
ByteTrix:main
Choose a base branch
from
kovyrin:feature/subtitle-downloads
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a4dca4a
feat(wistia): add subtitle download support
kovyrin f2cd39d
Respect subtitle flag when restoring cached tasks
kovyrin 80129f8
Update thinkific_downloader/downloader.py
kovyrin 7f4a58a
Update thinkific_downloader/downloader.py
kovyrin 60f8273
Update thinkific_downloader/wistia_downloader.py
kovyrin e02aca2
Refactor Wistia track extraction helper
kovyrin 72573ac
Factor cache restore helpers
kovyrin bd00862
Decompose Wistia track processing helpers
kovyrin c705cc3
Update thinkific_downloader/downloader.py
kovyrin 08b0129
Update thinkific_downloader/wistia_downloader.py
kovyrin 47192c4
Update thinkific_downloader/downloader.py
kovyrin 98112af
Improve resume cache handling for subtitles
kovyrin 462b3b6
Return Wistia subtitle tasks for callers
kovyrin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -382,10 +382,77 @@ def download_file_chunked(src_url: str, dst_name: str, chunk_mb: int = 1): | |
| add_download_task(src_url, dst_path, "file") | ||
|
|
||
|
|
||
| def _load_cached_progress(cache_file: Path): | ||
| """Return previously analyzed chapters and queued tasks from the resume cache.""" | ||
| analyzed_chapters = set() | ||
| saved_tasks: List[Dict[str, Any]] = [] | ||
|
|
||
| if not cache_file.exists(): | ||
| return analyzed_chapters, saved_tasks | ||
|
|
||
| try: | ||
| with open(cache_file, 'r', encoding='utf-8') as f: | ||
| cache_data = json.load(f) | ||
|
|
||
| analyzed_chapters = set(cache_data.get('analyzed_chapters', [])) | ||
| saved_tasks = cache_data.get('download_tasks', []) | ||
| print(f"📋 Found previous progress: {len(analyzed_chapters)} chapters analyzed, {len(saved_tasks)} tasks cached") | ||
|
|
||
| # If subtitle downloads were newly enabled, invalidate cache so we can regenerate tasks. | ||
| if SETTINGS and SETTINGS.subtitle_download_enabled and saved_tasks: | ||
| has_subtitle_tasks = any( | ||
| (task.get('content_type') or '').lower() == 'subtitle' | ||
| for task in saved_tasks | ||
| ) | ||
| if not has_subtitle_tasks: | ||
| print("🆕 Subtitle support enabled — refreshing cached analysis to include captions.") | ||
| analyzed_chapters = set() | ||
| saved_tasks = [] | ||
| try: | ||
| cache_file.unlink() | ||
| except OSError: | ||
| pass | ||
| except (json.JSONDecodeError, OSError): | ||
| analyzed_chapters = set() | ||
| saved_tasks = [] | ||
|
|
||
| return analyzed_chapters, saved_tasks | ||
|
|
||
|
|
||
| def _restore_saved_tasks(saved_tasks: List[Dict[str, Any]]): | ||
| """Restore cached download tasks, respecting the subtitle feature flag.""" | ||
| if not saved_tasks: | ||
| return | ||
|
|
||
| restored_tasks = saved_tasks | ||
| if SETTINGS and hasattr(SETTINGS, 'subtitle_download_enabled') and not SETTINGS.subtitle_download_enabled: | ||
| filtered_tasks: List[Dict[str, Any]] = [] | ||
| skipped_count = 0 | ||
| for task in saved_tasks: | ||
| content_type = (task.get('content_type') or 'video').lower() | ||
| if content_type == 'subtitle': | ||
| skipped_count += 1 | ||
| continue | ||
| filtered_tasks.append(task) | ||
| restored_tasks = filtered_tasks | ||
|
||
| if skipped_count: | ||
| print(f"⏭️ Skipping {skipped_count} cached subtitle task(s) because subtitle downloads are disabled.") | ||
kovyrin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if not restored_tasks: | ||
| return | ||
|
|
||
| print(f"📥 Restoring {len(restored_tasks)} previously collected download tasks...") | ||
| for task_data in restored_tasks: | ||
| add_download_task(task_data['url'], Path(task_data['dest_path']), task_data.get('content_type', 'video')) | ||
|
|
||
|
|
||
|
|
||
| def init_course(data: Dict[str, Any]): | ||
| """Initialize course structure and collect ALL download tasks first.""" | ||
| global COURSE_CONTENTS, ROOT_PROJECT_DIR, BASE_HOST, DOWNLOAD_TASKS | ||
|
|
||
| # Ensure settings/download manager are initialized so feature flags are available | ||
| init_settings() | ||
|
|
||
| # Initialize download tasks list | ||
| DOWNLOAD_TASKS = [] | ||
|
|
@@ -409,17 +476,7 @@ def init_course(data: Dict[str, Any]): | |
| analyzed_chapters = set() | ||
| saved_tasks = [] | ||
|
|
||
| if cache_file.exists(): | ||
| try: | ||
| import json | ||
| with open(cache_file, 'r', encoding='utf-8') as f: | ||
| cache_data = json.load(f) | ||
| analyzed_chapters = set(cache_data.get('analyzed_chapters', [])) | ||
| saved_tasks = cache_data.get('download_tasks', []) | ||
| print(f"📋 Found previous progress: {len(analyzed_chapters)} chapters analyzed, {len(saved_tasks)} tasks cached") | ||
| except: | ||
| analyzed_chapters = set() | ||
| saved_tasks = [] | ||
| analyzed_chapters, saved_tasks = _load_cached_progress(cache_file) | ||
|
|
||
| # Derive base host from landing_page_url if available | ||
| landing = data['course'].get('landing_page_url') | ||
|
|
@@ -430,10 +487,7 @@ def init_course(data: Dict[str, Any]): | |
| print("\n🔍 Phase 1: Analyzing course content and collecting download links...") | ||
|
|
||
| # Restore saved download tasks | ||
| if saved_tasks: | ||
| print(f"📥 Restoring {len(saved_tasks)} previously collected download tasks...") | ||
| for task_data in saved_tasks: | ||
| add_download_task(task_data['url'], Path(task_data['dest_path']), task_data.get('content_type', 'video')) | ||
| _restore_saved_tasks(saved_tasks) | ||
|
|
||
| collect_all_download_tasks(data, analyzed_chapters, cache_file) | ||
|
|
||
|
|
@@ -835,9 +889,16 @@ def collect_video_task_wistia(wistia_id: str, file_name: str, dest_dir: Path): | |
| video_url = selected.get('url') | ||
| if video_url: | ||
| ext = '.mp4' # Default extension | ||
| resolved_name = filter_filename(file_name) + ext | ||
| resolved_name = filter_filename(file_name) | ||
| if not resolved_name.lower().endswith(ext): | ||
| resolved_name += ext | ||
| print(f" 📹 Found video: {resolved_name}") | ||
| add_download_task(video_url, dest_dir / resolved_name, "video") | ||
| try: | ||
| from .wistia_downloader import queue_wistia_subtitle_downloads | ||
| queue_wistia_subtitle_downloads(data.get('media') or {}, dest_dir, resolved_name) | ||
| except Exception as subtitle_error: | ||
| print(f" ⚠️ Unable to queue subtitles for {resolved_name}: {subtitle_error}") | ||
| except Exception as e: | ||
| print(f" ❌ Failed to collect Wistia video {wistia_id}: {e}") | ||
|
|
||
|
|
@@ -1282,4 +1343,4 @@ def main(argv: List[str]): | |
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main(sys.argv) | ||
| main(sys.argv) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.