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.

106 lines
3.5 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. _TEST = {
  16. 'url': 'http://player.piksel.com/v/nv60p12f',
  17. 'md5': 'd9c17bbe9c3386344f9cfd32fad8d235',
  18. 'info_dict': {
  19. 'id': 'nv60p12f',
  20. 'ext': 'mp4',
  21. 'title': 'فن الحياة - الحلقة 1',
  22. 'description': 'احدث برامج الداعية الاسلامي " مصطفي حسني " فى رمضان 2016علي النهار نور',
  23. 'timestamp': 1465231790,
  24. 'upload_date': '20160606',
  25. }
  26. }
  27. @staticmethod
  28. def _extract_url(webpage):
  29. mobj = re.search(
  30. r'<iframe[^>]+src=["\'](?P<url>(?:https?:)?//player\.piksel\.com/v/[a-z0-9]+)',
  31. webpage)
  32. if mobj:
  33. return mobj.group('url')
  34. def _real_extract(self, url):
  35. video_id = self._match_id(url)
  36. webpage = self._download_webpage(url, video_id)
  37. app_token = self._search_regex(
  38. r'clientAPI\s*:\s*"([^"]+)"', webpage, 'app token')
  39. response = self._download_json(
  40. 'http://player.piksel.com/ws/ws_program/api/%s/mode/json/apiv/5' % app_token,
  41. video_id, query={
  42. 'v': video_id
  43. })['response']
  44. failure = response.get('failure')
  45. if failure:
  46. raise ExtractorError(response['failure']['reason'], expected=True)
  47. video_data = response['WsProgramResponse']['program']['asset']
  48. title = video_data['title']
  49. formats = []
  50. m3u8_url = dict_get(video_data, [
  51. 'm3u8iPadURL',
  52. 'ipadM3u8Url',
  53. 'm3u8AndroidURL',
  54. 'm3u8iPhoneURL',
  55. 'iphoneM3u8Url'])
  56. if m3u8_url:
  57. formats.extend(self._extract_m3u8_formats(
  58. m3u8_url, video_id, 'mp4', 'm3u8_native',
  59. m3u8_id='hls', fatal=False))
  60. asset_type = dict_get(video_data, ['assetType', 'asset_type'])
  61. for asset_file in video_data.get('assetFiles', []):
  62. # TODO: extract rtmp formats
  63. http_url = asset_file.get('http_url')
  64. if not http_url:
  65. continue
  66. tbr = None
  67. vbr = int_or_none(asset_file.get('videoBitrate'), 1024)
  68. abr = int_or_none(asset_file.get('audioBitrate'), 1024)
  69. if asset_type == 'video':
  70. tbr = vbr + abr
  71. elif asset_type == 'audio':
  72. tbr = abr
  73. format_id = ['http']
  74. if tbr:
  75. format_id.append(compat_str(tbr))
  76. formats.append({
  77. 'format_id': '-'.join(format_id),
  78. 'url': unescapeHTML(http_url),
  79. 'vbr': vbr,
  80. 'abr': abr,
  81. 'width': int_or_none(asset_file.get('videoWidth')),
  82. 'height': int_or_none(asset_file.get('videoHeight')),
  83. 'filesize': int_or_none(asset_file.get('filesize')),
  84. 'tbr': tbr,
  85. })
  86. self._sort_formats(formats)
  87. return {
  88. 'id': video_id,
  89. 'title': title,
  90. 'description': video_data.get('description'),
  91. 'thumbnail': video_data.get('thumbnailUrl'),
  92. 'timestamp': parse_iso8601(video_data.get('dateadd')),
  93. 'formats': formats,
  94. }