@danhachuel/thunderbolt 0.6.66 → 0.6.67
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.
|
@@ -585,11 +585,64 @@ def _post_from_node(node: dict[str, Any]) -> dict[str, Any] | None:
|
|
|
585
585
|
}
|
|
586
586
|
|
|
587
587
|
|
|
588
|
+
def _fetch_posts_with_ytdlp(username: str, limit: int = 10) -> list[dict[str, Any]]:
|
|
589
|
+
"""Fetch public Instagram post metadata with the installed yt-dlp CLI."""
|
|
590
|
+
import subprocess
|
|
591
|
+
|
|
592
|
+
url = f'https://www.instagram.com/{username}/'
|
|
593
|
+
cmd = [
|
|
594
|
+
'yt-dlp', '--dump-json', '--no-download', '--flat-playlist',
|
|
595
|
+
'--playlist-end', str(max(1, int(limit))), url,
|
|
596
|
+
]
|
|
597
|
+
try:
|
|
598
|
+
result = subprocess.run(cmd, capture_output=True, text=True, timeout=30, check=False)
|
|
599
|
+
if result.returncode != 0:
|
|
600
|
+
print(f'yt-dlp erro para @{username}: {result.stderr.strip()}')
|
|
601
|
+
return []
|
|
602
|
+
posts: list[dict[str, Any]] = []
|
|
603
|
+
for line in result.stdout.splitlines():
|
|
604
|
+
if not line.strip():
|
|
605
|
+
continue
|
|
606
|
+
try:
|
|
607
|
+
data = json.loads(line)
|
|
608
|
+
except json.JSONDecodeError:
|
|
609
|
+
continue
|
|
610
|
+
post_id = str(data.get('id') or '').strip()
|
|
611
|
+
post_url = str(data.get('webpage_url') or data.get('url') or '').strip()
|
|
612
|
+
shortcode = post_id or (post_url.rstrip('/').split('/')[-1] if post_url else '')
|
|
613
|
+
if not shortcode and not post_id:
|
|
614
|
+
continue
|
|
615
|
+
timestamp = data.get('timestamp') or data.get('release_timestamp') or ''
|
|
616
|
+
thumbnail = str(data.get('thumbnail') or '').strip()
|
|
617
|
+
posts.append({
|
|
618
|
+
'id': post_id or shortcode,
|
|
619
|
+
'shortcode': shortcode,
|
|
620
|
+
'url': post_url or f'https://www.instagram.com/p/{shortcode}/',
|
|
621
|
+
'image_url': thumbnail,
|
|
622
|
+
'display_url': thumbnail,
|
|
623
|
+
'caption': str(data.get('description') or data.get('title') or '').strip(),
|
|
624
|
+
'published_at': timestamp,
|
|
625
|
+
'timestamp': timestamp,
|
|
626
|
+
'is_video': bool(data.get('vcodec') not in (None, 'none')),
|
|
627
|
+
})
|
|
628
|
+
posts = posts[:max(1, int(limit))]
|
|
629
|
+
print(f'yt-dlp sucesso para @{username}: {len(posts)} posts')
|
|
630
|
+
return posts
|
|
631
|
+
except Exception as exc:
|
|
632
|
+
print(f'yt-dlp exceção para @{username}: {exc}')
|
|
633
|
+
return []
|
|
634
|
+
|
|
635
|
+
|
|
588
636
|
def fetch_public_instagram_posts(source: str, limit: int = 10) -> IntegrationResult:
|
|
589
637
|
try:
|
|
590
638
|
reference = normalize_instagram_reference(source)
|
|
591
639
|
except ValueError as exc:
|
|
592
640
|
return IntegrationResult(False, str(exc), {})
|
|
641
|
+
if platform.system() == 'Windows':
|
|
642
|
+
ytdlp_posts = _fetch_posts_with_ytdlp(reference['username'], limit)
|
|
643
|
+
print(f'yt-dlp posts retornados para @{reference["username"]}: {len(ytdlp_posts)}')
|
|
644
|
+
if ytdlp_posts:
|
|
645
|
+
return IntegrationResult(True, f'{len(ytdlp_posts)} posts obtidos via yt-dlp', reference | {'posts': ytdlp_posts})
|
|
593
646
|
api_user = _fetch_web_profile_user(reference['username'])
|
|
594
647
|
if api_user:
|
|
595
648
|
api_posts: list[dict[str, Any]] = []
|
package/package.json
CHANGED