dtube.py 2.7 KB

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