vporn.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. parse_duration,
  6. str_to_int,
  7. )
  8. class VpornIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?vporn\.com/[^/]+/(?P<display_id>[^/]+)/(?P<id>\d+)'
  10. _TESTS = [
  11. {
  12. 'url': 'http://www.vporn.com/masturbation/violet-on-her-th-birthday/497944/',
  13. 'md5': 'facf37c1b86546fa0208058546842c55',
  14. 'info_dict': {
  15. 'id': '497944',
  16. 'display_id': 'violet-on-her-th-birthday',
  17. 'ext': 'mp4',
  18. 'title': 'Violet on her 19th birthday',
  19. 'description': 'Violet dances in front of the camera which is sure to get you horny.',
  20. 'thumbnail': 're:^https?://.*\.jpg$',
  21. 'uploader': 'kileyGrope',
  22. 'categories': ['Masturbation', 'Teen'],
  23. 'duration': 393,
  24. 'age_limit': 18,
  25. 'view_count': int,
  26. 'like_count': int,
  27. 'dislike_count': int,
  28. 'comment_count': int,
  29. }
  30. },
  31. {
  32. 'url': 'http://www.vporn.com/female/hana-shower/523564/',
  33. 'md5': 'ced35a4656198a1664cf2cda1575a25f',
  34. 'info_dict': {
  35. 'id': '523564',
  36. 'display_id': 'hana-shower',
  37. 'ext': 'mp4',
  38. 'title': 'Hana Shower',
  39. 'description': 'Hana showers at the bathroom.',
  40. 'thumbnail': 're:^https?://.*\.jpg$',
  41. 'uploader': 'Hmmmmm',
  42. 'categories': ['Big Boobs', 'Erotic', 'Teen', 'Female'],
  43. 'duration': 588,
  44. 'age_limit': 18,
  45. 'view_count': int,
  46. 'like_count': int,
  47. 'dislike_count': int,
  48. 'comment_count': int,
  49. }
  50. },
  51. ]
  52. def _real_extract(self, url):
  53. mobj = re.match(self._VALID_URL, url)
  54. video_id = mobj.group('id')
  55. display_id = mobj.group('display_id')
  56. webpage = self._download_webpage(url, display_id)
  57. title = self._html_search_regex(
  58. r'videoname\s*=\s*\'([^\']+)\'', webpage, 'title').strip()
  59. description = self._html_search_regex(
  60. r'class="(?:descr|description_txt)">(.*?)</div>',
  61. webpage, 'description', fatal=False)
  62. thumbnail = self._html_search_regex(
  63. r'flashvars\.imageUrl\s*=\s*"([^"]+)"', webpage, 'description', fatal=False, default=None)
  64. if thumbnail:
  65. thumbnail = 'http://www.vporn.com' + thumbnail
  66. uploader = self._html_search_regex(
  67. r'(?s)Uploaded by:.*?<a href="/user/[^"]+">([^<]+)</a>',
  68. webpage, 'uploader', fatal=False)
  69. categories = re.findall(r'<a href="/cat/[^"]+">([^<]+)</a>', webpage)
  70. duration = parse_duration(self._search_regex(
  71. r'Runtime:\s*</span>\s*(\d+ min \d+ sec)',
  72. webpage, 'duration', fatal=False))
  73. view_count = str_to_int(self._search_regex(
  74. r'class="views">([\d,\.]+) [Vv]iews<',
  75. webpage, 'view count', fatal=False))
  76. comment_count = str_to_int(self._html_search_regex(
  77. r"'Comments \(([\d,\.]+)\)'",
  78. webpage, 'comment count', default=None))
  79. formats = []
  80. for video in re.findall(r'flashvars\.videoUrl([^=]+?)\s*=\s*"(https?://[^"]+)"', webpage):
  81. video_url = video[1]
  82. fmt = {
  83. 'url': video_url,
  84. 'format_id': video[0],
  85. }
  86. m = re.search(r'_(?P<width>\d+)x(?P<height>\d+)_(?P<vbr>\d+)k\.mp4$', video_url)
  87. if m:
  88. fmt.update({
  89. 'width': int(m.group('width')),
  90. 'height': int(m.group('height')),
  91. 'vbr': int(m.group('vbr')),
  92. })
  93. formats.append(fmt)
  94. self._sort_formats(formats)
  95. return {
  96. 'id': video_id,
  97. 'display_id': display_id,
  98. 'title': title,
  99. 'description': description,
  100. 'thumbnail': thumbnail,
  101. 'uploader': uploader,
  102. 'categories': categories,
  103. 'duration': duration,
  104. 'view_count': view_count,
  105. 'comment_count': comment_count,
  106. 'age_limit': 18,
  107. 'formats': formats,
  108. }