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