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.

123 lines
4.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_str
  6. from ..utils import (
  7. ExtractorError,
  8. dict_get,
  9. int_or_none,
  10. unescapeHTML,
  11. parse_iso8601,
  12. )
  13. class PikselIE(InfoExtractor):
  14. _VALID_URL = r'https?://player\.piksel\.com/v/(?P<id>[a-z0-9]+)'
  15. _TESTS = [
  16. {
  17. 'url': 'http://player.piksel.com/v/nv60p12f',
  18. 'md5': 'd9c17bbe9c3386344f9cfd32fad8d235',
  19. 'info_dict': {
  20. 'id': 'nv60p12f',
  21. 'ext': 'mp4',
  22. 'title': 'فن الحياة - الحلقة 1',
  23. 'description': 'احدث برامج الداعية الاسلامي " مصطفي حسني " فى رمضان 2016علي النهار نور',
  24. 'timestamp': 1465231790,
  25. 'upload_date': '20160606',
  26. }
  27. },
  28. {
  29. # Original source: http://www.uscourts.gov/cameras-courts/state-washington-vs-donald-j-trump-et-al
  30. 'url': 'https://player.piksel.com/v/v80kqp41',
  31. 'md5': '753ddcd8cc8e4fa2dda4b7be0e77744d',
  32. 'info_dict': {
  33. 'id': 'v80kqp41',
  34. 'ext': 'mp4',
  35. 'title': 'WAW- State of Washington vs. Donald J. Trump, et al',
  36. 'description': 'State of Washington vs. Donald J. Trump, et al, Case Number 17-CV-00141-JLR, TRO Hearing, Civil Rights Case, 02/3/2017, 1:00 PM (PST), Seattle Federal Courthouse, Seattle, WA, Judge James L. Robart presiding.',
  37. 'timestamp': 1486171129,
  38. 'upload_date': '20170204',
  39. }
  40. }
  41. ]
  42. @staticmethod
  43. def _extract_url(webpage):
  44. mobj = re.search(
  45. r'<iframe[^>]+src=["\'](?P<url>(?:https?:)?//player\.piksel\.com/v/[a-z0-9]+)',
  46. webpage)
  47. if mobj:
  48. return mobj.group('url')
  49. def _real_extract(self, url):
  50. video_id = self._match_id(url)
  51. webpage = self._download_webpage(url, video_id)
  52. app_token = self._search_regex([
  53. r'clientAPI\s*:\s*"([^"]+)"',
  54. r'data-de-api-key\s*=\s*"([^"]+)"'
  55. ], webpage, 'app token')
  56. response = self._download_json(
  57. 'http://player.piksel.com/ws/ws_program/api/%s/mode/json/apiv/5' % app_token,
  58. video_id, query={
  59. 'v': video_id
  60. })['response']
  61. failure = response.get('failure')
  62. if failure:
  63. raise ExtractorError(response['failure']['reason'], expected=True)
  64. video_data = response['WsProgramResponse']['program']['asset']
  65. title = video_data['title']
  66. formats = []
  67. m3u8_url = dict_get(video_data, [
  68. 'm3u8iPadURL',
  69. 'ipadM3u8Url',
  70. 'm3u8AndroidURL',
  71. 'm3u8iPhoneURL',
  72. 'iphoneM3u8Url'])
  73. if m3u8_url:
  74. formats.extend(self._extract_m3u8_formats(
  75. m3u8_url, video_id, 'mp4', 'm3u8_native',
  76. m3u8_id='hls', fatal=False))
  77. asset_type = dict_get(video_data, ['assetType', 'asset_type'])
  78. for asset_file in video_data.get('assetFiles', []):
  79. # TODO: extract rtmp formats
  80. http_url = asset_file.get('http_url')
  81. if not http_url:
  82. continue
  83. tbr = None
  84. vbr = int_or_none(asset_file.get('videoBitrate'), 1024)
  85. abr = int_or_none(asset_file.get('audioBitrate'), 1024)
  86. if asset_type == 'video':
  87. tbr = vbr + abr
  88. elif asset_type == 'audio':
  89. tbr = abr
  90. format_id = ['http']
  91. if tbr:
  92. format_id.append(compat_str(tbr))
  93. formats.append({
  94. 'format_id': '-'.join(format_id),
  95. 'url': unescapeHTML(http_url),
  96. 'vbr': vbr,
  97. 'abr': abr,
  98. 'width': int_or_none(asset_file.get('videoWidth')),
  99. 'height': int_or_none(asset_file.get('videoHeight')),
  100. 'filesize': int_or_none(asset_file.get('filesize')),
  101. 'tbr': tbr,
  102. })
  103. self._sort_formats(formats)
  104. return {
  105. 'id': video_id,
  106. 'title': title,
  107. 'description': video_data.get('description'),
  108. 'thumbnail': video_data.get('thumbnailUrl'),
  109. 'timestamp': parse_iso8601(video_data.get('dateadd')),
  110. 'formats': formats,
  111. }