logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

sbs.py (3231B)


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