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.

53 lines
1.9 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. _TEST = {
  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. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. info = self._download_json(
  28. 'https://dotsub.com/api/media/%s/metadata' % video_id, video_id)
  29. video_url = info.get('mediaURI')
  30. if not video_url:
  31. webpage = self._download_webpage(url, video_id)
  32. video_url = self._search_regex(
  33. [r'<source[^>]+src="([^"]+)"', r'"file"\s*:\s*\'([^\']+)'],
  34. webpage, 'video url')
  35. return {
  36. 'id': video_id,
  37. 'url': video_url,
  38. 'ext': 'flv',
  39. 'title': info['title'],
  40. 'description': info.get('description'),
  41. 'thumbnail': info.get('screenshotURI'),
  42. 'duration': int_or_none(info.get('duration'), 1000),
  43. 'uploader': info.get('user'),
  44. 'timestamp': float_or_none(info.get('dateCreated'), 1000),
  45. 'view_count': int_or_none(info.get('numberOfViews')),
  46. }