aboutsummaryrefslogtreecommitdiffstats
path: root/hypervideo_dl/extractor/tv5unis.py
blob: 978255b1772767426fd3dd8528c2ed42d3999bec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from .common import InfoExtractor
from ..utils import (
    int_or_none,
    parse_age_limit,
    smuggle_url,
    try_get,
)


class TV5UnisBaseIE(InfoExtractor):
    _GEO_COUNTRIES = ['CA']

    def _real_extract(self, url):
        groups = self._match_valid_url(url).groups()
        product = self._download_json(
            'https://api.tv5unis.ca/graphql', groups[0], query={
                'query': '''{
  %s(%s) {
    collection {
      title
    }
    episodeNumber
    rating {
      name
    }
    seasonNumber
    tags
    title
    videoElement {
      ... on Video {
        mediaId
      }
    }
  }
}''' % (self._GQL_QUERY_NAME, self._gql_args(groups)),
            })['data'][self._GQL_QUERY_NAME]
        media_id = product['videoElement']['mediaId']

        return {
            '_type': 'url_transparent',
            'id': media_id,
            'title': product.get('title'),
            'url': smuggle_url('limelight:media:' + media_id, {'geo_countries': self._GEO_COUNTRIES}),
            'age_limit': parse_age_limit(try_get(product, lambda x: x['rating']['name'])),
            'tags': product.get('tags'),
            'series': try_get(product, lambda x: x['collection']['title']),
            'season_number': int_or_none(product.get('seasonNumber')),
            'episode_number': int_or_none(product.get('episodeNumber')),
            'ie_key': 'LimelightMedia',
        }


class TV5UnisVideoIE(TV5UnisBaseIE):
    IE_NAME = 'tv5unis:video'
    _VALID_URL = r'https?://(?:www\.)?tv5unis\.ca/videos/[^/]+/(?P<id>\d+)'
    _TEST = {
        'url': 'https://www.tv5unis.ca/videos/bande-annonces/71843',
        'md5': '3d794164928bda97fb87a17e89923d9b',
        'info_dict': {
            'id': 'a883684aecb2486cad9bdc7bbe17f861',
            'ext': 'mp4',
            'title': 'Watatatow',
            'duration': 10.01,
        }
    }
    _GQL_QUERY_NAME = 'productById'

    @staticmethod
    def _gql_args(groups):
        return 'id: %s' % groups


class TV5UnisIE(TV5UnisBaseIE):
    IE_NAME = 'tv5unis'
    _VALID_URL = r'https?://(?:www\.)?tv5unis\.ca/videos/(?P<id>[^/]+)(?:/saisons/(?P<season_number>\d+)/episodes/(?P<episode_number>\d+))?/?(?:[?#&]|$)'
    _TESTS = [{
        'url': 'https://www.tv5unis.ca/videos/watatatow/saisons/6/episodes/1',
        'md5': 'a479907d2e531a73e1f8dc48d6388d02',
        'info_dict': {
            'id': 'e5ee23a586c44612a56aad61accf16ef',
            'ext': 'mp4',
            'title': 'Je ne peux pas lui résister',
            '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...",
            'subtitles': {
                'fr': 'count:1',
            },
            'duration': 1370,
            'age_limit': 8,
            'tags': 'count:3',
            'series': 'Watatatow',
            'season_number': 6,
            'episode_number': 1,
        },
    }, {
        'url': 'https://www.tv5unis.ca/videos/le-voyage-de-fanny',
        'md5': '9ca80ebb575c681d10cae1adff3d4774',
        'info_dict': {
            'id': '726188eefe094d8faefb13381d42bc06',
            'ext': 'mp4',
            'title': 'Le voyage de Fanny',
            '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.",
            'subtitles': {
                'fr': 'count:1',
            },
            'duration': 5587.034,
            'tags': 'count:4',
        },
    }]
    _GQL_QUERY_NAME = 'productByRootProductSlug'

    @staticmethod
    def _gql_args(groups):
        args = 'rootProductSlug: "%s"' % groups[0]
        if groups[1]:
            args += ', seasonNumber: %s, episodeNumber: %s' % groups[1:]
        return args