(self, target, platform)
| 18558 | return [self._social_result("Instagram", username, info, img, 200, url, info.get("Status") != " Non Trovato")] |
| 18559 | |
| 18560 | def enhanced_scraper(self, target, platform): |
| 18561 | target_clean = target.strip() |
| 18562 | target_norm = target_clean.strip() |
| 18563 | share_payload = {} |
| 18564 | base = SOCIAL_MAP.get(platform, {"icon": "", "base": ""}) |
| 18565 | |
| 18566 | if platform == "Instagram": |
| 18567 | share_data = self._normalize_instagram_share_link(target_clean) |
| 18568 | share_payload = share_data.get("metadata", {}) |
| 18569 | share_query = str(share_data.get("query") or "").strip() |
| 18570 | if share_query and share_query != target_clean and share_query != target: |
| 18571 | target_clean = share_query |
| 18572 | if share_query: |
| 18573 | platform = "Instagram" |
| 18574 | |
| 18575 | def _coerce_results(raw): |
| 18576 | if raw is None: |
| 18577 | return [] |
| 18578 | if isinstance(raw, dict): |
| 18579 | return [dict(raw)] |
| 18580 | if not isinstance(raw, (list, tuple)): |
| 18581 | return [] |
| 18582 | out = [] |
| 18583 | for item in raw: |
| 18584 | if isinstance(item, dict): |
| 18585 | out.append(dict(item)) |
| 18586 | else: |
| 18587 | try: |
| 18588 | out.append(dict(item)) |
| 18589 | except Exception: |
| 18590 | continue |
| 18591 | return out |
| 18592 | |
| 18593 | if platform in SOCIAL_MAP: |
| 18594 | cache_key = f"{platform}|{target_norm.lower()}" |
| 18595 | cached = self._social_search_cache.get(cache_key) |
| 18596 | if isinstance(cached, dict) and cached.get("ts", 0) + self._social_search_cache_ttl >= time.time(): |
| 18597 | return _coerce_results(cached.get("results") or []) |
| 18598 | |
| 18599 | def _norm_for_lookup(s): |
| 18600 | # case-insensitive matching without losing original |
| 18601 | return (s or "").strip().lower() |
| 18602 | |
| 18603 | def _is_probable_handle_x(h): |
| 18604 | # X usernames are typically [A-Za-z0-9_], but we allow extra chars for "best effort" |
| 18605 | return bool(re.fullmatch(r"[A-Za-z0-9_]{1,32}", h or "")) |
| 18606 | |
| 18607 | def safe_str(val): |
| 18608 | if not val: return "" |
| 18609 | return str(val).replace('\n', ' | ').strip() |
| 18610 | |
| 18611 | if "t.me/" in target_clean or "telegram.me/" in target_clean: |
| 18612 | target_clean = target_clean.split('/')[-1].split('?')[0] |
| 18613 | platform = "Telegram" |
| 18614 | elif target_clean.startswith('@') or (target_clean.isdigit() and len(target_clean) > 5 and platform == "Telegram"): |
| 18615 | if target_clean.startswith('@'): target_clean = target_clean[1:] |
| 18616 | platform = "Telegram" |
| 18617 |
no test coverage detected