2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_urllib_parse_urlparse
15 class SRGSSRIE(InfoExtractor
):
16 _VALID_URL
= r
'(?:https?://tp\.srgssr\.ch/p(?:/[^/]+)+\?urn=urn|srgssr):(?P<bu>srf|rts|rsi|rtr|swi):(?:[^:]+:)?(?P<type>video|audio):(?P<id>[0-9a-f\-]{36}|\d+)'
18 _GEO_COUNTRIES
= ['CH']
21 'AGERATING12': 'To protect children under the age of 12, this video is only available between 8 p.m. and 6 a.m.',
22 'AGERATING18': 'To protect children under the age of 18, this video is only available between 11 p.m. and 5 a.m.',
23 # 'ENDDATE': 'For legal reasons, this video was only available for a specified period of time.',
24 'GEOBLOCK': 'For legal reasons, this video is only available in Switzerland.',
25 'LEGAL': 'The video cannot be transmitted for legal reasons.',
26 'STARTDATE': 'This video is not yet available. Please try again later.',
29 def _get_tokenized_src(self
, url
, video_id
, format_id
):
30 sp
= compat_urllib_parse_urlparse(url
).path
.split('/')
31 token
= self
._download
_json
(
32 'http://tp.srgssr.ch/akahd/token?acl=/%s/%s/*' % (sp
[1], sp
[2]),
33 video_id
, 'Downloading %s token' % format_id
, fatal
=False) or {}
34 auth_params
= token
.get('token', {}).get('authparams')
36 url
+= '?' + auth_params
39 def get_media_data(self
, bu
, media_type
, media_id
):
40 media_data
= self
._download
_json
(
41 'http://il.srgssr.ch/integrationlayer/1.0/ue/%s/%s/play/%s.json' % (bu
, media_type
, media_id
),
42 media_id
)[media_type
.capitalize()]
44 if media_data
.get('block') and media_data
['block'] in self
._ERRORS
:
45 message
= self
._ERRORS
[media_data
['block']]
46 if media_data
['block'] == 'GEOBLOCK':
47 self
.raise_geo_restricted(
48 msg
=message
, countries
=self
._GEO
_COUNTRIES
)
50 '%s said: %s' % (self
.IE_NAME
, message
), expected
=True)
54 def _real_extract(self
, url
):
55 bu
, media_type
, media_id
= re
.match(self
._VALID
_URL
, url
).groups()
57 media_data
= self
.get_media_data(bu
, media_type
, media_id
)
59 metadata
= media_data
['AssetMetadatas']['AssetMetadata'][0]
60 title
= metadata
['title']
61 description
= metadata
.get('description')
62 created_date
= media_data
.get('createdDate') or metadata
.get('createdDate')
63 timestamp
= parse_iso8601(created_date
)
66 'id': image
.get('id'),
68 } for image
in media_data
.get('Image', {}).get('ImageRepresentations', {}).get('ImageRepresentation', [])]
70 preference
= qualities(['LQ', 'MQ', 'SD', 'HQ', 'HD'])
72 for source
in media_data
.get('Playlists', {}).get('Playlist', []) + media_data
.get('Downloads', {}).get('Download', []):
73 protocol
= source
.get('@protocol')
74 for asset
in source
['url']:
75 asset_url
= asset
['text']
76 quality
= asset
['@quality']
77 format_id
= '%s-%s' % (protocol
, quality
)
78 if protocol
.startswith('HTTP-HDS') or protocol
.startswith('HTTP-HLS'):
79 asset_url
= self
._get
_tokenized
_src
(asset_url
, media_id
, format_id
)
80 if protocol
.startswith('HTTP-HDS'):
81 formats
.extend(self
._extract
_f
4m
_formats
(
82 asset_url
+ ('?' if '?' not in asset_url
else '&') + 'hdcore=3.4.0',
83 media_id
, f4m_id
=format_id
, fatal
=False))
84 elif protocol
.startswith('HTTP-HLS'):
85 formats
.extend(self
._extract
_m
3u8_formats
(
86 asset_url
, media_id
, 'mp4', 'm3u8_native',
87 m3u8_id
=format_id
, fatal
=False))
90 'format_id': format_id
,
92 'preference': preference(quality
),
93 'ext': 'flv' if protocol
== 'RTMP' else None,
95 self
._sort
_formats
(formats
)
100 'description': description
,
101 'timestamp': timestamp
,
102 'thumbnails': thumbnails
,
107 class SRGSSRPlayIE(InfoExtractor
):
108 IE_DESC
= 'srf.ch, rts.ch, rsi.ch, rtr.ch and swissinfo.ch play sites'
109 _VALID_URL
= r
'''(?x)
112 (?P<bu>srf|rts|rsi|rtr|swissinfo)\.ch/play/(?:tv|radio)/
114 [^/]+/(?P<type>video|audio)/[^?]+|
115 popup(?P<type_2>video|audio)player
117 \?.*?\b(?:id=|urn=urn:[^:]+:video:)(?P<id>[0-9a-f\-]{36}|\d+)
121 'url': 'http://www.srf.ch/play/tv/10vor10/video/snowden-beantragt-asyl-in-russland?id=28e1a57d-5b76-4399-8ab3-9097f071e6c5',
122 'md5': 'da6b5b3ac9fa4761a942331cef20fcb3',
124 'id': '28e1a57d-5b76-4399-8ab3-9097f071e6c5',
126 'upload_date': '20130701',
127 'title': 'Snowden beantragt Asyl in Russland',
128 'timestamp': 1372713995,
131 # No Speichern (Save) button
132 'url': 'http://www.srf.ch/play/tv/top-gear/video/jaguar-xk120-shadow-und-tornado-dampflokomotive?id=677f5829-e473-4823-ac83-a1087fe97faa',
133 'md5': '0a274ce38fda48c53c01890651985bc6',
135 'id': '677f5829-e473-4823-ac83-a1087fe97faa',
137 'upload_date': '20130710',
138 'title': 'Jaguar XK120, Shadow und Tornado-Dampflokomotive',
139 'description': 'md5:88604432b60d5a38787f152dec89cd56',
140 'timestamp': 1373493600,
143 'url': 'http://www.rtr.ch/play/radio/actualitad/audio/saira-tujetsch-tuttina-cuntinuar-cun-sedrun-muster-turissem?id=63cb0778-27f8-49af-9284-8c7a8c6d15fc',
145 'id': '63cb0778-27f8-49af-9284-8c7a8c6d15fc',
147 'upload_date': '20151013',
148 'title': 'Saira: Tujetsch - tuttina cuntinuar cun Sedrun Mustér Turissem',
149 'timestamp': 1444750398,
153 'skip_download': True,
156 'url': 'http://www.rts.ch/play/tv/-/video/le-19h30?id=6348260',
157 'md5': '67a2a9ae4e8e62a68d0e9820cc9782df',
160 'display_id': '6348260',
166 'upload_date': '20141201',
167 'timestamp': 1417458600,
168 'thumbnail': r
're:^https?://.*\.image',
173 'skip_download': True,
176 'url': 'https://www.srf.ch/play/tv/popupvideoplayer?id=c4dba0ca-e75b-43b2-a34f-f708a4932e01',
177 'only_matching': True,
179 'url': 'https://www.srf.ch/play/tv/10vor10/video/snowden-beantragt-asyl-in-russland?urn=urn:srf:video:28e1a57d-5b76-4399-8ab3-9097f071e6c5',
180 'only_matching': True,
182 'url': 'https://www.rts.ch/play/tv/19h30/video/le-19h30?urn=urn:rts:video:6348260',
183 'only_matching': True,
186 def _real_extract(self
, url
):
187 mobj
= re
.match(self
._VALID
_URL
, url
)
188 bu
= mobj
.group('bu')
189 media_type
= mobj
.group('type') or mobj
.group('type_2')
190 media_id
= mobj
.group('id')
191 # other info can be extracted from url + '&layout=json'
192 return self
.url_result('srgssr:%s:%s:%s' % (bu
[:3], media_type
, media_id
), 'SRGSSR')