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.

65 lines
2.0 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. determine_ext,
  8. compat_urllib_parse,
  9. compat_urllib_request,
  10. )
  11. class PromptFileIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?promptfile\.com/l/(?P<id>[0-9A-Z\-]+)'
  13. _TEST = {
  14. 'url': 'http://www.promptfile.com/l/D21B4746E9-F01462F0FF',
  15. 'md5': 'd1451b6302da7215485837aaea882c4c',
  16. 'info_dict': {
  17. 'id': 'D21B4746E9-F01462F0FF',
  18. 'ext': 'mp4',
  19. 'title': 'Birds.mp4',
  20. 'thumbnail': 're:^https?://.*\.jpg$',
  21. }
  22. }
  23. def _real_extract(self, url):
  24. video_id = self._match_id(url)
  25. webpage = self._download_webpage(url, video_id)
  26. if re.search(r'<div.+id="not_found_msg".+>(?!We are).+</div>[^-]', webpage) is not None:
  27. raise ExtractorError('Video %s does not exist' % video_id,
  28. expected=True)
  29. fields = dict(re.findall(r'''(?x)type="hidden"\s+
  30. name="(.+?)"\s+
  31. value="(.*?)"
  32. ''', webpage))
  33. post = compat_urllib_parse.urlencode(fields)
  34. req = compat_urllib_request.Request(url, post)
  35. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  36. webpage = self._download_webpage(
  37. req, video_id, 'Downloading video page')
  38. url = self._html_search_regex(r'url:\s*\'([^\']+)\'', webpage, 'URL')
  39. title = self._html_search_regex(
  40. r'<span.+title="([^"]+)">', webpage, 'title')
  41. thumbnail = self._html_search_regex(
  42. r'<div id="player_overlay">.*button>.*?<img src="([^"]+)"',
  43. webpage, 'thumbnail', fatal=False, flags=re.DOTALL)
  44. formats = [{
  45. 'format_id': 'sd',
  46. 'url': url,
  47. 'ext': determine_ext(title),
  48. }]
  49. self._sort_formats(formats)
  50. return {
  51. 'id': video_id,
  52. 'title': title,
  53. 'thumbnail': thumbnail,
  54. 'formats': formats,
  55. }