dlive.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import json
  2. from .common import InfoExtractor
  3. from ..utils import int_or_none
  4. class DLiveVODIE(InfoExtractor):
  5. IE_NAME = 'dlive:vod'
  6. _VALID_URL = r'https?://(?:www\.)?dlive\.tv/p/(?P<uploader_id>.+?)\+(?P<id>[^/?#&]+)'
  7. _TESTS = [{
  8. 'url': 'https://dlive.tv/p/pdp+3mTzOl4WR',
  9. 'info_dict': {
  10. 'id': '3mTzOl4WR',
  11. 'ext': 'mp4',
  12. 'title': 'Minecraft with james charles epic',
  13. 'upload_date': '20190701',
  14. 'timestamp': 1562011015,
  15. 'uploader_id': 'pdp',
  16. },
  17. }, {
  18. 'url': 'https://dlive.tv/p/pdpreplay+D-RD-xSZg',
  19. 'only_matching': True,
  20. }]
  21. def _real_extract(self, url):
  22. uploader_id, vod_id = self._match_valid_url(url).groups()
  23. broadcast = self._download_json(
  24. 'https://graphigo.prd.dlive.tv/', vod_id,
  25. data=json.dumps({'query': '''query {
  26. pastBroadcast(permlink:"%s+%s") {
  27. content
  28. createdAt
  29. length
  30. playbackUrl
  31. title
  32. thumbnailUrl
  33. viewCount
  34. }
  35. }''' % (uploader_id, vod_id)}).encode())['data']['pastBroadcast'] # noqa: UP031
  36. title = broadcast['title']
  37. formats = self._extract_m3u8_formats(
  38. broadcast['playbackUrl'], vod_id, 'mp4', 'm3u8_native')
  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/)(?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'] # noqa: UP031
  68. livestream = user['livestream']
  69. title = livestream['title']
  70. username = user['username']
  71. formats = self._extract_m3u8_formats(
  72. f'https://live.prd.dlive.tv/hls/live/{username}.m3u8',
  73. display_name, 'mp4')
  74. return {
  75. 'id': display_name,
  76. 'title': title,
  77. 'uploader': display_name,
  78. 'uploader_id': username,
  79. 'formats': formats,
  80. 'description': livestream.get('content'),
  81. 'thumbnail': livestream.get('thumbnailUrl'),
  82. 'is_live': True,
  83. 'timestamp': int_or_none(livestream.get('createdAt'), 1000),
  84. 'view_count': int_or_none(livestream.get('watchingCount')),
  85. }