promptfile.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_urllib_parse_urlencode
  6. from ..utils import (
  7. determine_ext,
  8. ExtractorError,
  9. sanitized_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 = self._hidden_inputs(webpage)
  30. post = compat_urllib_parse_urlencode(fields)
  31. req = sanitized_Request(url, post)
  32. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  33. webpage = self._download_webpage(
  34. req, video_id, 'Downloading video page')
  35. url = self._html_search_regex(r'url:\s*\'([^\']+)\'', webpage, 'URL')
  36. title = self._html_search_regex(
  37. r'<span.+title="([^"]+)">', webpage, 'title')
  38. thumbnail = self._html_search_regex(
  39. r'<div id="player_overlay">.*button>.*?<img src="([^"]+)"',
  40. webpage, 'thumbnail', fatal=False, flags=re.DOTALL)
  41. formats = [{
  42. 'format_id': 'sd',
  43. 'url': url,
  44. 'ext': determine_ext(title),
  45. }]
  46. self._sort_formats(formats)
  47. return {
  48. 'id': video_id,
  49. 'title': title,
  50. 'thumbnail': thumbnail,
  51. 'formats': formats,
  52. }