You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
3.0 KiB

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