]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/dtube.py
[ie/PrankCastPost] Add extractor (#8933)
[yt-dlp.git] / yt_dlp / extractor / dtube.py
CommitLineData
7f34984e 1import json
7f34984e
RA
2from socket import timeout
3
4from .common import InfoExtractor
5from ..utils import (
6 int_or_none,
7 parse_iso8601,
8)
9
10
11class DTubeIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?d\.tube/(?:#!/)?v/(?P<uploader_id>[0-9a-z.-]+)/(?P<id>[0-9a-z]{8})'
13 _TEST = {
0266854f
S
14 'url': 'https://d.tube/#!/v/broncnutz/x380jtr1',
15 'md5': '9f29088fa08d699a7565ee983f56a06e',
7f34984e 16 'info_dict': {
0266854f 17 'id': 'x380jtr1',
7f34984e 18 'ext': 'mp4',
0266854f
S
19 'title': 'Lefty 3-Rings is Back Baby!! NCAA Picks',
20 'description': 'md5:60be222088183be3a42f196f34235776',
21 'uploader_id': 'broncnutz',
22 'upload_date': '20190107',
23 'timestamp': 1546854054,
7f34984e
RA
24 },
25 'params': {
26 'format': '480p',
27 },
28 }
29
30 def _real_extract(self, url):
5ad28e7f 31 uploader_id, video_id = self._match_valid_url(url).groups()
7f34984e
RA
32 result = self._download_json('https://api.steemit.com/', video_id, data=json.dumps({
33 'jsonrpc': '2.0',
34 'method': 'get_content',
35 'params': [uploader_id, video_id],
36 }).encode())['result']
37
38 metadata = json.loads(result['json_metadata'])
39 video = metadata['video']
40 content = video['content']
41 info = video.get('info', {})
42 title = info.get('title') or result['title']
43
44 def canonical_url(h):
45 if not h:
46 return None
bcc334a3 47 return 'https://video.dtube.top/ipfs/' + h
7f34984e
RA
48
49 formats = []
50 for q in ('240', '480', '720', '1080', ''):
51 video_url = canonical_url(content.get('video%shash' % q))
52 if not video_url:
53 continue
54 format_id = (q + 'p') if q else 'Source'
55 try:
56 self.to_screen('%s: Checking %s video format URL' % (video_id, format_id))
57 self._downloader._opener.open(video_url, timeout=5).close()
6f9f3340 58 except timeout:
7f34984e
RA
59 self.to_screen(
60 '%s: %s URL is invalid, skipping' % (video_id, format_id))
61 continue
62 formats.append({
63 'format_id': format_id,
64 'url': video_url,
65 'height': int_or_none(q),
66 'ext': 'mp4',
67 })
68
69 return {
70 'id': video_id,
71 'title': title,
72 'description': content.get('description'),
73 'thumbnail': canonical_url(info.get('snaphash')),
74 'tags': content.get('tags') or metadata.get('tags'),
75 'duration': info.get('duration'),
76 'formats': formats,
77 'timestamp': parse_iso8601(result.get('created')),
78 'uploader_id': uploader_id,
79 }