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.

67 lines
2.1 KiB

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