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