logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

dtube.py (2798B)


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