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