dlive.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. from __future__ import unicode_literals
  2. import json
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import int_or_none
  6. class DLiveVODIE(InfoExtractor):
  7. IE_NAME = 'dlive:vod'
  8. _VALID_URL = r'https?://(?:www\.)?dlive\.tv/p/(?P<uploader_id>.+?)\+(?P<id>[a-zA-Z0-9]+)'
  9. _TEST = {
  10. 'url': 'https://dlive.tv/p/pdp+3mTzOl4WR',
  11. 'info_dict': {
  12. 'id': '3mTzOl4WR',
  13. 'ext': 'mp4',
  14. 'title': 'Minecraft with james charles epic',
  15. 'upload_date': '20190701',
  16. 'timestamp': 1562011015,
  17. 'uploader_id': 'pdp',
  18. }
  19. }
  20. def _real_extract(self, url):
  21. uploader_id, vod_id = re.match(self._VALID_URL, url).groups()
  22. broadcast = self._download_json(
  23. 'https://graphigo.prd.dlive.tv/', vod_id,
  24. data=json.dumps({'query': '''query {
  25. pastBroadcast(permlink:"%s+%s") {
  26. content
  27. createdAt
  28. length
  29. playbackUrl
  30. title
  31. thumbnailUrl
  32. viewCount
  33. }
  34. }''' % (uploader_id, vod_id)}).encode())['data']['pastBroadcast']
  35. title = broadcast['title']
  36. formats = self._extract_m3u8_formats(
  37. broadcast['playbackUrl'], vod_id, 'mp4', 'm3u8_native')
  38. self._sort_formats(formats)
  39. return {
  40. 'id': vod_id,
  41. 'title': title,
  42. 'uploader_id': uploader_id,
  43. 'formats': formats,
  44. 'description': broadcast.get('content'),
  45. 'thumbnail': broadcast.get('thumbnailUrl'),
  46. 'timestamp': int_or_none(broadcast.get('createdAt'), 1000),
  47. 'view_count': int_or_none(broadcast.get('viewCount')),
  48. }
  49. class DLiveStreamIE(InfoExtractor):
  50. IE_NAME = 'dlive:stream'
  51. _VALID_URL = r'https?://(?:www\.)?dlive\.tv/(?P<id>[\w.-]+)'
  52. def _real_extract(self, url):
  53. display_name = self._match_id(url)
  54. user = self._download_json(
  55. 'https://graphigo.prd.dlive.tv/', display_name,
  56. data=json.dumps({'query': '''query {
  57. userByDisplayName(displayname:"%s") {
  58. livestream {
  59. content
  60. createdAt
  61. title
  62. thumbnailUrl
  63. watchingCount
  64. }
  65. username
  66. }
  67. }''' % display_name}).encode())['data']['userByDisplayName']
  68. livestream = user['livestream']
  69. title = livestream['title']
  70. username = user['username']
  71. formats = self._extract_m3u8_formats(
  72. 'https://live.prd.dlive.tv/hls/live/%s.m3u8' % username,
  73. display_name, 'mp4')
  74. self._sort_formats(formats)
  75. return {
  76. 'id': display_name,
  77. 'title': self._live_title(title),
  78. 'uploader': display_name,
  79. 'uploader_id': username,
  80. 'formats': formats,
  81. 'description': livestream.get('content'),
  82. 'thumbnail': livestream.get('thumbnailUrl'),
  83. 'is_live': True,
  84. 'timestamp': int_or_none(livestream.get('createdAt'), 1000),
  85. 'view_count': int_or_none(livestream.get('watchingCount')),
  86. }