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