@danhachuel/thunderbolt 0.6.66 → 0.6.68
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/integrations/instagram_public.py +89 -0
- package/package.json +1 -1
- package/requirements.txt +1 -0
- package/scripts/install.mjs +1 -1
|
@@ -585,11 +585,100 @@ def _post_from_node(node: dict[str, Any]) -> dict[str, Any] | None:
|
|
|
585
585
|
}
|
|
586
586
|
|
|
587
587
|
|
|
588
|
+
def _fetch_posts_with_instaloader(username: str, limit: int = 10) -> list[dict[str, Any]]:
|
|
589
|
+
"""Obtém os posts mais recentes de um perfil público usando Instaloader."""
|
|
590
|
+
print(f'Instaloader: tentando obter posts de @{username}')
|
|
591
|
+
try:
|
|
592
|
+
import instaloader
|
|
593
|
+
|
|
594
|
+
loader = instaloader.Instaloader()
|
|
595
|
+
profile = instaloader.Profile.from_username(loader.context, username)
|
|
596
|
+
posts: list[dict[str, Any]] = []
|
|
597
|
+
for post in profile.get_posts():
|
|
598
|
+
if len(posts) >= max(1, int(limit)):
|
|
599
|
+
break
|
|
600
|
+
timestamp = post.date_utc.timestamp() if post.date_utc else ''
|
|
601
|
+
post_url = str(post.url or '').strip()
|
|
602
|
+
shortcode = str(post.shortcode or '').strip()
|
|
603
|
+
posts.append({
|
|
604
|
+
'id': post.mediaid,
|
|
605
|
+
'shortcode': shortcode,
|
|
606
|
+
'url': f'https://www.instagram.com/p/{shortcode}/' if shortcode else post_url,
|
|
607
|
+
'image_url': post_url,
|
|
608
|
+
'display_url': post_url,
|
|
609
|
+
'caption': str(post.caption or '').strip(),
|
|
610
|
+
'published_at': timestamp,
|
|
611
|
+
'timestamp': timestamp,
|
|
612
|
+
'is_video': bool(getattr(post, 'is_video', False)),
|
|
613
|
+
})
|
|
614
|
+
print(f'Instaloader: {len(posts)} posts encontrados para @{username}')
|
|
615
|
+
return posts
|
|
616
|
+
except Exception as exc:
|
|
617
|
+
print(f'Instaloader falhou para @{username}: {exc}')
|
|
618
|
+
return []
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
def _fetch_posts_with_ytdlp(username: str, limit: int = 10) -> list[dict[str, Any]]:
|
|
622
|
+
"""Fetch public Instagram post metadata with the installed yt-dlp CLI."""
|
|
623
|
+
import subprocess
|
|
624
|
+
|
|
625
|
+
url = f'https://www.instagram.com/{username}/'
|
|
626
|
+
cmd = [
|
|
627
|
+
'yt-dlp', '--dump-json', '--no-download', '--flat-playlist',
|
|
628
|
+
'--playlist-end', str(max(1, int(limit))), url,
|
|
629
|
+
]
|
|
630
|
+
try:
|
|
631
|
+
result = subprocess.run(cmd, capture_output=True, text=True, timeout=30, check=False)
|
|
632
|
+
if result.returncode != 0:
|
|
633
|
+
print(f'yt-dlp erro para @{username}: {result.stderr.strip()}')
|
|
634
|
+
return []
|
|
635
|
+
posts: list[dict[str, Any]] = []
|
|
636
|
+
for line in result.stdout.splitlines():
|
|
637
|
+
if not line.strip():
|
|
638
|
+
continue
|
|
639
|
+
try:
|
|
640
|
+
data = json.loads(line)
|
|
641
|
+
except json.JSONDecodeError:
|
|
642
|
+
continue
|
|
643
|
+
post_id = str(data.get('id') or '').strip()
|
|
644
|
+
post_url = str(data.get('webpage_url') or data.get('url') or '').strip()
|
|
645
|
+
shortcode = post_id or (post_url.rstrip('/').split('/')[-1] if post_url else '')
|
|
646
|
+
if not shortcode and not post_id:
|
|
647
|
+
continue
|
|
648
|
+
timestamp = data.get('timestamp') or data.get('release_timestamp') or ''
|
|
649
|
+
thumbnail = str(data.get('thumbnail') or '').strip()
|
|
650
|
+
posts.append({
|
|
651
|
+
'id': post_id or shortcode,
|
|
652
|
+
'shortcode': shortcode,
|
|
653
|
+
'url': post_url or f'https://www.instagram.com/p/{shortcode}/',
|
|
654
|
+
'image_url': thumbnail,
|
|
655
|
+
'display_url': thumbnail,
|
|
656
|
+
'caption': str(data.get('description') or data.get('title') or '').strip(),
|
|
657
|
+
'published_at': timestamp,
|
|
658
|
+
'timestamp': timestamp,
|
|
659
|
+
'is_video': bool(data.get('vcodec') not in (None, 'none')),
|
|
660
|
+
})
|
|
661
|
+
posts = posts[:max(1, int(limit))]
|
|
662
|
+
print(f'yt-dlp sucesso para @{username}: {len(posts)} posts')
|
|
663
|
+
return posts
|
|
664
|
+
except Exception as exc:
|
|
665
|
+
print(f'yt-dlp exceção para @{username}: {exc}')
|
|
666
|
+
return []
|
|
667
|
+
|
|
668
|
+
|
|
588
669
|
def fetch_public_instagram_posts(source: str, limit: int = 10) -> IntegrationResult:
|
|
589
670
|
try:
|
|
590
671
|
reference = normalize_instagram_reference(source)
|
|
591
672
|
except ValueError as exc:
|
|
592
673
|
return IntegrationResult(False, str(exc), {})
|
|
674
|
+
if platform.system() == 'Windows':
|
|
675
|
+
instaloader_posts = _fetch_posts_with_instaloader(reference['username'], limit)
|
|
676
|
+
if instaloader_posts:
|
|
677
|
+
return IntegrationResult(True, f'{len(instaloader_posts)} posts obtidos via Instaloader', reference | {'posts': instaloader_posts})
|
|
678
|
+
ytdlp_posts = _fetch_posts_with_ytdlp(reference['username'], limit)
|
|
679
|
+
print(f'yt-dlp posts retornados para @{reference["username"]}: {len(ytdlp_posts)}')
|
|
680
|
+
if ytdlp_posts:
|
|
681
|
+
return IntegrationResult(True, f'{len(ytdlp_posts)} posts obtidos via yt-dlp', reference | {'posts': ytdlp_posts})
|
|
593
682
|
api_user = _fetch_web_profile_user(reference['username'])
|
|
594
683
|
if api_user:
|
|
595
684
|
api_posts: list[dict[str, Any]] = []
|
package/package.json
CHANGED
package/requirements.txt
CHANGED
package/scripts/install.mjs
CHANGED
|
@@ -481,7 +481,7 @@ function writeSettings(moneyprinterPath) {
|
|
|
481
481
|
|
|
482
482
|
function installThunderboltDependencies(python) {
|
|
483
483
|
if (!existsSync(pythonBin)) run(python.command, [...python.args, "-m", "venv", venvPath]);
|
|
484
|
-
installRequirementIfNeeded(join(root, "requirements.txt"), "thunderbolt_requirements_sha256", ["streamlit", "requests", "pandas", "toml", "imageio_ffmpeg", "edge_tts", "google.auth", "google_auth_oauthlib", "googleapiclient", "yt_dlp", "deno", "youtube_transcript_api", "huggingface_hub", "playwright"], "Thunderbolt");
|
|
484
|
+
installRequirementIfNeeded(join(root, "requirements.txt"), "thunderbolt_requirements_sha256", ["streamlit", "requests", "pandas", "toml", "imageio_ffmpeg", "edge_tts", "google.auth", "google_auth_oauthlib", "googleapiclient", "yt_dlp", "instaloader", "deno", "youtube_transcript_api", "huggingface_hub", "playwright"], "Thunderbolt");
|
|
485
485
|
installPlaywrightBrowsers();
|
|
486
486
|
}
|
|
487
487
|
|