logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

tf1.py (3073B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. import re
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. int_or_none,
  8. parse_iso8601,
  9. try_get,
  10. )
  11. class TF1IE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?tf1\.fr/[^/]+/(?P<program_slug>[^/]+)/videos/(?P<id>[^/?&#]+)\.html'
  13. _TESTS = [{
  14. 'url': 'https://www.tf1.fr/tmc/quotidien-avec-yann-barthes/videos/quotidien-premiere-partie-11-juin-2019.html',
  15. 'info_dict': {
  16. 'id': '13641379',
  17. 'ext': 'mp4',
  18. 'title': 'md5:f392bc52245dc5ad43771650c96fb620',
  19. 'description': 'md5:a02cdb217141fb2d469d6216339b052f',
  20. 'upload_date': '20190611',
  21. 'timestamp': 1560273989,
  22. 'duration': 1738,
  23. 'series': 'Quotidien avec Yann Barthès',
  24. 'tags': ['intégrale', 'quotidien', 'Replay'],
  25. },
  26. 'params': {
  27. # Sometimes wat serves the whole file with the --test option
  28. 'skip_download': True,
  29. 'format': 'bestvideo',
  30. },
  31. }, {
  32. 'url': 'http://www.tf1.fr/tf1/koh-lanta/videos/replay-koh-lanta-22-mai-2015.html',
  33. 'only_matching': True,
  34. }, {
  35. 'url': 'http://www.tf1.fr/hd1/documentaire/videos/mylene-farmer-d-une-icone.html',
  36. 'only_matching': True,
  37. }]
  38. def _real_extract(self, url):
  39. program_slug, slug = re.match(self._VALID_URL, url).groups()
  40. video = self._download_json(
  41. 'https://www.tf1.fr/graphql/web', slug, query={
  42. 'id': '9b80783950b85247541dd1d851f9cc7fa36574af015621f853ab111a679ce26f',
  43. 'variables': json.dumps({
  44. 'programSlug': program_slug,
  45. 'slug': slug,
  46. })
  47. })['data']['videoBySlug']
  48. wat_id = video['streamId']
  49. tags = []
  50. for tag in (video.get('tags') or []):
  51. label = tag.get('label')
  52. if not label:
  53. continue
  54. tags.append(label)
  55. decoration = video.get('decoration') or {}
  56. thumbnails = []
  57. for source in (try_get(decoration, lambda x: x['image']['sources'], list) or []):
  58. source_url = source.get('url')
  59. if not source_url:
  60. continue
  61. thumbnails.append({
  62. 'url': source_url,
  63. 'width': int_or_none(source.get('width')),
  64. })
  65. return {
  66. '_type': 'url_transparent',
  67. 'id': wat_id,
  68. 'url': 'wat:' + wat_id,
  69. 'title': video.get('title'),
  70. 'thumbnails': thumbnails,
  71. 'description': decoration.get('description'),
  72. 'timestamp': parse_iso8601(video.get('date')),
  73. 'duration': int_or_none(try_get(video, lambda x: x['publicPlayingInfos']['duration'])),
  74. 'tags': tags,
  75. 'series': decoration.get('programLabel'),
  76. 'season_number': int_or_none(video.get('season')),
  77. 'episode_number': int_or_none(video.get('episode')),
  78. }