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.

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