]>
Commit | Line | Data |
---|---|---|
29f7c58a | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
29f7c58a | 4 | |
5 | from .common import InfoExtractor | |
6 | from ..utils import ( | |
7 | int_or_none, | |
8 | parse_age_limit, | |
9 | smuggle_url, | |
10 | try_get, | |
11 | ) | |
12 | ||
13 | ||
14 | class TV5UnisBaseIE(InfoExtractor): | |
15 | _GEO_COUNTRIES = ['CA'] | |
16 | ||
17 | def _real_extract(self, url): | |
5ad28e7f | 18 | groups = self._match_valid_url(url).groups() |
29f7c58a | 19 | product = self._download_json( |
20 | 'https://api.tv5unis.ca/graphql', groups[0], query={ | |
21 | 'query': '''{ | |
22 | %s(%s) { | |
23 | collection { | |
24 | title | |
25 | } | |
26 | episodeNumber | |
27 | rating { | |
28 | name | |
29 | } | |
30 | seasonNumber | |
31 | tags | |
32 | title | |
33 | videoElement { | |
34 | ... on Video { | |
35 | mediaId | |
36 | } | |
37 | } | |
38 | } | |
39 | }''' % (self._GQL_QUERY_NAME, self._gql_args(groups)), | |
40 | })['data'][self._GQL_QUERY_NAME] | |
41 | media_id = product['videoElement']['mediaId'] | |
42 | ||
43 | return { | |
44 | '_type': 'url_transparent', | |
45 | 'id': media_id, | |
46 | 'title': product.get('title'), | |
47 | 'url': smuggle_url('limelight:media:' + media_id, {'geo_countries': self._GEO_COUNTRIES}), | |
48 | 'age_limit': parse_age_limit(try_get(product, lambda x: x['rating']['name'])), | |
49 | 'tags': product.get('tags'), | |
50 | 'series': try_get(product, lambda x: x['collection']['title']), | |
51 | 'season_number': int_or_none(product.get('seasonNumber')), | |
52 | 'episode_number': int_or_none(product.get('episodeNumber')), | |
53 | 'ie_key': 'LimelightMedia', | |
54 | } | |
55 | ||
56 | ||
57 | class TV5UnisVideoIE(TV5UnisBaseIE): | |
58 | IE_NAME = 'tv5unis:video' | |
59 | _VALID_URL = r'https?://(?:www\.)?tv5unis\.ca/videos/[^/]+/(?P<id>\d+)' | |
60 | _TEST = { | |
61 | 'url': 'https://www.tv5unis.ca/videos/bande-annonces/71843', | |
62 | 'md5': '3d794164928bda97fb87a17e89923d9b', | |
63 | 'info_dict': { | |
64 | 'id': 'a883684aecb2486cad9bdc7bbe17f861', | |
65 | 'ext': 'mp4', | |
66 | 'title': 'Watatatow', | |
67 | 'duration': 10.01, | |
68 | } | |
69 | } | |
70 | _GQL_QUERY_NAME = 'productById' | |
71 | ||
72 | @staticmethod | |
73 | def _gql_args(groups): | |
74 | return 'id: %s' % groups | |
75 | ||
76 | ||
77 | class TV5UnisIE(TV5UnisBaseIE): | |
78 | IE_NAME = 'tv5unis' | |
79 | _VALID_URL = r'https?://(?:www\.)?tv5unis\.ca/videos/(?P<id>[^/]+)(?:/saisons/(?P<season_number>\d+)/episodes/(?P<episode_number>\d+))?/?(?:[?#&]|$)' | |
80 | _TESTS = [{ | |
81 | 'url': 'https://www.tv5unis.ca/videos/watatatow/saisons/6/episodes/1', | |
82 | 'md5': 'a479907d2e531a73e1f8dc48d6388d02', | |
83 | 'info_dict': { | |
84 | 'id': 'e5ee23a586c44612a56aad61accf16ef', | |
85 | 'ext': 'mp4', | |
86 | 'title': 'Je ne peux pas lui résister', | |
87 | '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...", | |
88 | 'subtitles': { | |
89 | 'fr': 'count:1', | |
90 | }, | |
91 | 'duration': 1370, | |
92 | 'age_limit': 8, | |
93 | 'tags': 'count:3', | |
94 | 'series': 'Watatatow', | |
95 | 'season_number': 6, | |
96 | 'episode_number': 1, | |
97 | }, | |
98 | }, { | |
99 | 'url': 'https://www.tv5unis.ca/videos/le-voyage-de-fanny', | |
100 | 'md5': '9ca80ebb575c681d10cae1adff3d4774', | |
101 | 'info_dict': { | |
102 | 'id': '726188eefe094d8faefb13381d42bc06', | |
103 | 'ext': 'mp4', | |
104 | 'title': 'Le voyage de Fanny', | |
105 | '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.", | |
106 | 'subtitles': { | |
107 | 'fr': 'count:1', | |
108 | }, | |
109 | 'duration': 5587.034, | |
110 | 'tags': 'count:4', | |
111 | }, | |
112 | }] | |
113 | _GQL_QUERY_NAME = 'productByRootProductSlug' | |
114 | ||
115 | @staticmethod | |
116 | def _gql_args(groups): | |
117 | args = 'rootProductSlug: "%s"' % groups[0] | |
118 | if groups[1]: | |
119 | args += ', seasonNumber: %s, episodeNumber: %s' % groups[1:] | |
120 | return args |