]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/dtube.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / yt_dlp / extractor / dtube.py
1 import json
2 import socket
3
4 from .common import InfoExtractor
5 from ..utils import (
6 int_or_none,
7 parse_iso8601,
8 )
9
10
11 class DTubeIE(InfoExtractor):
12 _WORKING = False
13 _VALID_URL = r'https?://(?:www\.)?d\.tube/(?:#!/)?v/(?P<uploader_id>[0-9a-z.-]+)/(?P<id>[0-9a-z]{8})'
14 _TEST = {
15 'url': 'https://d.tube/#!/v/broncnutz/x380jtr1',
16 'md5': '9f29088fa08d699a7565ee983f56a06e',
17 'info_dict': {
18 'id': 'x380jtr1',
19 'ext': 'mp4',
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,
25 },
26 'params': {
27 'format': '480p',
28 },
29 }
30
31 def _real_extract(self, url):
32 uploader_id, video_id = self._match_valid_url(url).groups()
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
48 return 'https://video.dtube.top/ipfs/' + h
49
50 formats = []
51 for q in ('240', '480', '720', '1080', ''):
52 video_url = canonical_url(content.get(f'video{q}hash'))
53 if not video_url:
54 continue
55 format_id = (q + 'p') if q else 'Source'
56 try:
57 self.to_screen(f'{video_id}: Checking {format_id} video format URL')
58 self._downloader._opener.open(video_url, timeout=5).close()
59 except socket.timeout:
60 self.to_screen(
61 f'{video_id}: {format_id} URL is invalid, skipping')
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 }