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