]>
Commit | Line | Data |
---|---|---|
6ae36035 RA |
1 | import re |
2 | ||
50efb383 NJ |
3 | from .common import InfoExtractor |
4 | from ..utils import ( | |
9d8985a1 | 5 | int_or_none, |
50efb383 NJ |
6 | parse_iso8601, |
7 | ) | |
8 | ||
9 | ||
10 | class TV4IE(InfoExtractor): | |
11 | IE_DESC = 'tv4.se and tv4play.se' | |
12 | _VALID_URL = r'''(?x)https?://(?:www\.)? | |
13 | (?: | |
14 | tv4\.se/(?:[^/]+)/klipp/(?:.*)-| | |
15 | tv4play\.se/ | |
16 | (?: | |
2181983a | 17 | (?:program|barn)/(?:(?:[^/]+/){1,2}|(?:[^\?]+)\?video_id=)| |
50efb383 NJ |
18 | iframe/video/| |
19 | film/| | |
20 | sport/| | |
21 | ) | |
22 | )(?P<id>[0-9]+)''' | |
c58b7ffe | 23 | _GEO_COUNTRIES = ['SE'] |
50efb383 NJ |
24 | _TESTS = [ |
25 | { | |
26 | 'url': 'http://www.tv4.se/kalla-fakta/klipp/kalla-fakta-5-english-subtitles-2491650', | |
1f393a32 | 27 | 'md5': 'cb837212f342d77cec06e6dad190e96d', |
50efb383 NJ |
28 | 'info_dict': { |
29 | 'id': '2491650', | |
30 | 'ext': 'mp4', | |
31 | 'title': 'Kalla Fakta 5 (english subtitles)', | |
ec85ded8 | 32 | 'thumbnail': r're:^https?://.*\.jpg$', |
50efb383 NJ |
33 | 'timestamp': int, |
34 | 'upload_date': '20131125', | |
35 | }, | |
36 | }, | |
37 | { | |
38 | 'url': 'http://www.tv4play.se/iframe/video/3054113', | |
1f393a32 | 39 | 'md5': 'cb837212f342d77cec06e6dad190e96d', |
50efb383 NJ |
40 | 'info_dict': { |
41 | 'id': '3054113', | |
42 | 'ext': 'mp4', | |
43 | 'title': 'Så här jobbar ficktjuvarna - se avslöjande bilder', | |
ec85ded8 | 44 | 'thumbnail': r're:^https?://.*\.jpg$', |
50efb383 NJ |
45 | 'description': 'Unika bilder avslöjar hur turisternas fickor vittjas mitt på Stockholms central. Två experter på ficktjuvarna avslöjar knepen du ska se upp för.', |
46 | 'timestamp': int, | |
47 | 'upload_date': '20150130', | |
48 | }, | |
49 | }, | |
50 | { | |
51 | 'url': 'http://www.tv4play.se/sport/3060959', | |
52 | 'only_matching': True, | |
53 | }, | |
54 | { | |
55 | 'url': 'http://www.tv4play.se/film/2378136', | |
56 | 'only_matching': True, | |
57 | }, | |
58 | { | |
59 | 'url': 'http://www.tv4play.se/barn/looney-tunes?video_id=3062412', | |
60 | 'only_matching': True, | |
61 | }, | |
319fc706 | 62 | { |
fad9fc53 | 63 | 'url': 'http://www.tv4play.se/program/farang/3922081', |
319fc706 | 64 | 'only_matching': True, |
2181983a | 65 | }, |
66 | { | |
67 | 'url': 'https://www.tv4play.se/program/nyheterna/avsnitt/13315940', | |
68 | 'only_matching': True, | |
319fc706 | 69 | } |
50efb383 NJ |
70 | ] |
71 | ||
72 | def _real_extract(self, url): | |
73 | video_id = self._match_id(url) | |
74 | ||
75 | info = self._download_json( | |
20e11b70 S |
76 | 'https://playback-api.b17g.net/asset/%s' % video_id, |
77 | video_id, 'Downloading video info JSON', query={ | |
78 | 'service': 'tv4', | |
79 | 'device': 'browser', | |
80 | 'protocol': 'hls,dash', | |
81 | 'drm': 'widevine', | |
82 | })['metadata'] | |
50efb383 | 83 | |
9d8985a1 | 84 | title = info['title'] |
50efb383 | 85 | |
6ae36035 RA |
86 | manifest_url = self._download_json( |
87 | 'https://playback-api.b17g.net/media/' + video_id, | |
88 | video_id, query={ | |
89 | 'service': 'tv4', | |
90 | 'device': 'browser', | |
91 | 'protocol': 'hls', | |
92 | })['playbackItem']['manifestUrl'] | |
0c541b56 F |
93 | formats = [] |
94 | subtitles = {} | |
95 | ||
96 | fmts, subs = self._extract_m3u8_formats_and_subtitles( | |
6ae36035 RA |
97 | manifest_url, video_id, 'mp4', |
98 | 'm3u8_native', m3u8_id='hls', fatal=False) | |
0c541b56 F |
99 | formats.extend(fmts) |
100 | subtitles = self._merge_subtitles(subtitles, subs) | |
101 | ||
102 | fmts, subs = self._extract_mpd_formats_and_subtitles( | |
6ae36035 | 103 | manifest_url.replace('.m3u8', '.mpd'), |
0c541b56 F |
104 | video_id, mpd_id='dash', fatal=False) |
105 | formats.extend(fmts) | |
106 | subtitles = self._merge_subtitles(subtitles, subs) | |
107 | ||
108 | fmts = self._extract_f4m_formats( | |
6ae36035 | 109 | manifest_url.replace('.m3u8', '.f4m'), |
0c541b56 F |
110 | video_id, f4m_id='hds', fatal=False) |
111 | formats.extend(fmts) | |
112 | ||
113 | fmts, subs = self._extract_ism_formats_and_subtitles( | |
91bd3bd0 | 114 | re.sub(r'\.ism/.*?\.m3u8', r'.ism/Manifest', manifest_url), |
0c541b56 F |
115 | video_id, ism_id='mss', fatal=False) |
116 | formats.extend(fmts) | |
117 | subtitles = self._merge_subtitles(subtitles, subs) | |
c58b7ffe S |
118 | |
119 | if not formats and info.get('is_geo_restricted'): | |
b7da73eb | 120 | self.raise_geo_restricted(countries=self._GEO_COUNTRIES, metadata_available=True) |
c58b7ffe | 121 | |
50efb383 NJ |
122 | self._sort_formats(formats) |
123 | ||
124 | return { | |
125 | 'id': video_id, | |
9d8985a1 | 126 | 'title': title, |
50efb383 | 127 | 'formats': formats, |
0c541b56 | 128 | 'subtitles': subtitles, |
50efb383 NJ |
129 | 'description': info.get('description'), |
130 | 'timestamp': parse_iso8601(info.get('broadcast_date_time')), | |
9d8985a1 | 131 | 'duration': int_or_none(info.get('duration')), |
50efb383 | 132 | 'thumbnail': info.get('image'), |
20e11b70 S |
133 | 'is_live': info.get('isLive') is True, |
134 | 'series': info.get('seriesTitle'), | |
135 | 'season_number': int_or_none(info.get('seasonNumber')), | |
136 | 'episode': info.get('episodeTitle'), | |
137 | 'episode_number': int_or_none(info.get('episodeNumber')), | |
50efb383 | 138 | } |