]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/tv5unis.py
Completely change project name to yt-dlp (#85)
[yt-dlp.git] / yt_dlp / extractor / tv5unis.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 int_or_none,
9 parse_age_limit,
10 smuggle_url,
11 try_get,
12 )
13
14
15 class TV5UnisBaseIE(InfoExtractor):
16 _GEO_COUNTRIES = ['CA']
17
18 def _real_extract(self, url):
19 groups = re.match(self._VALID_URL, url).groups()
20 product = self._download_json(
21 'https://api.tv5unis.ca/graphql', groups[0], query={
22 'query': '''{
23 %s(%s) {
24 collection {
25 title
26 }
27 episodeNumber
28 rating {
29 name
30 }
31 seasonNumber
32 tags
33 title
34 videoElement {
35 ... on Video {
36 mediaId
37 }
38 }
39 }
40 }''' % (self._GQL_QUERY_NAME, self._gql_args(groups)),
41 })['data'][self._GQL_QUERY_NAME]
42 media_id = product['videoElement']['mediaId']
43
44 return {
45 '_type': 'url_transparent',
46 'id': media_id,
47 'title': product.get('title'),
48 'url': smuggle_url('limelight:media:' + media_id, {'geo_countries': self._GEO_COUNTRIES}),
49 'age_limit': parse_age_limit(try_get(product, lambda x: x['rating']['name'])),
50 'tags': product.get('tags'),
51 'series': try_get(product, lambda x: x['collection']['title']),
52 'season_number': int_or_none(product.get('seasonNumber')),
53 'episode_number': int_or_none(product.get('episodeNumber')),
54 'ie_key': 'LimelightMedia',
55 }
56
57
58 class TV5UnisVideoIE(TV5UnisBaseIE):
59 IE_NAME = 'tv5unis:video'
60 _VALID_URL = r'https?://(?:www\.)?tv5unis\.ca/videos/[^/]+/(?P<id>\d+)'
61 _TEST = {
62 'url': 'https://www.tv5unis.ca/videos/bande-annonces/71843',
63 'md5': '3d794164928bda97fb87a17e89923d9b',
64 'info_dict': {
65 'id': 'a883684aecb2486cad9bdc7bbe17f861',
66 'ext': 'mp4',
67 'title': 'Watatatow',
68 'duration': 10.01,
69 }
70 }
71 _GQL_QUERY_NAME = 'productById'
72
73 @staticmethod
74 def _gql_args(groups):
75 return 'id: %s' % groups
76
77
78 class TV5UnisIE(TV5UnisBaseIE):
79 IE_NAME = 'tv5unis'
80 _VALID_URL = r'https?://(?:www\.)?tv5unis\.ca/videos/(?P<id>[^/]+)(?:/saisons/(?P<season_number>\d+)/episodes/(?P<episode_number>\d+))?/?(?:[?#&]|$)'
81 _TESTS = [{
82 'url': 'https://www.tv5unis.ca/videos/watatatow/saisons/6/episodes/1',
83 'md5': 'a479907d2e531a73e1f8dc48d6388d02',
84 'info_dict': {
85 'id': 'e5ee23a586c44612a56aad61accf16ef',
86 'ext': 'mp4',
87 'title': 'Je ne peux pas lui résister',
88 'description': "Atys, le nouveau concierge de l'école, a réussi à ébranler la confiance de Mado en affirmant qu\'une médaille, ce n'est que du métal. Comme Mado essaie de lui prouver que ses valeurs sont solides, il veut la mettre à l'épreuve...",
89 'subtitles': {
90 'fr': 'count:1',
91 },
92 'duration': 1370,
93 'age_limit': 8,
94 'tags': 'count:3',
95 'series': 'Watatatow',
96 'season_number': 6,
97 'episode_number': 1,
98 },
99 }, {
100 'url': 'https://www.tv5unis.ca/videos/le-voyage-de-fanny',
101 'md5': '9ca80ebb575c681d10cae1adff3d4774',
102 'info_dict': {
103 'id': '726188eefe094d8faefb13381d42bc06',
104 'ext': 'mp4',
105 'title': 'Le voyage de Fanny',
106 'description': "Fanny, 12 ans, cachée dans un foyer loin de ses parents, s'occupe de ses deux soeurs. Devant fuir, Fanny prend la tête d'un groupe de huit enfants et s'engage dans un dangereux périple à travers la France occupée pour rejoindre la frontière suisse.",
107 'subtitles': {
108 'fr': 'count:1',
109 },
110 'duration': 5587.034,
111 'tags': 'count:4',
112 },
113 }]
114 _GQL_QUERY_NAME = 'productByRootProductSlug'
115
116 @staticmethod
117 def _gql_args(groups):
118 args = 'rootProductSlug: "%s"' % groups[0]
119 if groups[1]:
120 args += ', seasonNumber: %s, episodeNumber: %s' % groups[1:]
121 return args