]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/tv4.py
Revert "pull changes from remote master (#190)" (#193)
[yt-dlp.git] / youtube_dl / extractor / tv4.py
CommitLineData
50efb383
NJ
1# coding: utf-8
2from __future__ import unicode_literals
3
6ae36035
RA
4import re
5
50efb383
NJ
6from .common import InfoExtractor
7from ..utils import (
9d8985a1 8 int_or_none,
50efb383
NJ
9 parse_iso8601,
10)
11
12
13class TV4IE(InfoExtractor):
14 IE_DESC = 'tv4.se and tv4play.se'
15 _VALID_URL = r'''(?x)https?://(?:www\.)?
16 (?:
17 tv4\.se/(?:[^/]+)/klipp/(?:.*)-|
18 tv4play\.se/
19 (?:
319fc706 20 (?:program|barn)/(?:[^/]+/|(?:[^\?]+)\?video_id=)|
50efb383
NJ
21 iframe/video/|
22 film/|
23 sport/|
24 )
25 )(?P<id>[0-9]+)'''
c58b7ffe 26 _GEO_COUNTRIES = ['SE']
50efb383
NJ
27 _TESTS = [
28 {
29 'url': 'http://www.tv4.se/kalla-fakta/klipp/kalla-fakta-5-english-subtitles-2491650',
1f393a32 30 'md5': 'cb837212f342d77cec06e6dad190e96d',
50efb383
NJ
31 'info_dict': {
32 'id': '2491650',
33 'ext': 'mp4',
34 'title': 'Kalla Fakta 5 (english subtitles)',
ec85ded8 35 'thumbnail': r're:^https?://.*\.jpg$',
50efb383
NJ
36 'timestamp': int,
37 'upload_date': '20131125',
38 },
39 },
40 {
41 'url': 'http://www.tv4play.se/iframe/video/3054113',
1f393a32 42 'md5': 'cb837212f342d77cec06e6dad190e96d',
50efb383
NJ
43 'info_dict': {
44 'id': '3054113',
45 'ext': 'mp4',
46 'title': 'Så här jobbar ficktjuvarna - se avslöjande bilder',
ec85ded8 47 'thumbnail': r're:^https?://.*\.jpg$',
50efb383
NJ
48 '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.',
49 'timestamp': int,
50 'upload_date': '20150130',
51 },
52 },
53 {
54 'url': 'http://www.tv4play.se/sport/3060959',
55 'only_matching': True,
56 },
57 {
58 'url': 'http://www.tv4play.se/film/2378136',
59 'only_matching': True,
60 },
61 {
62 'url': 'http://www.tv4play.se/barn/looney-tunes?video_id=3062412',
63 'only_matching': True,
64 },
319fc706 65 {
fad9fc53 66 'url': 'http://www.tv4play.se/program/farang/3922081',
319fc706
S
67 'only_matching': True,
68 }
50efb383
NJ
69 ]
70
71 def _real_extract(self, url):
72 video_id = self._match_id(url)
73
74 info = self._download_json(
20e11b70
S
75 'https://playback-api.b17g.net/asset/%s' % video_id,
76 video_id, 'Downloading video info JSON', query={
77 'service': 'tv4',
78 'device': 'browser',
79 'protocol': 'hls,dash',
80 'drm': 'widevine',
81 })['metadata']
50efb383 82
9d8985a1 83 title = info['title']
50efb383 84
6ae36035
RA
85 manifest_url = self._download_json(
86 'https://playback-api.b17g.net/media/' + video_id,
87 video_id, query={
88 'service': 'tv4',
89 'device': 'browser',
90 'protocol': 'hls',
91 })['playbackItem']['manifestUrl']
92 formats = self._extract_m3u8_formats(
93 manifest_url, video_id, 'mp4',
94 'm3u8_native', m3u8_id='hls', fatal=False)
95 formats.extend(self._extract_mpd_formats(
96 manifest_url.replace('.m3u8', '.mpd'),
97 video_id, mpd_id='dash', fatal=False))
98 formats.extend(self._extract_f4m_formats(
99 manifest_url.replace('.m3u8', '.f4m'),
100 video_id, f4m_id='hds', fatal=False))
101 formats.extend(self._extract_ism_formats(
19a107f2 102 re.sub(r'\.ism/.+?\.m3u8', r'.ism/Manifest', manifest_url),
6ae36035 103 video_id, ism_id='mss', fatal=False))
c58b7ffe
S
104
105 if not formats and info.get('is_geo_restricted'):
106 self.raise_geo_restricted(countries=self._GEO_COUNTRIES)
107
50efb383
NJ
108 self._sort_formats(formats)
109
110 return {
111 'id': video_id,
9d8985a1 112 'title': title,
50efb383 113 'formats': formats,
6ae36035 114 # 'subtitles': subtitles,
50efb383
NJ
115 'description': info.get('description'),
116 'timestamp': parse_iso8601(info.get('broadcast_date_time')),
9d8985a1 117 'duration': int_or_none(info.get('duration')),
50efb383 118 'thumbnail': info.get('image'),
20e11b70
S
119 'is_live': info.get('isLive') is True,
120 'series': info.get('seriesTitle'),
121 'season_number': int_or_none(info.get('seasonNumber')),
122 'episode': info.get('episodeTitle'),
123 'episode_number': int_or_none(info.get('episodeNumber')),
50efb383 124 }