dotsub.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. float_or_none,
  4. int_or_none,
  5. )
  6. class DotsubIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?dotsub\.com/view/(?P<id>[^/]+)'
  8. _TESTS = [{
  9. 'url': 'https://dotsub.com/view/9c63db2a-fa95-4838-8e6e-13deafe47f09',
  10. 'md5': '21c7ff600f545358134fea762a6d42b6',
  11. 'info_dict': {
  12. 'id': '9c63db2a-fa95-4838-8e6e-13deafe47f09',
  13. 'ext': 'flv',
  14. 'title': 'MOTIVATION - "It\'s Possible" Best Inspirational Video Ever',
  15. 'description': 'md5:41af1e273edbbdfe4e216a78b9d34ac6',
  16. 'thumbnail': 're:^https?://dotsub.com/media/9c63db2a-fa95-4838-8e6e-13deafe47f09/p',
  17. 'duration': 198,
  18. 'uploader': 'liuxt',
  19. 'timestamp': 1385778501.104,
  20. 'upload_date': '20131130',
  21. 'view_count': int,
  22. }
  23. }, {
  24. 'url': 'https://dotsub.com/view/747bcf58-bd59-45b7-8c8c-ac312d084ee6',
  25. 'md5': '2bb4a83896434d5c26be868c609429a3',
  26. 'info_dict': {
  27. 'id': '168006778',
  28. 'ext': 'mp4',
  29. 'title': 'Apartments and flats in Raipur the white symphony',
  30. 'description': 'md5:784d0639e6b7d1bc29530878508e38fe',
  31. 'thumbnail': 're:^https?://dotsub.com/media/747bcf58-bd59-45b7-8c8c-ac312d084ee6/p',
  32. 'duration': 290,
  33. 'timestamp': 1476767794.2809999,
  34. 'upload_date': '20161018',
  35. 'uploader': 'parthivi001',
  36. 'uploader_id': 'user52596202',
  37. 'view_count': int,
  38. },
  39. 'add_ie': ['Vimeo'],
  40. }]
  41. def _real_extract(self, url):
  42. video_id = self._match_id(url)
  43. info = self._download_json(
  44. 'https://dotsub.com/api/media/%s/metadata' % video_id, video_id)
  45. video_url = info.get('mediaURI')
  46. if not video_url:
  47. webpage = self._download_webpage(url, video_id)
  48. video_url = self._search_regex(
  49. [r'<source[^>]+src="([^"]+)"', r'"file"\s*:\s*\'([^\']+)'],
  50. webpage, 'video url', default=None)
  51. info_dict = {
  52. 'id': video_id,
  53. 'url': video_url,
  54. 'ext': 'flv',
  55. }
  56. if not video_url:
  57. setup_data = self._parse_json(self._html_search_regex(
  58. r'(?s)data-setup=([\'"])(?P<content>(?!\1).+?)\1',
  59. webpage, 'setup data', group='content'), video_id)
  60. info_dict = {
  61. '_type': 'url_transparent',
  62. 'url': setup_data['src'],
  63. }
  64. info_dict.update({
  65. 'title': info['title'],
  66. 'description': info.get('description'),
  67. 'thumbnail': info.get('screenshotURI'),
  68. 'duration': int_or_none(info.get('duration'), 1000),
  69. 'uploader': info.get('user'),
  70. 'timestamp': float_or_none(info.get('dateCreated'), 1000),
  71. 'view_count': int_or_none(info.get('numberOfViews')),
  72. })
  73. return info_dict