]>
Commit | Line | Data |
---|---|---|
4a71ef6d RA |
1 | from __future__ import unicode_literals |
2 | ||
3 | import json | |
4a71ef6d RA |
4 | |
5 | from .common import InfoExtractor | |
6 | from ..utils import int_or_none | |
7 | ||
8 | ||
9 | class DLiveVODIE(InfoExtractor): | |
10 | IE_NAME = 'dlive:vod' | |
07ab44c4 C |
11 | _VALID_URL = r'https?://(?:www\.)?dlive\.tv/p/(?P<uploader_id>.+?)\+(?P<id>[^/?#&]+)' |
12 | _TESTS = [{ | |
4a71ef6d RA |
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 | } | |
07ab44c4 C |
22 | }, { |
23 | 'url': 'https://dlive.tv/p/pdpreplay+D-RD-xSZg', | |
24 | 'only_matching': True, | |
25 | }] | |
4a71ef6d RA |
26 | |
27 | def _real_extract(self, url): | |
5ad28e7f | 28 | uploader_id, vod_id = self._match_valid_url(url).groups() |
4a71ef6d RA |
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' | |
b99f11a5 | 60 | _VALID_URL = r'https?://(?:www\.)?dlive\.tv/(?!p/)(?P<id>[\w.-]+)' |
4a71ef6d RA |
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, | |
39ca3b5c | 87 | 'title': title, |
4a71ef6d RA |
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 | } |