twentyfourvideo.py 4.0 KB

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