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