@auscera/socialscrape 0.0.0-stage → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +111 -2
- package/bin/socialscrape.mjs +115 -0
- package/engine/README.md +245 -0
- package/engine/SKILL.md +194 -0
- package/engine/agent.py +665 -0
- package/engine/batch_manager.py +622 -0
- package/engine/cli.py +23 -0
- package/engine/handlers.py +1109 -0
- package/engine/plugins/__init__.py +77 -0
- package/engine/plugins/instagram-scrape/README.md +164 -0
- package/engine/plugins/instagram-scrape/SKILL.md +53 -0
- package/engine/plugins/instagram-scrape/cli.py +176 -0
- package/engine/plugins/instagram-scrape/core.py +408 -0
- package/engine/plugins/instagram-scrape/plugin.json +42 -0
- package/engine/plugins/linkedin-scrape/README.md +143 -0
- package/engine/plugins/linkedin-scrape/SKILL.md +47 -0
- package/engine/plugins/linkedin-scrape/cli.py +126 -0
- package/engine/plugins/linkedin-scrape/core.py +188 -0
- package/engine/plugins/linkedin-scrape/plugin.json +36 -0
- package/engine/plugins/meta-ad-library-scraper/README.md +127 -0
- package/engine/plugins/meta-ad-library-scraper/SKILL.md +44 -0
- package/engine/plugins/meta-ad-library-scraper/cli.py +161 -0
- package/engine/plugins/meta-ad-library-scraper/core.py +348 -0
- package/engine/plugins/meta-ad-library-scraper/plugin.json +44 -0
- package/engine/plugins/pinterest-scraper/README.md +150 -0
- package/engine/plugins/pinterest-scraper/SKILL.md +45 -0
- package/engine/plugins/pinterest-scraper/cli.py +193 -0
- package/engine/plugins/pinterest-scraper/core.py +420 -0
- package/engine/plugins/pinterest-scraper/plugin.json +40 -0
- package/engine/plugins/reddit-discussion-scraper/README.md +162 -0
- package/engine/plugins/reddit-discussion-scraper/SKILL.md +52 -0
- package/engine/plugins/reddit-discussion-scraper/cli.py +218 -0
- package/engine/plugins/reddit-discussion-scraper/core.py +546 -0
- package/engine/plugins/reddit-discussion-scraper/plugin.json +46 -0
- package/engine/plugins/shared/__init__.py +15 -0
- package/engine/plugins/shared/paths.py +90 -0
- package/engine/plugins/shared/process_runner.py +169 -0
- package/engine/plugins/shared/session_manager.py +287 -0
- package/engine/plugins/threads-scraper/README.md +139 -0
- package/engine/plugins/threads-scraper/SKILL.md +43 -0
- package/engine/plugins/threads-scraper/cli.py +178 -0
- package/engine/plugins/threads-scraper/core.py +460 -0
- package/engine/plugins/threads-scraper/plugin.json +40 -0
- package/engine/plugins/tiktok-scrape/README.md +158 -0
- package/engine/plugins/tiktok-scrape/SKILL.md +51 -0
- package/engine/plugins/tiktok-scrape/cli.py +163 -0
- package/engine/plugins/tiktok-scrape/core.py +313 -0
- package/engine/plugins/tiktok-scrape/plugin.json +40 -0
- package/engine/plugins/twitter-scrape/README.md +158 -0
- package/engine/plugins/twitter-scrape/SKILL.md +50 -0
- package/engine/plugins/twitter-scrape/cli.py +153 -0
- package/engine/plugins/twitter-scrape/core.py +254 -0
- package/engine/plugins/twitter-scrape/plugin.json +40 -0
- package/engine/plugins/youtube-scrape/README.md +199 -0
- package/engine/plugins/youtube-scrape/SKILL.md +115 -0
- package/engine/plugins/youtube-scrape/cli.py +340 -0
- package/engine/plugins/youtube-scrape/core.py +829 -0
- package/engine/plugins/youtube-scrape/plugin.json +48 -0
- package/engine/requirements.txt +8 -0
- package/engine/socialscrape_cli.py +500 -0
- package/engine/storage.py +570 -0
- package/engine/ui.py +690 -0
- package/package.json +27 -3
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: youtube-scrape
|
|
3
|
+
description: "Self-contained plugin and skill for scraping YouTube transcripts, video metadata, comment threads, and downloading media/thumbnails across videos, live streams, shorts, and full channels."
|
|
4
|
+
triggers:
|
|
5
|
+
- youtube.com
|
|
6
|
+
- youtu.be
|
|
7
|
+
- youtube transcript
|
|
8
|
+
- youtube metadata
|
|
9
|
+
- youtube comments
|
|
10
|
+
- download youtube
|
|
11
|
+
- download video
|
|
12
|
+
- youtube live stream
|
|
13
|
+
- youtube shorts
|
|
14
|
+
- youtube channel scrape
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# YouTube Scrape Plugin & Skill
|
|
18
|
+
|
|
19
|
+
## Overview
|
|
20
|
+
This plugin executes high-speed, cost-effective, zero-browser, and zero-cookie scraping of:
|
|
21
|
+
- **Transcripts**: Full text and timestamped segments for videos, live streams, and shorts.
|
|
22
|
+
- **Video Metadata**: View counts, like counts, descriptions, upload date, duration, and tags.
|
|
23
|
+
- **Comments**: Top comment threads, reply counts, authors, likes, and timestamps.
|
|
24
|
+
- **Media & Thumbnails**: Direct downloads for MP4 video (360p to 4K), audio, and high-res thumbnails.
|
|
25
|
+
- **Channel Discovery**: Full channel scraping across `/videos`, `/streams`, and `/shorts`.
|
|
26
|
+
|
|
27
|
+
All disk outputs are organized into structured directories inside `plugins/youtube-scrape/Outputs/`:
|
|
28
|
+
- `Outputs/videos/<video_id>/`
|
|
29
|
+
- `Outputs/shorts/<short_id>/`
|
|
30
|
+
- `Outputs/live/<live_id>/`
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 🛑 Zero-Assumption & Clarification Protocol (MANDATORY FOR AI AGENTS)
|
|
35
|
+
|
|
36
|
+
**STRICT RULE**: When triggered by a user, the AI Agent **MUST NOT ASSUME** or guess parameters if they are underspecified. The agent must first ask the user to clarify:
|
|
37
|
+
|
|
38
|
+
### 1. Source Identification:
|
|
39
|
+
- Is this a **Single Video / Short / Live stream**, a **Bulk List** (pasted or in a file), or a **YouTube Channel**?
|
|
40
|
+
|
|
41
|
+
### 2. Feature & Output Scope:
|
|
42
|
+
- What does the user need?
|
|
43
|
+
- **In-Memory Transcript Only** (Zero disk writes, fast `--stdout` pipe for reasoning).
|
|
44
|
+
- **Structured Data Bundle** (Transcript + Metadata + Comments saved into `Outputs/`).
|
|
45
|
+
- **Media Download** (Do they want the actual `.mp4` video file or thumbnail downloaded?).
|
|
46
|
+
- **Full Suite** (`--all`: Transcript + Metadata + Comments + Thumbnail + Video).
|
|
47
|
+
|
|
48
|
+
### 3. Video Resolution (If Video Download is Requested):
|
|
49
|
+
- What quality/resolution does the user want?
|
|
50
|
+
- `best` (highest available), `1080p` (Full HD), `720p` (HD), `480p`, `360p`, or `4k`.
|
|
51
|
+
|
|
52
|
+
### 4. Channel Scope (If Channel URL is Given):
|
|
53
|
+
- Which tab to fetch: `/videos` (long-form), `/streams` (live broadcasts), `/shorts`, or `all`?
|
|
54
|
+
- How many videos to scrape (`--limit N`, default: 10)?
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## ⚡ Execution Modes & Commands
|
|
59
|
+
|
|
60
|
+
### 1. In-Memory / Zero-Disk Execution (Preferred for Agent Analysis)
|
|
61
|
+
When an agent only needs to read or summarize content without saving files to disk:
|
|
62
|
+
```bash
|
|
63
|
+
python plugins/youtube-scrape/cli.py "<URL>" --stdout
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 2. Single Video Scrapes (Saved to `Outputs/`)
|
|
67
|
+
```bash
|
|
68
|
+
# Full complete suite (Transcript + Metadata + Comments + Thumbnail + Video)
|
|
69
|
+
python plugins/youtube-scrape/cli.py "<URL>" --all
|
|
70
|
+
|
|
71
|
+
# Download MP4 Video at specific resolution (e.g. 1080p, 720p, 480p, 4k)
|
|
72
|
+
python plugins/youtube-scrape/cli.py "<URL>" --no-transcript --download-video --resolution 1080p
|
|
73
|
+
|
|
74
|
+
# Metadata & Comments only
|
|
75
|
+
python plugins/youtube-scrape/cli.py "<URL>" --no-transcript --metadata --comments --max-comments 50
|
|
76
|
+
|
|
77
|
+
# Fast Transcript Only
|
|
78
|
+
python plugins/youtube-scrape/cli.py "<URL>"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 3. Channel Extraction
|
|
82
|
+
```bash
|
|
83
|
+
# Scrape latest 10 regular long-form videos
|
|
84
|
+
python plugins/youtube-scrape/cli.py --channel "https://www.youtube.com/@ChannelName" --type videos --limit 10
|
|
85
|
+
|
|
86
|
+
# Scrape latest 5 Live streams
|
|
87
|
+
python plugins/youtube-scrape/cli.py --channel "https://www.youtube.com/@ChannelName" --type streams --limit 5
|
|
88
|
+
|
|
89
|
+
# Scrape latest 20 YouTube Shorts
|
|
90
|
+
python plugins/youtube-scrape/cli.py --channel "https://www.youtube.com/@ChannelName" --type shorts --limit 20
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 4. Bulk Batch Processing
|
|
94
|
+
```bash
|
|
95
|
+
python plugins/youtube-scrape/run_batch.py
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 5. Interactive Wizard Mode (For Manual Teammates)
|
|
99
|
+
```bash
|
|
100
|
+
python plugins/youtube-scrape/cli.py -i
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 6. Programmatic Python SDK (`core.py`)
|
|
104
|
+
```python
|
|
105
|
+
import sys
|
|
106
|
+
from pathlib import Path
|
|
107
|
+
|
|
108
|
+
sys.path.insert(0, str(Path("plugins/youtube-scrape").resolve()))
|
|
109
|
+
import core
|
|
110
|
+
|
|
111
|
+
# In-memory extraction (Zero disk writes)
|
|
112
|
+
transcript = core.get_transcript("VIDEO_ID")
|
|
113
|
+
metadata = core.get_video_metadata("VIDEO_ID")
|
|
114
|
+
comments = core.get_video_comments("VIDEO_ID", max_comments=30)
|
|
115
|
+
```
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
"""
|
|
2
|
+
YouTube Universal Scraper CLI (`cli.py`)
|
|
3
|
+
Interactive CLI and command-line entrypoint for youtube-scrape.
|
|
4
|
+
Thin presentation layer that imports pure functions from core.py.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
import argparse
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import List, Dict, Any
|
|
12
|
+
|
|
13
|
+
# Ensure UTF-8 console output on Windows
|
|
14
|
+
sys.stdout.reconfigure(encoding="utf-8")
|
|
15
|
+
|
|
16
|
+
PLUGIN_DIR = Path(__file__).parent.resolve()
|
|
17
|
+
try:
|
|
18
|
+
from plugins.shared.paths import get_plugin_outputs_dir
|
|
19
|
+
except ImportError:
|
|
20
|
+
_shared_parent = str(PLUGIN_DIR.parent.resolve())
|
|
21
|
+
if _shared_parent not in sys.path:
|
|
22
|
+
sys.path.insert(0, _shared_parent)
|
|
23
|
+
from shared.paths import get_plugin_outputs_dir
|
|
24
|
+
|
|
25
|
+
DEFAULT_OUTPUTS_DIR = get_plugin_outputs_dir(PLUGIN_DIR)
|
|
26
|
+
|
|
27
|
+
# Import pure logic from core.py
|
|
28
|
+
try:
|
|
29
|
+
from core import (
|
|
30
|
+
extract_video_id,
|
|
31
|
+
get_content_type,
|
|
32
|
+
get_transcript,
|
|
33
|
+
get_video_metadata,
|
|
34
|
+
get_video_comments,
|
|
35
|
+
download_media,
|
|
36
|
+
get_channel_videos,
|
|
37
|
+
scrape_youtube_item,
|
|
38
|
+
validate_output_dir,
|
|
39
|
+
validate_youtube_url,
|
|
40
|
+
)
|
|
41
|
+
except ImportError:
|
|
42
|
+
sys.path.insert(0, str(PLUGIN_DIR))
|
|
43
|
+
from core import (
|
|
44
|
+
extract_video_id,
|
|
45
|
+
get_content_type,
|
|
46
|
+
get_transcript,
|
|
47
|
+
get_video_metadata,
|
|
48
|
+
get_video_comments,
|
|
49
|
+
download_media,
|
|
50
|
+
get_channel_videos,
|
|
51
|
+
scrape_youtube_item,
|
|
52
|
+
validate_output_dir,
|
|
53
|
+
validate_youtube_url,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def run_interactive_wizard():
|
|
58
|
+
"""Interactive CLI parameter discovery wizard for non-technical users."""
|
|
59
|
+
print("=" * 65)
|
|
60
|
+
print(" 🎬 YouTube Universal Scraper & Downloader Wizard")
|
|
61
|
+
print("=" * 65)
|
|
62
|
+
print("\nSelect Source Type:")
|
|
63
|
+
print(" [1] Single Video / YouTube Live / YouTube Shorts URL")
|
|
64
|
+
print(" [2] Bulk URL List (File or Comma-separated)")
|
|
65
|
+
print(" [3] YouTube Channel URL (Extract Videos, Streams, or Shorts)")
|
|
66
|
+
|
|
67
|
+
choice = input("\nEnter choice [1-3] (default: 1): ").strip() or "1"
|
|
68
|
+
items_to_process: List[Dict[str, str]] = []
|
|
69
|
+
|
|
70
|
+
if choice == "1":
|
|
71
|
+
url = input("\nEnter YouTube Video, Live, or Shorts URL: ").strip()
|
|
72
|
+
if not url:
|
|
73
|
+
print("No URL provided. Exiting.")
|
|
74
|
+
sys.exit(1)
|
|
75
|
+
vid = extract_video_id(url)
|
|
76
|
+
ctype = get_content_type(url)
|
|
77
|
+
items_to_process.append({"id": vid, "title": "", "type": ctype, "url": url})
|
|
78
|
+
|
|
79
|
+
elif choice == "2":
|
|
80
|
+
file_or_list = input("\nEnter path to URL file (or paste comma-separated URLs): ").strip()
|
|
81
|
+
if not file_or_list:
|
|
82
|
+
print("No input provided. Exiting.")
|
|
83
|
+
sys.exit(1)
|
|
84
|
+
if os.path.exists(file_or_list):
|
|
85
|
+
with open(file_or_list, "r", encoding="utf-8") as f:
|
|
86
|
+
lines = [line.strip() for line in f if line.strip() and not line.startswith("#")]
|
|
87
|
+
else:
|
|
88
|
+
lines = [u.strip() for u in file_or_list.split(",") if u.strip()]
|
|
89
|
+
|
|
90
|
+
for u in lines:
|
|
91
|
+
vid = extract_video_id(u)
|
|
92
|
+
ctype = get_content_type(u)
|
|
93
|
+
items_to_process.append({"id": vid, "title": "", "type": ctype, "url": u})
|
|
94
|
+
|
|
95
|
+
elif choice == "3":
|
|
96
|
+
channel_url = input("\nEnter Channel URL or Handle (e.g. https://www.youtube.com/@ChannelName): ").strip()
|
|
97
|
+
if not channel_url:
|
|
98
|
+
print("No channel URL provided. Exiting.")
|
|
99
|
+
sys.exit(1)
|
|
100
|
+
|
|
101
|
+
print("\nSelect Content Type to fetch from Channel:")
|
|
102
|
+
print(" [1] Standard Long-form Videos (/videos)")
|
|
103
|
+
print(" [2] Live Streams (/streams)")
|
|
104
|
+
print(" [3] YouTube Shorts (/shorts)")
|
|
105
|
+
print(" [4] All Content Types")
|
|
106
|
+
type_choice = input("Enter choice [1-4] (default: 1): ").strip() or "1"
|
|
107
|
+
type_map = {"1": "videos", "2": "streams", "3": "shorts", "4": "all"}
|
|
108
|
+
selected_type = type_map.get(type_choice, "videos")
|
|
109
|
+
|
|
110
|
+
limit_str = input("\nEnter maximum number of videos to fetch (default: 10): ").strip() or "10"
|
|
111
|
+
try:
|
|
112
|
+
limit = int(limit_str)
|
|
113
|
+
except ValueError:
|
|
114
|
+
limit = 10
|
|
115
|
+
|
|
116
|
+
try:
|
|
117
|
+
items_to_process = get_channel_videos(channel_url, content_type=selected_type, limit=limit)
|
|
118
|
+
print(f"\n[+] Found {len(items_to_process)} matching items from channel.")
|
|
119
|
+
except Exception as e:
|
|
120
|
+
print(f"\n[!] Input error: {e}")
|
|
121
|
+
sys.exit(1)
|
|
122
|
+
|
|
123
|
+
if not items_to_process:
|
|
124
|
+
print("No items found to extract. Exiting.")
|
|
125
|
+
sys.exit(0)
|
|
126
|
+
|
|
127
|
+
print("\nSelect Extraction Mode:")
|
|
128
|
+
print(" [1] Transcript & Metadata (Fast)")
|
|
129
|
+
print(" [2] Transcript Only")
|
|
130
|
+
print(" [3] Metadata & Comments")
|
|
131
|
+
print(" [4] Download Video Media & Thumbnail")
|
|
132
|
+
print(" [5] Full Complete Suite (Transcript + Metadata + Comments + Thumbnail)")
|
|
133
|
+
|
|
134
|
+
mode_choice = input("Enter choice [1-5] (default: 1): ").strip() or "1"
|
|
135
|
+
|
|
136
|
+
fetch_transcript = mode_choice in ("1", "2", "5")
|
|
137
|
+
fetch_metadata = mode_choice in ("1", "3", "5")
|
|
138
|
+
fetch_comments = mode_choice in ("3", "5")
|
|
139
|
+
download_video = mode_choice in ("4", "5")
|
|
140
|
+
download_thumb = mode_choice in ("4", "5")
|
|
141
|
+
|
|
142
|
+
video_quality = "best"
|
|
143
|
+
if download_video:
|
|
144
|
+
print("\nSelect Video Resolution / Quality:")
|
|
145
|
+
print(" [1] Best Available (Default)")
|
|
146
|
+
print(" [2] 1080p Full HD")
|
|
147
|
+
print(" [3] 720p HD")
|
|
148
|
+
print(" [4] 480p SD")
|
|
149
|
+
print(" [5] 360p Low Bandwidth")
|
|
150
|
+
print(" [6] 4K Ultra HD (2160p)")
|
|
151
|
+
res_choice = input("Enter choice [1-6] (default: 1): ").strip() or "1"
|
|
152
|
+
res_map = {"1": "best", "2": "1080p", "3": "720p", "4": "480p", "5": "360p", "6": "4k"}
|
|
153
|
+
video_quality = res_map.get(res_choice, "best")
|
|
154
|
+
|
|
155
|
+
out_dir_str = input(f"\nEnter output directory (default: '{DEFAULT_OUTPUTS_DIR}'): ").strip() or str(DEFAULT_OUTPUTS_DIR)
|
|
156
|
+
try:
|
|
157
|
+
out_dir = validate_output_dir(out_dir_str)
|
|
158
|
+
except ValueError as e:
|
|
159
|
+
print(f"\n[!] Directory error: {e}")
|
|
160
|
+
sys.exit(1)
|
|
161
|
+
|
|
162
|
+
print("\n" + "=" * 65)
|
|
163
|
+
print(f" Starting extraction of {len(items_to_process)} items -> '{out_dir}'")
|
|
164
|
+
print("=" * 65)
|
|
165
|
+
|
|
166
|
+
total = len(items_to_process)
|
|
167
|
+
for idx, item in enumerate(items_to_process, 1):
|
|
168
|
+
vid = item["id"]
|
|
169
|
+
ctype = item.get("type", "videos")
|
|
170
|
+
title = item.get("title", "")
|
|
171
|
+
print(f"\n[{idx}/{total}] Processing [{ctype.upper()}]: {title or vid} (ID: {vid})...")
|
|
172
|
+
|
|
173
|
+
res = scrape_youtube_item(
|
|
174
|
+
url_or_id=item.get("url") or vid,
|
|
175
|
+
output_base_dir=out_dir,
|
|
176
|
+
content_type=ctype,
|
|
177
|
+
fetch_transcript=fetch_transcript,
|
|
178
|
+
fetch_metadata=fetch_metadata,
|
|
179
|
+
fetch_comments=fetch_comments,
|
|
180
|
+
download_video_file=download_video,
|
|
181
|
+
download_thumb_file=download_thumb,
|
|
182
|
+
video_quality=video_quality,
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
if res["status"] == "success":
|
|
186
|
+
print(f" [+] Saved bundle to: {res['item_directory']}")
|
|
187
|
+
if res.get("transcript") and res["transcript"]["status"] == "success":
|
|
188
|
+
words = len(res["transcript"]["text"].split())
|
|
189
|
+
print(f" - Transcript: {words} words")
|
|
190
|
+
if res.get("metadata") and res["metadata"].get("status") == "success":
|
|
191
|
+
print(f" - Metadata: Views={res['metadata'].get('view_count', 0)}, Likes={res['metadata'].get('like_count', 0)}")
|
|
192
|
+
if res.get("comments") and res["comments"].get("status") == "success":
|
|
193
|
+
print(f" - Comments: {res['comments'].get('count', 0)} comments scraped")
|
|
194
|
+
if res.get("media") and res["media"].get("status") == "success":
|
|
195
|
+
if res["media"].get("video_path"):
|
|
196
|
+
print(f" - Media: Downloaded video file")
|
|
197
|
+
if res["media"].get("thumbnail_path"):
|
|
198
|
+
print(f" - Media: Downloaded thumbnail")
|
|
199
|
+
else:
|
|
200
|
+
print(f" [!] Errors encountered: {', '.join(res.get('errors', []))}")
|
|
201
|
+
|
|
202
|
+
print("\n" + "=" * 65)
|
|
203
|
+
print(" Extraction & Download Complete!")
|
|
204
|
+
print(f" Check '{out_dir}' for results.")
|
|
205
|
+
print("=" * 65)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def main():
|
|
209
|
+
parser = argparse.ArgumentParser(
|
|
210
|
+
description="YouTube Universal Scraper & Downloader CLI Plugin."
|
|
211
|
+
)
|
|
212
|
+
parser.add_argument("url", nargs="?", help="Single YouTube video/live/shorts URL or ID.")
|
|
213
|
+
parser.add_argument("--channel", "-c", type=str, help="YouTube Channel URL or handle.")
|
|
214
|
+
parser.add_argument("--type", "-t", choices=["videos", "streams", "live", "shorts", "all"], default="videos")
|
|
215
|
+
parser.add_argument("--limit", "-l", type=int, default=10, help="Maximum videos to fetch from channel.")
|
|
216
|
+
parser.add_argument("--file", "-f", type=str, help="Path to text file containing URLs.")
|
|
217
|
+
parser.add_argument("--output-dir", "-o", type=str, default=str(DEFAULT_OUTPUTS_DIR), help="Output base directory.")
|
|
218
|
+
|
|
219
|
+
# Feature flags
|
|
220
|
+
parser.add_argument("--transcript", action="store_true", default=True, help="Extract transcript (default: True).")
|
|
221
|
+
parser.add_argument("--no-transcript", dest="transcript", action="store_false", help="Skip transcript extraction.")
|
|
222
|
+
parser.add_argument("--metadata", "-m", action="store_true", help="Extract video metadata.")
|
|
223
|
+
parser.add_argument("--comments", action="store_true", help="Extract video comments.")
|
|
224
|
+
parser.add_argument("--max-comments", type=int, default=50, help="Max comments to extract (default: 50).")
|
|
225
|
+
parser.add_argument("--download-media", "--download-video", dest="download_media", action="store_true", help="Download video media file (.mp4).")
|
|
226
|
+
parser.add_argument("--download-thumb", action="store_true", help="Download video thumbnail.")
|
|
227
|
+
parser.add_argument("--resolution", "--quality", "-q", dest="resolution", choices=["360p", "480p", "720p", "1080p", "1440p", "2160p", "4k", "best", "worst"], default="best", help="Video download resolution/quality (default: best).")
|
|
228
|
+
parser.add_argument("--all", "-a", action="store_true", help="Extract EVERYTHING (Transcript + Metadata + Comments + Thumbnail + Video Media).")
|
|
229
|
+
|
|
230
|
+
# Console flags
|
|
231
|
+
parser.add_argument("--stdout", action="store_true", help="Print raw transcript directly to console (single item only).")
|
|
232
|
+
parser.add_argument("--no-sandbox", action="store_true", help="Disable XML sandboxing tags (<transcript>) around output text.")
|
|
233
|
+
parser.add_argument("--interactive", "-i", action="store_true", help="Run interactive parameter wizard.")
|
|
234
|
+
|
|
235
|
+
args = parser.parse_args()
|
|
236
|
+
|
|
237
|
+
if args.interactive:
|
|
238
|
+
run_interactive_wizard()
|
|
239
|
+
return
|
|
240
|
+
|
|
241
|
+
# Check for feature overrides
|
|
242
|
+
fetch_transcript = args.transcript
|
|
243
|
+
fetch_metadata = args.metadata or args.all
|
|
244
|
+
fetch_comments = args.comments or args.all
|
|
245
|
+
download_video = args.download_media or args.all
|
|
246
|
+
download_thumb = args.download_thumb or args.all
|
|
247
|
+
video_quality = args.resolution
|
|
248
|
+
|
|
249
|
+
items_to_process: List[Dict[str, str]] = []
|
|
250
|
+
|
|
251
|
+
if args.channel:
|
|
252
|
+
c_type = "streams" if args.type == "live" else args.type
|
|
253
|
+
try:
|
|
254
|
+
print(f"[*] Discovering items from channel: {args.channel}...")
|
|
255
|
+
items_to_process = get_channel_videos(args.channel, content_type=c_type, limit=args.limit)
|
|
256
|
+
print(f"[+] Found {len(items_to_process)} items.")
|
|
257
|
+
except Exception as e:
|
|
258
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
259
|
+
sys.exit(1)
|
|
260
|
+
elif args.url:
|
|
261
|
+
vid = extract_video_id(args.url)
|
|
262
|
+
ctype = get_content_type(args.url)
|
|
263
|
+
items_to_process.append({"id": vid, "title": "", "type": ctype, "url": args.url})
|
|
264
|
+
elif args.file:
|
|
265
|
+
file_path = Path(args.file)
|
|
266
|
+
if not file_path.exists():
|
|
267
|
+
print(f"Error: File not found: {file_path}", file=sys.stderr)
|
|
268
|
+
sys.exit(1)
|
|
269
|
+
with open(file_path, "r", encoding="utf-8") as f:
|
|
270
|
+
for line in f:
|
|
271
|
+
clean = line.strip()
|
|
272
|
+
if clean and not clean.startswith("#"):
|
|
273
|
+
vid = extract_video_id(clean)
|
|
274
|
+
ctype = get_content_type(clean)
|
|
275
|
+
items_to_process.append({"id": vid, "title": "", "type": ctype, "url": clean})
|
|
276
|
+
else:
|
|
277
|
+
# Check default files
|
|
278
|
+
possible_defaults = [PLUGIN_DIR / "urls.txt", PLUGIN_DIR.parent.parent / "urls.txt"]
|
|
279
|
+
default_list = next((p for p in possible_defaults if p.exists()), None)
|
|
280
|
+
if default_list:
|
|
281
|
+
with open(default_list, "r", encoding="utf-8") as f:
|
|
282
|
+
for line in f:
|
|
283
|
+
clean = line.strip()
|
|
284
|
+
if clean and not clean.startswith("#"):
|
|
285
|
+
vid = extract_video_id(clean)
|
|
286
|
+
ctype = get_content_type(clean)
|
|
287
|
+
items_to_process.append({"id": vid, "title": "", "type": ctype, "url": clean})
|
|
288
|
+
|
|
289
|
+
if not items_to_process:
|
|
290
|
+
run_interactive_wizard()
|
|
291
|
+
return
|
|
292
|
+
|
|
293
|
+
if args.stdout and len(items_to_process) == 1:
|
|
294
|
+
vid = items_to_process[0]["id"]
|
|
295
|
+
res = get_transcript(vid)
|
|
296
|
+
if res["status"] == "success":
|
|
297
|
+
output_text = res["text"]
|
|
298
|
+
if not args.no_sandbox:
|
|
299
|
+
output_text = f"<transcript>\n{output_text}\n</transcript>"
|
|
300
|
+
print(output_text)
|
|
301
|
+
else:
|
|
302
|
+
print(f"Error: {res.get('error')}", file=sys.stderr)
|
|
303
|
+
sys.exit(1)
|
|
304
|
+
return
|
|
305
|
+
|
|
306
|
+
try:
|
|
307
|
+
out_dir = validate_output_dir(args.output_dir)
|
|
308
|
+
except ValueError as e:
|
|
309
|
+
print(f"Directory error: {e}", file=sys.stderr)
|
|
310
|
+
sys.exit(1)
|
|
311
|
+
|
|
312
|
+
print(f"[*] Processing {len(items_to_process)} items -> '{out_dir}'...")
|
|
313
|
+
for idx, item in enumerate(items_to_process, 1):
|
|
314
|
+
vid = item["id"]
|
|
315
|
+
ctype = item.get("type", "videos")
|
|
316
|
+
title = item.get("title", "")
|
|
317
|
+
print(f"[{idx}/{len(items_to_process)}] Scraping [{ctype.upper()}]: {title or vid} ({vid})...")
|
|
318
|
+
res = scrape_youtube_item(
|
|
319
|
+
url_or_id=item.get("url") or vid,
|
|
320
|
+
output_base_dir=out_dir,
|
|
321
|
+
content_type=ctype,
|
|
322
|
+
fetch_transcript=fetch_transcript,
|
|
323
|
+
fetch_metadata=fetch_metadata,
|
|
324
|
+
fetch_comments=fetch_comments,
|
|
325
|
+
download_video_file=download_video,
|
|
326
|
+
download_thumb_file=download_thumb,
|
|
327
|
+
video_quality=video_quality,
|
|
328
|
+
max_comments=args.max_comments,
|
|
329
|
+
sandbox_transcript=not args.no_sandbox,
|
|
330
|
+
)
|
|
331
|
+
if res["status"] == "success":
|
|
332
|
+
print(f" -> Saved to: {res['item_directory']}")
|
|
333
|
+
else:
|
|
334
|
+
print(f" -> Issues: {', '.join(res.get('errors', []))}")
|
|
335
|
+
|
|
336
|
+
print(f"\n[+] Done! All items processed and saved to '{out_dir}'")
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
if __name__ == "__main__":
|
|
340
|
+
main()
|