twentyfourvideo.py 4.6 KB

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