]>
Commit | Line | Data |
---|---|---|
7c8c6352 | 1 | import json |
e897bd82 | 2 | |
7c8c6352 | 3 | from .common import InfoExtractor |
3d2623a8 | 4 | from ..networking.exceptions import HTTPError |
7c8c6352 T |
5 | from ..utils import ( |
6 | ExtractorError, | |
7 | float_or_none, | |
8 | parse_iso8601, | |
9 | strip_or_none, | |
10 | traverse_obj, | |
11 | try_get, | |
12 | urljoin, | |
13 | ) | |
14 | ||
15 | ||
16 | class CinetecaMilanoIE(InfoExtractor): | |
17 | _VALID_URL = r'https?://(?:www\.)?cinetecamilano\.it/film/(?P<id>\d+)' | |
18 | _TESTS = [{ | |
19 | 'url': 'https://www.cinetecamilano.it/film/1942', | |
20 | 'info_dict': { | |
21 | 'id': '1942', | |
22 | 'ext': 'mp4', | |
23 | 'title': 'Il draghetto Gris\u00f9 (4 episodi)', | |
24 | 'release_date': '20220129', | |
25 | 'thumbnail': r're:.+\.png', | |
26 | 'description': 'md5:5328cbe080b93224712b6f17fcaf2c01', | |
27 | 'modified_date': '20200520', | |
28 | 'duration': 3139, | |
29 | 'release_timestamp': 1643446208, | |
30 | 'modified_timestamp': int | |
31 | } | |
32 | }] | |
33 | ||
34 | def _real_extract(self, url): | |
35 | video_id = self._match_id(url) | |
36 | try: | |
37 | film_json = self._download_json( | |
38 | f'https://www.cinetecamilano.it/api/catalogo/{video_id}/?', | |
39 | video_id, headers={ | |
40 | 'Referer': url, | |
41 | 'Authorization': try_get(self._get_cookies('https://www.cinetecamilano.it'), lambda x: f'Bearer {x["cnt-token"].value}') or '' | |
42 | }) | |
43 | except ExtractorError as e: | |
3d2623a8 | 44 | if ((isinstance(e.cause, HTTPError) and e.cause.status == 500) |
7c8c6352 T |
45 | or isinstance(e.cause, json.JSONDecodeError)): |
46 | self.raise_login_required(method='cookies') | |
47 | raise | |
48 | if not film_json.get('success') or not film_json.get('archive'): | |
49 | raise ExtractorError('Video information not found') | |
50 | archive = film_json['archive'] | |
51 | ||
52 | return { | |
53 | 'id': video_id, | |
54 | 'title': archive.get('title'), | |
55 | 'description': strip_or_none(archive.get('description')), | |
56 | 'duration': float_or_none(archive.get('duration'), invscale=60), | |
57 | 'release_timestamp': parse_iso8601(archive.get('updated_at'), delimiter=' '), | |
58 | 'modified_timestamp': parse_iso8601(archive.get('created_at'), delimiter=' '), | |
59 | 'thumbnail': urljoin(url, try_get(archive, lambda x: x['thumb']['src'].replace('/public/', '/storage/'))), | |
60 | 'formats': self._extract_m3u8_formats( | |
61 | urljoin(url, traverse_obj(archive, ('drm', 'hls'))), video_id, 'mp4') | |
62 | } |