tf1.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import json
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. int_or_none,
  5. parse_iso8601,
  6. try_get,
  7. )
  8. class TF1IE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?tf1\.fr/[^/]+/(?P<program_slug>[^/]+)/videos/(?P<id>[^/?&#]+)\.html'
  10. _TESTS = [{
  11. 'url': 'https://www.tf1.fr/tmc/quotidien-avec-yann-barthes/videos/quotidien-premiere-partie-11-juin-2019.html',
  12. 'info_dict': {
  13. 'id': '13641379',
  14. 'ext': 'mp4',
  15. 'title': 'md5:f392bc52245dc5ad43771650c96fb620',
  16. 'description': 'md5:a02cdb217141fb2d469d6216339b052f',
  17. 'upload_date': '20190611',
  18. 'timestamp': 1560273989,
  19. 'duration': 1738,
  20. 'series': 'Quotidien avec Yann Barthès',
  21. 'tags': ['intégrale', 'quotidien', 'Replay'],
  22. },
  23. 'params': {
  24. # Sometimes wat serves the whole file with the --test option
  25. 'skip_download': True,
  26. },
  27. }, {
  28. 'url': 'https://www.tf1.fr/tmc/burger-quiz/videos/burger-quiz-du-19-aout-2023-s03-episode-21-85585666.html',
  29. 'info_dict': {
  30. 'id': '14010600',
  31. 'ext': 'mp4',
  32. 'title': 'Burger Quiz - S03 EP21 avec Eye Haidara, Anne Depétrini, Jonathan Zaccaï et Pio Marmaï',
  33. 'thumbnail': 'https://photos.tf1.fr/1280/720/burger-quiz-11-9adb79-0@1x.jpg',
  34. 'description': 'Manu Payet recevra Eye Haidara, Anne Depétrini, Jonathan Zaccaï et Pio Marmaï.',
  35. 'upload_date': '20230819',
  36. 'timestamp': 1692469471,
  37. 'season_number': 3,
  38. 'series': 'Burger Quiz',
  39. 'episode_number': 21,
  40. 'season': 'Season 3',
  41. 'tags': 'count:13',
  42. 'episode': 'Episode 21',
  43. 'duration': 2312,
  44. },
  45. 'params': {'skip_download': 'm3u8'},
  46. }, {
  47. 'url': 'http://www.tf1.fr/tf1/koh-lanta/videos/replay-koh-lanta-22-mai-2015.html',
  48. 'only_matching': True,
  49. }, {
  50. 'url': 'http://www.tf1.fr/hd1/documentaire/videos/mylene-farmer-d-une-icone.html',
  51. 'only_matching': True,
  52. }]
  53. def _real_extract(self, url):
  54. program_slug, slug = self._match_valid_url(url).groups()
  55. video = self._download_json(
  56. 'https://www.tf1.fr/graphql/web', slug, query={
  57. 'id': '9b80783950b85247541dd1d851f9cc7fa36574af015621f853ab111a679ce26f',
  58. 'variables': json.dumps({
  59. 'programSlug': program_slug,
  60. 'slug': slug,
  61. }),
  62. })['data']['videoBySlug']
  63. wat_id = video['streamId']
  64. tags = []
  65. for tag in (video.get('tags') or []):
  66. label = tag.get('label')
  67. if not label:
  68. continue
  69. tags.append(label)
  70. decoration = video.get('decoration') or {}
  71. thumbnails = []
  72. for source in (try_get(decoration, lambda x: x['image']['sources'], list) or []):
  73. source_url = source.get('url')
  74. if not source_url:
  75. continue
  76. thumbnails.append({
  77. 'url': source_url,
  78. 'width': int_or_none(source.get('width')),
  79. })
  80. return {
  81. '_type': 'url_transparent',
  82. 'id': wat_id,
  83. 'url': 'wat:' + wat_id,
  84. 'title': video.get('title'),
  85. 'thumbnails': thumbnails,
  86. 'description': decoration.get('description'),
  87. 'timestamp': parse_iso8601(video.get('date')),
  88. 'duration': int_or_none(try_get(video, lambda x: x['publicPlayingInfos']['duration'])),
  89. 'tags': tags,
  90. 'series': decoration.get('programLabel'),
  91. 'season_number': int_or_none(video.get('season')),
  92. 'episode_number': int_or_none(video.get('episode')),
  93. }