SPB Git

Repository Public

make_reel.py 6.3 KB 181 lines python

1#!/usr/bin/env python32# =============================================================================3#                  SP BOUCHER | SOFTWARE & RESEARCH4#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# PROJECT METADATA8# -----------------------------------------------------------------------------9# Project          : FB Ka Automation10# File             : reels/make_reel.py11# Description      : Enregistre un Reel vertical (720x1280) : navigation fluide12#                    sur un site Ka.13# Module           : reels14# Repository       : https://git.spboucher.ai/fb-ka-automation15# Created          : 2026-12-0116# Last Modified    : 2026-12-0117#18# =============================================================================19# AUTHOR & PROFESSIONAL AFFILIATION20# =============================================================================21#22# Author           : Simon-Pierre Boucher23# Position         : Professor of Finance24# Institution      : Université du Québec en Outaouais (UQO)25# Department       : Département des sciences administratives26# Organization     : SP Boucher27#28# Website          : https://spboucher.ai29# Git              : https://git.spboucher.ai30#31# =============================================================================32# OFFICIAL CONTACT DIRECTORY33# =============================================================================34#35# General          : info@spboucher.ai36# Professional     : contact@spboucher.ai37# Direct           : simon@spboucher.ai38# Research         : research@spboucher.ai39# Development      : dev@spboucher.ai40# Support          : support@spboucher.ai41# Security/Admin   : admin@spboucher.ai42# Notifications    : notifications@spboucher.ai43#44# Preferred Contact: contact@spboucher.ai45#46# =============================================================================47# COPYRIGHT & INTELLECTUAL PROPERTY48# =============================================================================49#50# Copyright (c) 202651# Simon-Pierre Boucher52#53# All rights reserved where applicable.54#55# This file is governed by the applicable project license,56# copyright notices, institutional agreements and relevant law.57#58# Unless expressly authorized by the applicable license or59# rights holder, copying, redistribution, sublicensing,60# publication and commercial exploitation are not permitted.61#62# Existing third-party rights and notices remain unaffected.63#64# =============================================================================65# CONFIDENTIALITY & SECURITY66# =============================================================================67#68# Classification   : Public69# Distribution     : Public repository; use is governed by the project license70# Security Contact : admin@spboucher.ai71#72# Access to this source does not independently grant permission73# to redistribute or disclose confidential materials.74#75# Do not embed credentials, private keys, access tokens,76# certificates or confidential personal information.77#78# =============================================================================79# LICENSE & MAINTENANCE80# =============================================================================81#82# License          : None specified (no license file in this repository)83# Maintainer       : Simon-Pierre Boucher84# Technical Contact: dev@spboucher.ai85#86# =============================================================================87# END OF SP BOUCHER SOURCE HEADER88# =============================================================================8990"""Enregistre un Reel vertical (720x1280) : navigation fluide sur un site Ka."""91import sys, time, subprocess, pathlib9293site = sys.argv[1]           # ex: lou-ka94url = f"https://www.{site}.com"95outdir = pathlib.Path("/tmp/ka_reels")96outdir.mkdir(exist_ok=True)9798from playwright.sync_api import sync_playwright99100def dismiss_consent(page):101    try:102        page.evaluate("""103(() => {104  const rx = /accepter|j'accepte|tout accepter|^ok$|compris/i;105  let clicked = false;106  document.querySelectorAll('button,[role=button]').forEach(b => {107    const t = (b.innerText || '').trim();108    if (!clicked && rx.test(t)) { b.click(); clicked = true; }109  });110  if (!clicked) {111    document.querySelectorAll('div,section,aside').forEach(e => {112      const s = getComputedStyle(e);113      if ((s.position === 'fixed' || s.position === 'sticky') && /témoins|cookies/i.test(e.innerText || '')114          && e.innerText.length < 600) e.style.display = 'none';115    });116  }117})()118""")119        time.sleep(0.8)120    except Exception:121        pass122123124def smooth_scroll(page, total_px, step=12, delay=0.016):125    scrolled = 0126    while scrolled < total_px:127        page.evaluate(f"window.scrollBy(0,{step})")128        scrolled += step129        time.sleep(delay)130131with sync_playwright() as p:132    browser = p.chromium.launch()133    ctx = browser.new_context(134        viewport={"width": 720, "height": 1280},135        record_video_dir=str(outdir / "raw"),136        record_video_size={"width": 720, "height": 1280},137        device_scale_factor=2,138        user_agent="Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1",139        is_mobile=True,140        has_touch=True,141    )142    page = ctx.new_page()143144    # 1) Accueil — pause puis défilement doux145    page.goto(url, wait_until="load", timeout=45000)146    time.sleep(4)147    dismiss_consent(page)148    smooth_scroll(page, 2400)149    time.sleep(2)150151    # 2) Page stats — pause sur les cartes puis défilement152    try:153        page.goto(url + "/stats", wait_until="load", timeout=45000)154        time.sleep(5)155        dismiss_consent(page)156        smooth_scroll(page, 2000)157        time.sleep(2)158    except Exception as e:159        print("stats skip:", e)160161    # 3) Retour visuel en haut de l'accueil pour finir sur la marque162    page.goto(url, wait_until="load", timeout=45000)163    dismiss_consent(page)164    time.sleep(3)165166    video = page.video167    ctx.close()168    webm = video.path()169    browser.close()170171mp4 = outdir / f"{site}.mp4"172subprocess.run([173    "ffmpeg", "-y", "-i", webm,174    "-c:v", "libx264", "-pix_fmt", "yuv420p", "-r", "30",175    "-vf", "scale=720:1280",176    "-movflags", "+faststart", "-an",177    str(mp4)178], check=True, capture_output=True)179pathlib.Path(webm).unlink(missing_ok=True)180print(f"OK {mp4}")181
Files main
Menu

Theme