#!/usr/bin/env python # -*- coding: utf-8 -*- # Recette Calibre — L'Équipe Premium # Auteur : Kabonix # Auth : eqn:EQN2014 (Basic ZXFuOkVRTjIwMTQ=) — extrait des DEX natifs de LEquipe v10.58.2 # API : https://dwh.lequipe.fr/api/v1/efr/news/{id} # Cover: scraping https://www.lequipe.fr/abonnement/kiosque/ → Twipe (id journal = 1627) from __future__ import absolute_import, division, print_function, unicode_literals import datetime import json import re import urllib.request from calibre.web.feeds.news import BasicNewsRecipe class LEquipePremium(BasicNewsRecipe): title = "L'Équipe" __author__ = 'Kabonix' description = "Articles abonnés L'Équipe avec notes de matchs complètes" publisher = "L'Équipe" publication_type = 'newspaper' language = 'fr' encoding = 'utf-8' oldest_article = 1 no_stylesheets = True ignore_duplicate_articles = {'title', 'url'} remove_empty_feeds = True auto_cleanup = False delay = 1 # ------------------------------------------------------------------ # # Auth — hardcodé dans les DEX natifs de l'APK # # ------------------------------------------------------------------ # browser_user_agent = 'MOBILE-LEQUIPE/android/phone/10.58.2/premium/wifi/test' auth_header = 'Basic ZXFuOkVRTjIwMTQ=' # eqn:EQN2014 # ------------------------------------------------------------------ # # Couverture dynamique — scraping page kiosque Twipe # # ID fixe du titre "L'Équipe journal" chez Twipe : 1627 # # ------------------------------------------------------------------ # def get_cover_url(self): try: req = urllib.request.Request('https://www.lequipe.fr/abonnement/kiosque/', headers={'User-Agent': 'Mozilla/5.0'}) html = urllib.request.urlopen(req, timeout=10).read().decode('utf-8') m = re.search( r'https://eqp-eqp-webreader-production\.twipemobile\.com' r'/data/1627/covers/Preview-MEDIUM-\d+\.jpg[^"&]*', html, ) if m: return m.group(0) except Exception: pass # Fallback : miniature journal par date today = datetime.datetime.now().strftime('%Y%m%d') return f'https://www.lequipe.fr/thumbnail/journal/{today}/1000/1490' # ------------------------------------------------------------------ # # Browser avec headers d'auth # # ------------------------------------------------------------------ # def get_browser(self, *args, **kwargs): br = BasicNewsRecipe.get_browser(self, *args, **kwargs) br.addheaders = [ ('User-Agent', self.browser_user_agent), ('Authorization', self.auth_header), ('Accept', 'application/json'), ] return br # ------------------------------------------------------------------ # # Filtre RSS → URL API # # Seuls les /Article/ sont premium ; /Actualites/ = brèves gratuites # # ------------------------------------------------------------------ # def get_article_url(self, article): url = BasicNewsRecipe.get_article_url(self, article) if not url: return None # Supprimer le fragment #at_medium=RSS_feeds url = url.split('#')[0] if '/Article/' not in url: return None m = re.search(r'/(\d+)$', url) if m: return f'https://dwh.lequipe.fr/api/v1/efr/news/{m.group(1)}' return None # ------------------------------------------------------------------ # # Bloc notes de match # # data_url → JSON Twipe avec titulaires, remplaçants, notes # # ------------------------------------------------------------------ # def parse_playing_field(self, data_url): try: req = urllib.request.Request(data_url, headers={'User-Agent': self.browser_user_agent}) raw = urllib.request.urlopen(req, timeout=10).read().decode('utf-8') d = json.loads(raw) except Exception: return '' html = '
| {e1["nom"]} | ' f'' f'{e1["score"]} – {e2["score"]} | ' f'{e2["nom"]} | ' f'
| Note : {e1["note"]} | ' f'' f' | Note : {e2["note"]} | ' f'
| Joueur | ' f'Note | ' f'' f' |
|---|---|---|
| {nom}{buts} | ' f'{note} | ' f'{sortie} | ' f'
| ' f'{nom}{buts} (rempl. {remplace})' f' | ' f'{note} | ' f'{entree} | ' f'
| Entr. {entraineur.get("nom", "")} | ' f'' f'{entraineur.get("note", "-")} | ' f'' f' |
Arbitre : {arbitre.get("nom", "")} — Note : {arbitre.get("note", "-")}
' html += 'Erreur JSON
' title = '' image_html = '' body = '' for item in data.get('items', []): obj = item.get('objet', {}) obj_type = obj.get('__type', '') # --- En-tête article (titre + image) --- if obj_type == 'article_feature': title = obj.get('long_title', obj.get('title', '')) media = obj.get('media', {}) img_url = media.get('url', '') if img_url: img_url = img_url.replace('{width}', '800').replace('{height}', '600').replace('{quality}', '85') legende = media.get('legende', '') image_html = ( f'{self.strip_links(content)}
' elif layout == 'text': if ptitle: body += f'{self.strip_links(content)}
' elif layout == 'note': note_obj = p.get('note') if note_obj and note_obj.get('layout') == 'team': # Titre de section équipe (ex : "Chelsea — Note : 3,8") label = note_obj.get('label', '') rating = note_obj.get('rating_label', note_obj.get('rating', '')) color = note_obj.get('background_color', '#333') tcolor = note_obj.get('text_color', '#fff') body += f'| '
f' | '
f'' f'{self.strip_links(content)} | ' f'
{self.strip_links(content)}
' elif layout == 'playing_field': data_url = p.get('data', '') if data_url: body += self.parse_playing_field(data_url) elif layout == 'link': pass # on ignore les "lire aussi" # on ignore aussi layout_DFP / pub_DFP / pub return f'