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.

64 lines
2.0 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 = self._form_hidden_inputs(webpage)
  32. post = compat_urllib_parse.urlencode(fields)
  33. req = compat_urllib_request.Request(url, post)
  34. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  35. webpage = self._download_webpage(
  36. req, video_id, 'Downloading video page')
  37. url = self._html_search_regex(r'url:\s*\'([^\']+)\'', webpage, 'URL')
  38. title = self._html_search_regex(
  39. r'<span.+title="([^"]+)">', webpage, 'title')
  40. thumbnail = self._html_search_regex(
  41. r'<div id="player_overlay">.*button>.*?<img src="([^"]+)"',
  42. webpage, 'thumbnail', fatal=False, flags=re.DOTALL)
  43. formats = [{
  44. 'format_id': 'sd',
  45. 'url': url,
  46. 'ext': determine_ext(title),
  47. }]
  48. self._sort_formats(formats)
  49. return {
  50. 'id': video_id,
  51. 'title': title,
  52. 'thumbnail': thumbnail,
  53. 'formats': formats,
  54. }