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 ..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. _FILE_NOT_FOUND_REGEX = r'<div.+id="not_found_msg".+>.+</div>[^-]'
  14. _TEST = {
  15. 'url': 'http://www.promptfile.com/l/D21B4746E9-F01462F0FF',
  16. 'md5': 'd1451b6302da7215485837aaea882c4c',
  17. 'info_dict': {
  18. 'id': 'D21B4746E9-F01462F0FF',
  19. 'ext': 'mp4',
  20. 'title': 'Birds.mp4',
  21. 'thumbnail': 're:^https?://.*\.jpg$',
  22. }
  23. }
  24. def _real_extract(self, url):
  25. mobj = re.match(self._VALID_URL, url)
  26. video_id = mobj.group('id')
  27. webpage = self._download_webpage(url, video_id)
  28. if re.search(self._FILE_NOT_FOUND_REGEX, 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. }