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.

98 lines
3.3 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. 'url': 'https://www.pornflip.com/v/EkRD6-vS2-s',
  36. 'only_matching': True,
  37. }, {
  38. 'url': 'https://www.pornflip.com/embed/EkRD6-vS2-s',
  39. 'only_matching': True,
  40. }]
  41. def _real_extract(self, url):
  42. video_id = self._match_id(url)
  43. webpage = self._download_webpage(
  44. 'https://www.pornflip.com/v/%s' % video_id, video_id)
  45. flashvars = compat_parse_qs(self._search_regex(
  46. r'<embed[^>]+flashvars=(["\'])(?P<flashvars>(?:(?!\1).)+)\1',
  47. webpage, 'flashvars', group='flashvars'))
  48. title = flashvars['video_vars[title]'][0]
  49. def flashvar(kind):
  50. return try_get(
  51. flashvars, lambda x: x['video_vars[%s]' % kind][0], compat_str)
  52. formats = []
  53. for key, value in flashvars.items():
  54. if not (value and isinstance(value, list)):
  55. continue
  56. format_url = value[0]
  57. if key == 'video_vars[hds_manifest]':
  58. formats.extend(self._extract_mpd_formats(
  59. format_url, video_id, mpd_id='dash', fatal=False))
  60. continue
  61. height = self._search_regex(
  62. r'video_vars\[video_urls\]\[(\d+)', key, 'height', default=None)
  63. if not height:
  64. continue
  65. formats.append({
  66. 'url': format_url,
  67. 'format_id': 'http-%s' % height,
  68. 'height': int_or_none(height),
  69. })
  70. self._sort_formats(formats)
  71. uploader = self._html_search_regex(
  72. (r'<span[^>]+class="name"[^>]*>\s*<a[^>]+>\s*<strong>(?P<uploader>[^<]+)',
  73. r'<meta[^>]+content=(["\'])[^>]*\buploaded by (?P<uploader>.+?)\1'),
  74. webpage, 'uploader', fatal=False, group='uploader')
  75. return {
  76. 'id': video_id,
  77. 'formats': formats,
  78. 'title': title,
  79. 'thumbnail': flashvar('big_thumb'),
  80. 'duration': int_or_none(flashvar('duration')),
  81. 'timestamp': unified_timestamp(self._html_search_meta(
  82. 'uploadDate', webpage, 'timestamp')),
  83. 'uploader_id': flashvar('author_id'),
  84. 'uploader': uploader,
  85. 'view_count': int_or_none(flashvar('views')),
  86. 'age_limit': 18,
  87. }