]>
Commit | Line | Data |
---|---|---|
1 | # coding: utf-8 | |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..utils import ( | |
6 | smuggle_url, | |
7 | ExtractorError, | |
8 | ) | |
9 | ||
10 | ||
11 | class SBSIE(InfoExtractor): | |
12 | IE_DESC = 'sbs.com.au' | |
13 | _VALID_URL = r'''(?x) | |
14 | https?://(?:www\.)?sbs\.com\.au/(?: | |
15 | ondemand(?: | |
16 | /video/(?:single/)?| | |
17 | /movie/[^/]+/| | |
18 | .*?\bplay=|/watch/ | |
19 | )|news/(?:embeds/)?video/ | |
20 | )(?P<id>[0-9]+)''' | |
21 | ||
22 | _TESTS = [{ | |
23 | # Original URL is handled by the generic IE which finds the iframe: | |
24 | # http://www.sbs.com.au/thefeed/blog/2014/08/21/dingo-conservation | |
25 | 'url': 'http://www.sbs.com.au/ondemand/video/single/320403011771/?source=drupal&vertical=thefeed', | |
26 | 'md5': '3150cf278965eeabb5b4cea1c963fe0a', | |
27 | 'info_dict': { | |
28 | 'id': '_rFBPRPO4pMR', | |
29 | 'ext': 'mp4', | |
30 | 'title': 'Dingo Conservation (The Feed)', | |
31 | 'description': 'md5:f250a9856fca50d22dec0b5b8015f8a5', | |
32 | 'thumbnail': r're:http://.*\.jpg', | |
33 | 'duration': 308, | |
34 | 'timestamp': 1408613220, | |
35 | 'upload_date': '20140821', | |
36 | 'uploader': 'SBSC', | |
37 | }, | |
38 | }, { | |
39 | 'url': 'http://www.sbs.com.au/ondemand/video/320403011771/Dingo-Conservation-The-Feed', | |
40 | 'only_matching': True, | |
41 | }, { | |
42 | 'url': 'http://www.sbs.com.au/news/video/471395907773/The-Feed-July-9', | |
43 | 'only_matching': True, | |
44 | }, { | |
45 | 'url': 'https://www.sbs.com.au/ondemand/?play=1836638787723', | |
46 | 'only_matching': True, | |
47 | }, { | |
48 | 'url': 'https://www.sbs.com.au/ondemand/program/inside-windsor-castle?play=1283505731842', | |
49 | 'only_matching': True, | |
50 | }, { | |
51 | 'url': 'https://www.sbs.com.au/news/embeds/video/1840778819866', | |
52 | 'only_matching': True, | |
53 | }, { | |
54 | 'url': 'https://www.sbs.com.au/ondemand/watch/1698704451971', | |
55 | 'only_matching': True, | |
56 | }, { | |
57 | 'url': 'https://www.sbs.com.au/ondemand/movie/coherence/1469404227931', | |
58 | 'only_matching': True, | |
59 | }, { | |
60 | 'note': 'Live stream', | |
61 | 'url': 'https://www.sbs.com.au/ondemand/video/1726824003663/sbs-24x7-live-stream-nsw', | |
62 | 'only_matching': True, | |
63 | }] | |
64 | ||
65 | def _real_extract(self, url): | |
66 | video_id = self._match_id(url) | |
67 | player_params = self._download_json( | |
68 | 'http://www.sbs.com.au/api/video_pdkvars/id/%s?form=json' % video_id, video_id) | |
69 | ||
70 | error = player_params.get('error') | |
71 | if error: | |
72 | error_message = 'Sorry, The video you are looking for does not exist.' | |
73 | video_data = error.get('results') or {} | |
74 | error_code = error.get('errorCode') | |
75 | if error_code == 'ComingSoon': | |
76 | error_message = '%s is not yet available.' % video_data.get('title', '') | |
77 | elif error_code in ('Forbidden', 'intranetAccessOnly'): | |
78 | error_message = 'Sorry, This video cannot be accessed via this website' | |
79 | elif error_code == 'Expired': | |
80 | error_message = 'Sorry, %s is no longer available.' % video_data.get('title', '') | |
81 | raise ExtractorError('%s said: %s' % (self.IE_NAME, error_message), expected=True) | |
82 | ||
83 | urls = player_params['releaseUrls'] | |
84 | theplatform_url = (urls.get('progressive') or urls.get('html') | |
85 | or urls.get('standard') or player_params['relatedItemsURL']) | |
86 | ||
87 | return { | |
88 | '_type': 'url_transparent', | |
89 | 'ie_key': 'ThePlatform', | |
90 | 'id': video_id, | |
91 | 'url': smuggle_url(self._proto_relative_url(theplatform_url), {'force_smil_url': True}), | |
92 | 'is_live': player_params.get('streamType') == 'live', | |
93 | } |