pornflip.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_parse_qs,
  6. )
  7. from ..utils import (
  8. int_or_none,
  9. try_get,
  10. RegexNotFoundError,
  11. )
  12. class PornFlipIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?pornflip\.com/v/(?P<id>[0-9A-Za-z]{11})'
  14. _TEST = {
  15. 'url': 'https://www.pornflip.com/v/wz7DfNhMmep',
  16. 'md5': '98c46639849145ae1fd77af532a9278c',
  17. 'info_dict': {
  18. 'id': 'wz7DfNhMmep',
  19. 'ext': 'mp4',
  20. 'title': '2 Amateurs swallow make his dream cumshots true',
  21. 'uploader': 'figifoto',
  22. 'thumbnail': r're:^https?://.*\.jpg$',
  23. 'age_limit': 18,
  24. }
  25. }
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. webpage = self._download_webpage(url, video_id)
  29. uploader = self._html_search_regex(
  30. r'<span class="name">\s+<a class="ajax" href=".+>\s+<strong>([^<]+)<', webpage, 'uploader', fatal=False)
  31. flashvars = compat_parse_qs(self._html_search_regex(
  32. r'<embed.+?flashvars="([^"]+)"',
  33. webpage, 'flashvars'))
  34. title = flashvars['video_vars[title]'][0]
  35. thumbnail = try_get(flashvars, lambda x: x['video_vars[big_thumb]'][0])
  36. formats = []
  37. for k, v in flashvars.items():
  38. height = self._search_regex(r'video_vars\[video_urls\]\[(\d+).+?\]', k, 'height', default=None)
  39. if height:
  40. url = v[0]
  41. formats.append({
  42. 'height': int_or_none(height),
  43. 'url': url
  44. })
  45. self._sort_formats(formats)
  46. return {
  47. 'id': video_id,
  48. 'formats': formats,
  49. 'title': title,
  50. 'uploader': uploader,
  51. 'thumbnail': thumbnail,
  52. 'age_limit': 18,
  53. }