]>
Commit | Line | Data |
---|---|---|
61be785a | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..utils import js_to_json | |
6 | ||
7 | ||
8 | class PeerTVIE(InfoExtractor): | |
9 | IE_NAME = 'peer.tv' | |
10 | _VALID_URL = r'https?://(?:www\.)?peer\.tv/(?:de|it|en)/(?P<id>\d+)' | |
11 | _TESTS = [{ | |
12 | 'url': 'https://www.peer.tv/de/841', | |
13 | 'info_dict': { | |
14 | 'id': '841', | |
15 | 'ext': 'mp4', | |
16 | 'title': 'Die Brunnenburg', | |
17 | 'description': 'md5:4395f6142b090338340ab88a3aae24ed', | |
18 | }, | |
19 | }, { | |
20 | 'url': 'https://www.peer.tv/it/404', | |
21 | 'info_dict': { | |
22 | 'id': '404', | |
23 | 'ext': 'mp4', | |
24 | 'title': 'Cascate di ghiaccio in Val Gardena', | |
25 | 'description': 'md5:e8e5907f236171842674e8090e3577b8', | |
26 | }, | |
27 | }] | |
28 | ||
29 | def _real_extract(self, url): | |
30 | video_id = self._match_id(url) | |
31 | webpage = self._download_webpage(url, video_id) | |
32 | ||
33 | video_key = self._html_search_regex(r'player\.peer\.tv/js/([a-zA-Z0-9]+)', webpage, 'video key') | |
34 | ||
35 | js = self._download_webpage(f'https://player.peer.tv/js/{video_key}/', video_id, | |
36 | headers={'Referer': 'https://www.peer.tv/'}, note='Downloading session id') | |
37 | ||
38 | session_id = self._search_regex(r'["\']session_id["\']:\s*["\']([a-zA-Z0-9]+)["\']', js, 'session id') | |
39 | ||
40 | player_webpage = self._download_webpage( | |
41 | f'https://player.peer.tv/jsc/{video_key}/{session_id}?jsr=aHR0cHM6Ly93d3cucGVlci50di9kZS84NDE=&cs=UTF-8&mq=2&ua=0&webm=p&mp4=p&hls=1', | |
42 | video_id, note='Downloading player webpage') | |
43 | ||
44 | m3u8_url = self._search_regex(r'["\']playlist_url["\']:\s*(["\'][^"\']+["\'])', player_webpage, 'm3u8 url') | |
45 | m3u8_url = self._parse_json(m3u8_url, video_id, transform_source=js_to_json) | |
46 | ||
47 | formats = self._extract_m3u8_formats(m3u8_url, video_id, m3u8_id='hls') | |
48 | ||
49 | self._sort_formats(formats) | |
50 | ||
51 | return { | |
52 | 'id': video_id, | |
53 | 'title': self._html_search_regex(r'<h1>(.+?)</h1>', webpage, 'title').replace('\xa0', ' '), | |
54 | 'formats': formats, | |
55 | 'description': self._html_search_meta(('og:description', 'description'), webpage), | |
56 | 'thumbnail': self._html_search_meta(('og:image', 'image'), webpage) | |
57 | } |