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.

127 lines
4.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. parse_iso8601,
  7. int_or_none,
  8. xpath_attr,
  9. xpath_element,
  10. )
  11. class TwentyFourVideoIE(InfoExtractor):
  12. IE_NAME = '24video'
  13. _VALID_URL = r'''(?x)
  14. https?://
  15. (?P<host>
  16. (?:(?:www|porno)\.)?24video\.
  17. (?:net|me|xxx|sexy?|tube|adult|site)
  18. )/
  19. (?:
  20. video/(?:(?:view|xml)/)?|
  21. player/new24_play\.swf\?id=
  22. )
  23. (?P<id>\d+)
  24. '''
  25. _TESTS = [{
  26. 'url': 'http://www.24video.net/video/view/1044982',
  27. 'md5': 'e09fc0901d9eaeedac872f154931deeb',
  28. 'info_dict': {
  29. 'id': '1044982',
  30. 'ext': 'mp4',
  31. 'title': 'Эротика каменного века',
  32. 'description': 'Как смотрели порно в каменном веке.',
  33. 'thumbnail': r're:^https?://.*\.jpg$',
  34. 'uploader': 'SUPERTELO',
  35. 'duration': 31,
  36. 'timestamp': 1275937857,
  37. 'upload_date': '20100607',
  38. 'age_limit': 18,
  39. 'like_count': int,
  40. 'dislike_count': int,
  41. },
  42. }, {
  43. 'url': 'http://www.24video.net/player/new24_play.swf?id=1044982',
  44. 'only_matching': True,
  45. }, {
  46. 'url': 'http://www.24video.me/video/view/1044982',
  47. 'only_matching': True,
  48. }, {
  49. 'url': 'http://www.24video.tube/video/view/2363750',
  50. 'only_matching': True,
  51. }, {
  52. 'url': 'https://www.24video.site/video/view/2640421',
  53. 'only_matching': True,
  54. }, {
  55. 'url': 'https://porno.24video.net/video/2640421-vsya-takaya-gibkaya-i-v-masle',
  56. 'only_matching': True,
  57. }]
  58. def _real_extract(self, url):
  59. mobj = re.match(self._VALID_URL, url)
  60. video_id = mobj.group('id')
  61. host = mobj.group('host')
  62. webpage = self._download_webpage(
  63. 'http://%s/video/view/%s' % (host, video_id), video_id)
  64. title = self._og_search_title(webpage)
  65. description = self._html_search_regex(
  66. r'<(p|span)[^>]+itemprop="description"[^>]*>(?P<description>[^<]+)</\1>',
  67. webpage, 'description', fatal=False, group='description')
  68. thumbnail = self._og_search_thumbnail(webpage)
  69. duration = int_or_none(self._og_search_property(
  70. 'duration', webpage, 'duration', fatal=False))
  71. timestamp = parse_iso8601(self._search_regex(
  72. r'<time[^>]+\bdatetime="([^"]+)"[^>]+itemprop="uploadDate"',
  73. webpage, 'upload date', fatal=False))
  74. uploader = self._html_search_regex(
  75. r'class="video-uploaded"[^>]*>\s*<a href="/jsecUser/movies/[^"]+"[^>]*>([^<]+)</a>',
  76. webpage, 'uploader', fatal=False)
  77. view_count = int_or_none(self._html_search_regex(
  78. r'<span class="video-views">(\d+) просмотр',
  79. webpage, 'view count', fatal=False))
  80. comment_count = int_or_none(self._html_search_regex(
  81. r'<a[^>]+href="#tab-comments"[^>]*>(\d+) комментари',
  82. webpage, 'comment count', default=None))
  83. # Sets some cookies
  84. self._download_xml(
  85. r'http://%s/video/xml/%s?mode=init' % (host, video_id),
  86. video_id, 'Downloading init XML')
  87. video_xml = self._download_xml(
  88. 'http://%s/video/xml/%s?mode=play' % (host, video_id),
  89. video_id, 'Downloading video XML')
  90. video = xpath_element(video_xml, './/video', 'video', fatal=True)
  91. formats = [{
  92. 'url': xpath_attr(video, '', 'url', 'video URL', fatal=True),
  93. }]
  94. like_count = int_or_none(video.get('ratingPlus'))
  95. dislike_count = int_or_none(video.get('ratingMinus'))
  96. age_limit = 18 if video.get('adult') == 'true' else 0
  97. return {
  98. 'id': video_id,
  99. 'title': title,
  100. 'description': description,
  101. 'thumbnail': thumbnail,
  102. 'uploader': uploader,
  103. 'duration': duration,
  104. 'timestamp': timestamp,
  105. 'view_count': view_count,
  106. 'comment_count': comment_count,
  107. 'like_count': like_count,
  108. 'dislike_count': dislike_count,
  109. 'age_limit': age_limit,
  110. 'formats': formats,
  111. }