lci.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from .common import InfoExtractor
  2. from .wat import WatIE
  3. from ..utils import ExtractorError, int_or_none
  4. from ..utils.traversal import traverse_obj
  5. class LCIIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?(?:lci|tf1info)\.fr/(?:[^/?#]+/)+[\w-]+-(?P<id>\d+)\.html'
  7. _TESTS = [{
  8. 'url': 'https://www.tf1info.fr/replay-lci/videos/video-24h-pujadas-du-vendredi-24-mai-6708-2300831.html',
  9. 'info_dict': {
  10. 'id': '14113788',
  11. 'ext': 'mp4',
  12. 'title': '24H Pujadas du vendredi 24 mai 2024',
  13. 'thumbnail': 'https://photos.tf1.fr/1280/720/24h-pujadas-du-24-mai-2024-55bf2d-0@1x.jpg',
  14. 'upload_date': '20240524',
  15. 'duration': 6158,
  16. },
  17. 'params': {
  18. 'skip_download': True,
  19. },
  20. }, {
  21. 'url': 'https://www.tf1info.fr/politique/election-presidentielle-2022-second-tour-j-2-marine-le-pen-et-emmanuel-macron-en-interview-de-lci-vendredi-soir-2217486.html',
  22. 'info_dict': {
  23. 'id': '13875948',
  24. 'ext': 'mp4',
  25. 'title': 'md5:660df5481fd418bc3bbb0d070e6fdb5a',
  26. 'thumbnail': 'https://photos.tf1.fr/1280/720/presidentielle-2022-marine-le-pen-et-emmanuel-macron-invites-de-lci-ce-vendredi-9c0e73-e1a036-0@1x.jpg',
  27. 'upload_date': '20220422',
  28. 'duration': 33,
  29. },
  30. 'params': {
  31. 'skip_download': True,
  32. },
  33. }, {
  34. 'url': 'https://www.lci.fr/politique/election-presidentielle-2022-second-tour-j-2-marine-le-pen-et-emmanuel-macron-en-interview-de-lci-vendredi-soir-2217486.html',
  35. 'only_matching': True,
  36. }]
  37. def _real_extract(self, url):
  38. video_id = self._match_id(url)
  39. webpage = self._download_webpage(url, video_id)
  40. next_data = self._search_nextjs_data(webpage, video_id)
  41. wat_id = traverse_obj(next_data, (
  42. 'props', 'pageProps', 'page', 'tms', 'videos', {dict.keys}, ..., {int_or_none}, any))
  43. if wat_id is None:
  44. raise ExtractorError('Could not find wat_id')
  45. return self.url_result(f'wat:{wat_id}', WatIE, str(wat_id))