]>
Commit | Line | Data |
---|---|---|
7f34984e | 1 | import json |
7f34984e RA |
2 | from socket import timeout |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..utils import ( | |
6 | int_or_none, | |
7 | parse_iso8601, | |
8 | ) | |
9 | ||
10 | ||
11 | class 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', ''): | |
52 | video_url = canonical_url(content.get('video%shash' % q)) | |
53 | if not video_url: | |
54 | continue | |
55 | format_id = (q + 'p') if q else 'Source' | |
56 | try: | |
57 | self.to_screen('%s: Checking %s video format URL' % (video_id, format_id)) | |
58 | self._downloader._opener.open(video_url, timeout=5).close() | |
6f9f3340 | 59 | except timeout: |
7f34984e RA |
60 | self.to_screen( |
61 | '%s: %s URL is invalid, skipping' % (video_id, format_id)) | |
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 | } |