]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/dlive.py
[spotify] Detect iframe embeds (#3430)
[yt-dlp.git] / yt_dlp / extractor / dlive.py
1 import json
2
3 from .common import InfoExtractor
4 from ..utils import int_or_none
5
6
7 class DLiveVODIE(InfoExtractor):
8 IE_NAME = 'dlive:vod'
9 _VALID_URL = r'https?://(?:www\.)?dlive\.tv/p/(?P<uploader_id>.+?)\+(?P<id>[^/?#&]+)'
10 _TESTS = [{
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 }
20 }, {
21 'url': 'https://dlive.tv/p/pdpreplay+D-RD-xSZg',
22 'only_matching': True,
23 }]
24
25 def _real_extract(self, url):
26 uploader_id, vod_id = self._match_valid_url(url).groups()
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')
43 self._sort_formats(formats)
44 return {
45 'id': vod_id,
46 'title': title,
47 'uploader_id': uploader_id,
48 'formats': formats,
49 'description': broadcast.get('content'),
50 'thumbnail': broadcast.get('thumbnailUrl'),
51 'timestamp': int_or_none(broadcast.get('createdAt'), 1000),
52 'view_count': int_or_none(broadcast.get('viewCount')),
53 }
54
55
56 class DLiveStreamIE(InfoExtractor):
57 IE_NAME = 'dlive:stream'
58 _VALID_URL = r'https?://(?:www\.)?dlive\.tv/(?!p/)(?P<id>[\w.-]+)'
59
60 def _real_extract(self, url):
61 display_name = self._match_id(url)
62 user = self._download_json(
63 'https://graphigo.prd.dlive.tv/', display_name,
64 data=json.dumps({'query': '''query {
65 userByDisplayName(displayname:"%s") {
66 livestream {
67 content
68 createdAt
69 title
70 thumbnailUrl
71 watchingCount
72 }
73 username
74 }
75 }''' % display_name}).encode())['data']['userByDisplayName']
76 livestream = user['livestream']
77 title = livestream['title']
78 username = user['username']
79 formats = self._extract_m3u8_formats(
80 'https://live.prd.dlive.tv/hls/live/%s.m3u8' % username,
81 display_name, 'mp4')
82 self._sort_formats(formats)
83 return {
84 'id': display_name,
85 'title': title,
86 'uploader': display_name,
87 'uploader_id': username,
88 'formats': formats,
89 'description': livestream.get('content'),
90 'thumbnail': livestream.get('thumbnailUrl'),
91 'is_live': True,
92 'timestamp': int_or_none(livestream.get('createdAt'), 1000),
93 'view_count': int_or_none(livestream.get('watchingCount')),
94 }