logo

youtube-dl

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

dlive.py (3121B)


  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>[^/?#&]+)'
  9. _TESTS = [{
  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. 'url': 'https://dlive.tv/p/pdpreplay+D-RD-xSZg',
  21. 'only_matching': True,
  22. }]
  23. def _real_extract(self, url):
  24. uploader_id, vod_id = re.match(self._VALID_URL, url).groups()
  25. broadcast = self._download_json(
  26. 'https://graphigo.prd.dlive.tv/', vod_id,
  27. data=json.dumps({'query': '''query {
  28. pastBroadcast(permlink:"%s+%s") {
  29. content
  30. createdAt
  31. length
  32. playbackUrl
  33. title
  34. thumbnailUrl
  35. viewCount
  36. }
  37. }''' % (uploader_id, vod_id)}).encode())['data']['pastBroadcast']
  38. title = broadcast['title']
  39. formats = self._extract_m3u8_formats(
  40. broadcast['playbackUrl'], vod_id, 'mp4', 'm3u8_native')
  41. self._sort_formats(formats)
  42. return {
  43. 'id': vod_id,
  44. 'title': title,
  45. 'uploader_id': uploader_id,
  46. 'formats': formats,
  47. 'description': broadcast.get('content'),
  48. 'thumbnail': broadcast.get('thumbnailUrl'),
  49. 'timestamp': int_or_none(broadcast.get('createdAt'), 1000),
  50. 'view_count': int_or_none(broadcast.get('viewCount')),
  51. }
  52. class DLiveStreamIE(InfoExtractor):
  53. IE_NAME = 'dlive:stream'
  54. _VALID_URL = r'https?://(?:www\.)?dlive\.tv/(?!p/)(?P<id>[\w.-]+)'
  55. def _real_extract(self, url):
  56. display_name = self._match_id(url)
  57. user = self._download_json(
  58. 'https://graphigo.prd.dlive.tv/', display_name,
  59. data=json.dumps({'query': '''query {
  60. userByDisplayName(displayname:"%s") {
  61. livestream {
  62. content
  63. createdAt
  64. title
  65. thumbnailUrl
  66. watchingCount
  67. }
  68. username
  69. }
  70. }''' % display_name}).encode())['data']['userByDisplayName']
  71. livestream = user['livestream']
  72. title = livestream['title']
  73. username = user['username']
  74. formats = self._extract_m3u8_formats(
  75. 'https://live.prd.dlive.tv/hls/live/%s.m3u8' % username,
  76. display_name, 'mp4')
  77. self._sort_formats(formats)
  78. return {
  79. 'id': display_name,
  80. 'title': self._live_title(title),
  81. 'uploader': display_name,
  82. 'uploader_id': username,
  83. 'formats': formats,
  84. 'description': livestream.get('content'),
  85. 'thumbnail': livestream.get('thumbnailUrl'),
  86. 'is_live': True,
  87. 'timestamp': int_or_none(livestream.get('createdAt'), 1000),
  88. 'view_count': int_or_none(livestream.get('watchingCount')),
  89. }