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.

92 lines
3.1 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_parse_qs,
  6. compat_str,
  7. )
  8. from ..utils import (
  9. int_or_none,
  10. try_get,
  11. unified_timestamp,
  12. )
  13. class PornFlipIE(InfoExtractor):
  14. _VALID_URL = r'https?://(?:www\.)?pornflip\.com/(?:v|embed)/(?P<id>[0-9A-Za-z]{11})'
  15. _TESTS = [{
  16. 'url': 'https://www.pornflip.com/v/wz7DfNhMmep',
  17. 'md5': '98c46639849145ae1fd77af532a9278c',
  18. 'info_dict': {
  19. 'id': 'wz7DfNhMmep',
  20. 'ext': 'mp4',
  21. 'title': '2 Amateurs swallow make his dream cumshots true',
  22. 'thumbnail': r're:^https?://.*\.jpg$',
  23. 'duration': 112,
  24. 'timestamp': 1481655502,
  25. 'upload_date': '20161213',
  26. 'uploader_id': '106786',
  27. 'uploader': 'figifoto',
  28. 'view_count': int,
  29. 'age_limit': 18,
  30. }
  31. }, {
  32. 'url': 'https://www.pornflip.com/embed/wz7DfNhMmep',
  33. 'only_matching': True,
  34. }]
  35. def _real_extract(self, url):
  36. video_id = self._match_id(url)
  37. webpage = self._download_webpage(
  38. 'https://www.pornflip.com/v/%s' % video_id, video_id)
  39. flashvars = compat_parse_qs(self._search_regex(
  40. r'<embed[^>]+flashvars=(["\'])(?P<flashvars>(?:(?!\1).)+)\1',
  41. webpage, 'flashvars', group='flashvars'))
  42. title = flashvars['video_vars[title]'][0]
  43. def flashvar(kind):
  44. return try_get(
  45. flashvars, lambda x: x['video_vars[%s]' % kind][0], compat_str)
  46. formats = []
  47. for key, value in flashvars.items():
  48. if not (value and isinstance(value, list)):
  49. continue
  50. format_url = value[0]
  51. if key == 'video_vars[hds_manifest]':
  52. formats.extend(self._extract_mpd_formats(
  53. format_url, video_id, mpd_id='dash', fatal=False))
  54. continue
  55. height = self._search_regex(
  56. r'video_vars\[video_urls\]\[(\d+)', key, 'height', default=None)
  57. if not height:
  58. continue
  59. formats.append({
  60. 'url': format_url,
  61. 'format_id': 'http-%s' % height,
  62. 'height': int_or_none(height),
  63. })
  64. self._sort_formats(formats)
  65. uploader = self._html_search_regex(
  66. (r'<span[^>]+class="name"[^>]*>\s*<a[^>]+>\s*<strong>(?P<uploader>[^<]+)',
  67. r'<meta[^>]+content=(["\'])[^>]*\buploaded by (?P<uploader>.+?)\1'),
  68. webpage, 'uploader', fatal=False, group='uploader')
  69. return {
  70. 'id': video_id,
  71. 'formats': formats,
  72. 'title': title,
  73. 'thumbnail': flashvar('big_thumb'),
  74. 'duration': int_or_none(flashvar('duration')),
  75. 'timestamp': unified_timestamp(self._html_search_meta(
  76. 'uploadDate', webpage, 'timestamp')),
  77. 'uploader_id': flashvar('author_id'),
  78. 'uploader': uploader,
  79. 'view_count': int_or_none(flashvar('views')),
  80. 'age_limit': 18,
  81. }