You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.1 KiB

  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import json
  4. import re
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. js_to_json,
  8. remove_end,
  9. )
  10. class SBSIE(InfoExtractor):
  11. IE_DESC = 'sbs.com.au'
  12. _VALID_URL = r'https?://(?:www\.)?sbs\.com\.au/ondemand/video/(?:single/)?(?P<id>[0-9]+)'
  13. _TESTS = [{
  14. # Original URL is handled by the generic IE which finds the iframe:
  15. # http://www.sbs.com.au/thefeed/blog/2014/08/21/dingo-conservation
  16. 'url': 'http://www.sbs.com.au/ondemand/video/single/320403011771/?source=drupal&vertical=thefeed',
  17. 'md5': '3150cf278965eeabb5b4cea1c963fe0a',
  18. 'info_dict': {
  19. 'id': '320403011771',
  20. 'ext': 'mp4',
  21. 'title': 'Dingo Conservation',
  22. 'description': 'Dingoes are on the brink of extinction; most of the animals we think are dingoes are in fact crossbred with wild dogs. This family run a dingo conservation park to prevent their extinction',
  23. 'thumbnail': 're:http://.*\.jpg',
  24. },
  25. 'add_ies': ['generic'],
  26. },
  27. {
  28. 'url': 'http://www.sbs.com.au/ondemand/video/320403011771/Dingo-Conservation-The-Feed',
  29. 'only_matching': True,
  30. }]
  31. def _real_extract(self, url):
  32. mobj = re.match(self._VALID_URL, url)
  33. video_id = mobj.group('id')
  34. webpage = self._download_webpage(url, video_id)
  35. release_urls_json = js_to_json(self._search_regex(
  36. r'(?s)playerParams\.releaseUrls\s*=\s*(\{.*?\n\});\n',
  37. webpage, ''))
  38. release_urls = json.loads(release_urls_json)
  39. theplatform_url = (
  40. release_urls.get('progressive') or release_urls.get('standard'))
  41. title = remove_end(self._og_search_title(webpage), ' (The Feed)')
  42. description = self._html_search_meta('description', webpage)
  43. thumbnail = self._og_search_thumbnail(webpage)
  44. return {
  45. '_type': 'url_transparent',
  46. 'id': video_id,
  47. 'url': theplatform_url,
  48. 'title': title,
  49. 'description': description,
  50. 'thumbnail': thumbnail,
  51. }