@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,218 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Reddit Discussion Scraper CLI (`cli.py`)
|
|
3
|
+
Interactive wizard and command-line presentation layer for reddit-discussion-scraper.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
import json
|
|
9
|
+
import argparse
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Dict, Any
|
|
12
|
+
|
|
13
|
+
sys.stdout.reconfigure(encoding="utf-8")
|
|
14
|
+
PLUGIN_DIR = Path(__file__).parent.resolve()
|
|
15
|
+
try:
|
|
16
|
+
from plugins.shared.paths import get_plugin_outputs_dir
|
|
17
|
+
except ImportError:
|
|
18
|
+
_shared_parent = str(PLUGIN_DIR.parent.resolve())
|
|
19
|
+
if _shared_parent not in sys.path:
|
|
20
|
+
sys.path.insert(0, _shared_parent)
|
|
21
|
+
from shared.paths import get_plugin_outputs_dir
|
|
22
|
+
|
|
23
|
+
DEFAULT_OUTPUTS_DIR = get_plugin_outputs_dir(PLUGIN_DIR)
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
from core import (
|
|
27
|
+
parse_reddit_target,
|
|
28
|
+
get_subreddit_posts,
|
|
29
|
+
get_reddit_post_and_comments,
|
|
30
|
+
get_reddit_user_history,
|
|
31
|
+
search_reddit,
|
|
32
|
+
download_reddit_media,
|
|
33
|
+
)
|
|
34
|
+
except ImportError:
|
|
35
|
+
sys.path.insert(0, str(PLUGIN_DIR))
|
|
36
|
+
from core import (
|
|
37
|
+
parse_reddit_target,
|
|
38
|
+
get_subreddit_posts,
|
|
39
|
+
get_reddit_post_and_comments,
|
|
40
|
+
get_reddit_user_history,
|
|
41
|
+
search_reddit,
|
|
42
|
+
download_reddit_media,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def run_interactive_wizard():
|
|
47
|
+
print("=" * 65)
|
|
48
|
+
print(" š¤ Reddit Discussion Scraper & Media Downloader Wizard")
|
|
49
|
+
print("=" * 65)
|
|
50
|
+
print("\nSelect Option:")
|
|
51
|
+
print(" [1] Scrape Subreddit Feed (Hot, New, Top, Rising)")
|
|
52
|
+
print(" [2] Scrape Post & Nested Comments Tree")
|
|
53
|
+
print(" [3] Scrape User Posting & Comment History")
|
|
54
|
+
print(" [4] Keyword Search (Subreddit or Sitewide)")
|
|
55
|
+
print(" [5] Download Reddit Media / Video (v.redd.it MP4)")
|
|
56
|
+
print(" [6] Full Extraction Suite (--all)")
|
|
57
|
+
|
|
58
|
+
choice = input("\nEnter choice [1-6] (default: 1): ").strip() or "1"
|
|
59
|
+
|
|
60
|
+
if choice == "1":
|
|
61
|
+
sub = input("\nEnter Subreddit name or URL (e.g. 'sales' or 'r/electricians'): ").strip()
|
|
62
|
+
if not sub:
|
|
63
|
+
print("[!] No subreddit specified. Exiting.")
|
|
64
|
+
return
|
|
65
|
+
sort = input("Sort by [hot/new/top/rising] (default: hot): ").strip() or "hot"
|
|
66
|
+
time_filter = "all"
|
|
67
|
+
if sort == "top":
|
|
68
|
+
time_filter = input("Time window [day/week/month/year/all] (default: all): ").strip() or "all"
|
|
69
|
+
limit_str = input("Limit posts count [1-100] (default: 25): ").strip() or "25"
|
|
70
|
+
limit = int(limit_str) if limit_str.isdigit() else 25
|
|
71
|
+
|
|
72
|
+
print(f"\n[+] Fetching r/{sub} ({sort})...")
|
|
73
|
+
res = get_subreddit_posts(sub, sort=sort, time_filter=time_filter, limit=limit)
|
|
74
|
+
if res.get("status") == "success":
|
|
75
|
+
print(f"\nā
Fetched {res['count']} posts successfully!")
|
|
76
|
+
print(f"š¾ Saved to: {res.get('saved_path')}")
|
|
77
|
+
for idx, p in enumerate(res["posts"][:5], 1):
|
|
78
|
+
print(f" {idx}. [ā² {p['score']:,}] {p['title']} ({p['comments_count']} comments)")
|
|
79
|
+
else:
|
|
80
|
+
print(f"[!] Error: {res.get('error')}")
|
|
81
|
+
|
|
82
|
+
elif choice == "2":
|
|
83
|
+
target = input("\nEnter Reddit Post URL or ID: ").strip()
|
|
84
|
+
if not target:
|
|
85
|
+
print("[!] No post specified. Exiting.")
|
|
86
|
+
return
|
|
87
|
+
print(f"\n[+] Extracting Post & Comment Tree for: {target}...")
|
|
88
|
+
res = get_reddit_post_and_comments(target)
|
|
89
|
+
if res.get("status") == "success":
|
|
90
|
+
post = res.get("post", {})
|
|
91
|
+
print(f"\nā
Post Extracted:")
|
|
92
|
+
print(f" š Title: {post.get('title')}")
|
|
93
|
+
print(f" š¤ Author: u/{post.get('author')}")
|
|
94
|
+
print(f" ā² Score: {post.get('score'):,}")
|
|
95
|
+
print(f" š¬ Comments: {res.get('comments_count')} top-level threads extracted")
|
|
96
|
+
print(f" š¾ Saved to: {res.get('saved_path')}")
|
|
97
|
+
else:
|
|
98
|
+
print(f"[!] Error: {res.get('error')}")
|
|
99
|
+
|
|
100
|
+
elif choice == "3":
|
|
101
|
+
user = input("\nEnter Reddit Username (e.g. 'spez' or 'u/spez'): ").strip()
|
|
102
|
+
if not user:
|
|
103
|
+
print("[!] No username specified. Exiting.")
|
|
104
|
+
return
|
|
105
|
+
print(f"\n[+] Fetching user activity for {user}...")
|
|
106
|
+
res = get_reddit_user_history(user)
|
|
107
|
+
if res.get("status") == "success":
|
|
108
|
+
print(f"\nā
Extracted {res['count']} submissions/comments for u/{res['username']}")
|
|
109
|
+
print(f"š¾ Saved to: {res.get('saved_path')}")
|
|
110
|
+
else:
|
|
111
|
+
print(f"[!] Error: {res.get('error')}")
|
|
112
|
+
|
|
113
|
+
elif choice == "4":
|
|
114
|
+
query = input("\nEnter Search Query (e.g. 'AI automation recommendation'): ").strip()
|
|
115
|
+
sub = input("Restrict to Subreddit (optional, press Enter for sitewide): ").strip() or None
|
|
116
|
+
print(f"\n[+] Searching Reddit for '{query}'...")
|
|
117
|
+
res = search_reddit(query, subreddit=sub)
|
|
118
|
+
if res.get("status") == "success":
|
|
119
|
+
print(f"\nā
Found {res['count']} search results!")
|
|
120
|
+
print(f"š¾ Saved to: {res.get('saved_path')}")
|
|
121
|
+
else:
|
|
122
|
+
print(f"[!] Error: {res.get('error')}")
|
|
123
|
+
|
|
124
|
+
elif choice == "5":
|
|
125
|
+
target = input("\nEnter Reddit Post URL with Video/Media: ").strip()
|
|
126
|
+
print(f"\n[+] Downloading Media via yt-dlp...")
|
|
127
|
+
res = download_reddit_media(target)
|
|
128
|
+
if res.get("status") == "success":
|
|
129
|
+
print(f"\nā
Download complete!")
|
|
130
|
+
if res.get("video_path"):
|
|
131
|
+
print(f" š¬ Video saved: {res['video_path']}")
|
|
132
|
+
if res.get("thumbnail_path"):
|
|
133
|
+
print(f" š¼ļø Preview saved: {res['thumbnail_path']}")
|
|
134
|
+
else:
|
|
135
|
+
print(f"[!] Notice: {res.get('error')}")
|
|
136
|
+
|
|
137
|
+
elif choice == "6":
|
|
138
|
+
target = input("\nEnter Subreddit or Post URL: ").strip()
|
|
139
|
+
parsed = parse_reddit_target(target)
|
|
140
|
+
print(f"\n[+] Running Full Extraction Suite for {target}...")
|
|
141
|
+
if parsed["type"] == "subreddit":
|
|
142
|
+
feed = get_subreddit_posts(parsed["id"])
|
|
143
|
+
print(f"ā
Subreddit feed: {feed.get('saved_path')}")
|
|
144
|
+
elif parsed["type"] == "post":
|
|
145
|
+
tree = get_reddit_post_and_comments(parsed["url"])
|
|
146
|
+
media = download_reddit_media(parsed["url"])
|
|
147
|
+
print(f"ā
Comments & Media extracted:")
|
|
148
|
+
print(json.dumps({"discussion": tree, "media": media}, indent=2, default=str))
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def main():
|
|
152
|
+
parser = argparse.ArgumentParser(description="Reddit Discussion Scraper & Media Downloader CLI")
|
|
153
|
+
parser.add_argument("target", nargs="?", help="Subreddit name, Post URL, or Username")
|
|
154
|
+
parser.add_argument("-i", "--interactive", action="store_true", help="Launch interactive wizard")
|
|
155
|
+
parser.add_argument("--sort", default="hot", choices=["hot", "new", "top", "rising"], help="Feed sort")
|
|
156
|
+
parser.add_argument("--time", default="all", choices=["hour", "day", "week", "month", "year", "all"], help="Time window for top sort")
|
|
157
|
+
parser.add_argument("-l", "--limit", type=int, default=25, help="Number of items to extract")
|
|
158
|
+
parser.add_argument("--comments", action="store_true", help="Scrape full post comments tree")
|
|
159
|
+
parser.add_argument("--user", action="store_true", help="Extract user profile history")
|
|
160
|
+
parser.add_argument("--search", type=str, help="Execute keyword search")
|
|
161
|
+
parser.add_argument("--download-video", action="store_true", help="Download attached video (v.redd.it)")
|
|
162
|
+
parser.add_argument("--download-thumb", action="store_true", help="Download preview image")
|
|
163
|
+
parser.add_argument("-q", "--quality", default="best", choices=["best", "1080p", "720p", "480p"], help="Media quality")
|
|
164
|
+
parser.add_argument("--stdout", action="store_true", help="Output raw JSON to stdout")
|
|
165
|
+
parser.add_argument("--output-dir", "-o", type=str, default=str(DEFAULT_OUTPUTS_DIR), help="Output base directory.")
|
|
166
|
+
|
|
167
|
+
args = parser.parse_args()
|
|
168
|
+
if args.output_dir:
|
|
169
|
+
os.environ["SOCIALSCRAPE_OUTPUT_DIR"] = str(Path(args.output_dir).expanduser().resolve())
|
|
170
|
+
|
|
171
|
+
if args.interactive or (not args.target and not args.search):
|
|
172
|
+
run_interactive_wizard()
|
|
173
|
+
return
|
|
174
|
+
|
|
175
|
+
result = {}
|
|
176
|
+
|
|
177
|
+
if args.search:
|
|
178
|
+
result = search_reddit(args.search, subreddit=args.target, sort=args.sort, time_filter=args.time, limit=args.limit)
|
|
179
|
+
elif args.target:
|
|
180
|
+
parsed = parse_reddit_target(args.target)
|
|
181
|
+
|
|
182
|
+
if args.user or parsed["type"] == "user":
|
|
183
|
+
result = get_reddit_user_history(parsed["id"], limit=args.limit)
|
|
184
|
+
elif args.comments or parsed["type"] == "post":
|
|
185
|
+
result = get_reddit_post_and_comments(parsed["url"])
|
|
186
|
+
if args.download_video or args.download_thumb:
|
|
187
|
+
media_res = download_reddit_media(
|
|
188
|
+
parsed["url"],
|
|
189
|
+
download_video=args.download_video,
|
|
190
|
+
download_thumbnail=args.download_thumb,
|
|
191
|
+
quality=args.quality
|
|
192
|
+
)
|
|
193
|
+
result["media_download"] = media_res
|
|
194
|
+
else:
|
|
195
|
+
result = get_subreddit_posts(parsed["id"], sort=args.sort, time_filter=args.time, limit=args.limit)
|
|
196
|
+
if args.download_video or args.download_thumb:
|
|
197
|
+
media_res = download_reddit_media(
|
|
198
|
+
parsed["url"],
|
|
199
|
+
download_video=args.download_video,
|
|
200
|
+
download_thumbnail=args.download_thumb,
|
|
201
|
+
quality=args.quality
|
|
202
|
+
)
|
|
203
|
+
result["media_download"] = media_res
|
|
204
|
+
|
|
205
|
+
if args.stdout:
|
|
206
|
+
print(json.dumps(result, indent=2, default=str))
|
|
207
|
+
else:
|
|
208
|
+
status = result.get("status")
|
|
209
|
+
if status == "success":
|
|
210
|
+
print(f"ā
Extraction completed successfully!")
|
|
211
|
+
if "saved_path" in result:
|
|
212
|
+
print(f"š¾ File: {result['saved_path']}")
|
|
213
|
+
else:
|
|
214
|
+
print(f"[!] Notice: {result.get('error', 'Operation finished with warnings.')}")
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
if __name__ == "__main__":
|
|
218
|
+
main()
|