logo

youtube-dl

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

playstuff.py (2254B)


  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..compat import compat_str
  4. from ..utils import (
  5. smuggle_url,
  6. try_get,
  7. )
  8. class PlayStuffIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?play\.stuff\.co\.nz/details/(?P<id>[^/?#&]+)'
  10. _TESTS = [{
  11. 'url': 'https://play.stuff.co.nz/details/608778ac1de1c4001a3fa09a',
  12. 'md5': 'c82d3669e5247c64bc382577843e5bd0',
  13. 'info_dict': {
  14. 'id': '6250584958001',
  15. 'ext': 'mp4',
  16. 'title': 'Episode 1: Rotorua/Mt Maunganui/Tauranga',
  17. 'description': 'md5:c154bafb9f0dd02d01fd4100fb1c1913',
  18. 'uploader_id': '6005208634001',
  19. 'timestamp': 1619491027,
  20. 'upload_date': '20210427',
  21. },
  22. 'add_ie': ['BrightcoveNew'],
  23. }, {
  24. # geo restricted, bypassable
  25. 'url': 'https://play.stuff.co.nz/details/_6155660351001',
  26. 'only_matching': True,
  27. }]
  28. BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/%s_default/index.html?videoId=%s'
  29. def _real_extract(self, url):
  30. video_id = self._match_id(url)
  31. webpage = self._download_webpage(url, video_id)
  32. state = self._parse_json(
  33. self._search_regex(
  34. r'__INITIAL_STATE__\s*=\s*({.+?})\s*;', webpage, 'state'),
  35. video_id)
  36. account_id = try_get(
  37. state, lambda x: x['configurations']['accountId'],
  38. compat_str) or '6005208634001'
  39. player_id = try_get(
  40. state, lambda x: x['configurations']['playerId'],
  41. compat_str) or 'default'
  42. entries = []
  43. for item_id, video in state['items'].items():
  44. if not isinstance(video, dict):
  45. continue
  46. asset_id = try_get(
  47. video, lambda x: x['content']['attributes']['assetId'],
  48. compat_str)
  49. if not asset_id:
  50. continue
  51. entries.append(self.url_result(
  52. smuggle_url(
  53. self.BRIGHTCOVE_URL_TEMPLATE % (account_id, player_id, asset_id),
  54. {'geo_countries': ['NZ']}),
  55. 'BrightcoveNew', video_id))
  56. return self.playlist_result(entries, video_id)