SPB Git

Repository Public

main.py 7.9 KB 183 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : KA Apify Actors9# File             : ka-kick/src/main.py10# Module           : ka-kick11# Repository       : https://git.spboucher.ai/ka-apify-actors12# Created          : 2026-08-1813# Last Modified    : 2026-08-1814#15# =============================================================================16# AUTHOR & PROFESSIONAL AFFILIATION17# =============================================================================18#19# Author           : Simon-Pierre Boucher20# Position         : Professor of Finance21# Institution      : Université du Québec en Outaouais (UQO)22# Department       : Département des sciences administratives23# Organization     : SP Boucher24#25# Website          : https://spboucher.ai26# Git              : https://git.spboucher.ai27#28# =============================================================================29# OFFICIAL CONTACT DIRECTORY30# =============================================================================31#32# General          : info@spboucher.ai33# Professional     : contact@spboucher.ai34# Direct           : simon@spboucher.ai35# Research         : research@spboucher.ai36# Development      : dev@spboucher.ai37# Support          : support@spboucher.ai38# Security/Admin   : admin@spboucher.ai39# Notifications    : notifications@spboucher.ai40#41# Preferred Contact: contact@spboucher.ai42#43# =============================================================================44# COPYRIGHT & INTELLECTUAL PROPERTY45# =============================================================================46#47# Copyright (c) 202648# Simon-Pierre Boucher49#50# All rights reserved where applicable.51#52# This file is governed by the applicable project license,53# copyright notices, institutional agreements and relevant law.54#55# Unless expressly authorized by the applicable license or56# rights holder, copying, redistribution, sublicensing,57# publication and commercial exploitation are not permitted.58#59# Existing third-party rights and notices remain unaffected.60#61# =============================================================================62# CONFIDENTIALITY & SECURITY63# =============================================================================64#65# Classification   : Public66# Distribution     : Public repository; use is governed by the project license67# Security Contact : admin@spboucher.ai68#69# Access to this source does not independently grant permission70# to redistribute or disclose confidential materials.71#72# Do not embed credentials, private keys, access tokens,73# certificates or confidential personal information.74#75# =============================================================================76# LICENSE & MAINTENANCE77# =============================================================================78#79# License          : None specified (no license file in this repository)80# Maintainer       : Simon-Pierre Boucher81# Technical Contact: dev@spboucher.ai82#83# =============================================================================84# END OF SP BOUCHER SOURCE HEADER85# =============================================================================8687# ==============================================================================88# Author: Simon-Pierre Boucher <contact@spboucher.ai>89# File:   src/main.py (ka-kick)90# Desc:   Chaînes Kick détaillées via l'API publique /api/v2/channels/{slug}91#         (Cloudflare : proxy résidentiel + empreinte Chrome) : abonnés, badge,92#         live en cours, bio + LIENS SOCIAUX AUTO-DÉCLARÉS (instagram/twitter/93#         youtube/tiktok/facebook/discord → cross_link 0.90 côté crea-ka).94# ==============================================================================95from __future__ import annotations9697import asyncio98import json99100from apify import Actor101102from .net import Fetcher103104API_URL = "https://kick.com/api/v2/channels/{u}"105SOCIAL_KEYS = ("instagram", "twitter", "youtube", "tiktok", "facebook",106               "discord")107108109async def main() -> None:110    async with Actor:111        inp = await Actor.get_input() or {}112        usernames = [u.strip().lstrip("@").lower()113                     for u in (inp.get("usernames") or []) if u and u.strip()]114        proxy = await Actor.create_proxy_configuration(115            actor_proxy_input=inp.get("proxyConfiguration"))116        fetcher = Fetcher(proxy, delay=float(inp.get("requestDelay") or 1))117        sem = asyncio.Semaphore(int(inp.get("concurrency") or 3))118119        async def one(u: str) -> None:120            async with sem:121                miss = {"kind": "profile", "platform": "kick",122                        "username": u, "found": False}123                resp = None124                for attempt in range(3):  # mur Cloudflare → nouvelle IP125                    try:126                        resp = await fetcher.get(127                            API_URL.format(u=u), session_id=f"{u}k{attempt}",128                            headers={"Accept": "application/json"})129                    except Exception as exc:130                        await Actor.push_data({**miss,131                                               "error": str(exc)[:200]})132                        return133                    if resp.status_code == 404:134                        await Actor.push_data({**miss, "error": "http_404"})135                        return136                    if resp.status_code == 200 and \137                            (resp.text or "").startswith("{"):138                        break139                if resp.status_code != 200 or \140                        not (resp.text or "").startswith("{"):141                    await Actor.push_data(142                        {**miss, "error": f"http_{resp.status_code}"})143                    return144                try:145                    ch = json.loads(resp.text)146                except Exception:147                    await Actor.push_data({**miss, "error": "bad_json"})148                    return149                user = ch.get("user") or {}150                live = ch.get("livestream") or {}151                cats = [((c.get("category") or {}).get("name"))152                        for c in (ch.get("recent_categories") or [])153                        if isinstance(c, dict)]154                socials = {k: (user.get(k) or "").strip()155                           for k in SOCIAL_KEYS if (user.get(k) or "").strip()}156                await Actor.push_data({157                    "kind": "profile",158                    "platform": "kick",159                    "found": True,160                    "id": ch.get("id"),161                    "username": ch.get("slug"),162                    "full_name": user.get("username"),163                    "biography": user.get("bio"),164                    "followers": ch.get("followers_count")165                                 or ch.get("followersCount"),166                    "is_verified": bool(ch.get("verified")),167                    "is_banned": bool(ch.get("is_banned")),168                    "subscription_enabled": ch.get("subscription_enabled"),169                    "is_live_now": bool(live),170                    "live_viewers": live.get("viewer_count"),171                    "live_title": (live.get("session_title") or "")[:200]172                                  or None,173                    "avatar": user.get("profile_pic"),174                    "banner": ((ch.get("banner_image") or {}).get("url")175                               if isinstance(ch.get("banner_image"), dict)176                               else None),177                    "recent_categories": [c for c in cats if c][:5],178                    "social_links": socials,179                })180181        await asyncio.gather(*[one(u) for u in usernames])182        Actor.log.info(f"terminé : {len(usernames)} chaînes")183
Files main
Menu

Theme