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.

110 lines
3.9 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'https?://(?P<host>(?:www\.)?24video\.(?:net|me|xxx|sex|tube|adult))/(?: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. def _real_extract(self, url):
  42. mobj = re.match(self._VALID_URL, url)
  43. video_id = mobj.group('id')
  44. host = mobj.group('host')
  45. webpage = self._download_webpage(
  46. 'http://%s/video/view/%s' % (host, video_id), video_id)
  47. title = self._og_search_title(webpage)
  48. description = self._html_search_regex(
  49. r'<(p|span)[^>]+itemprop="description"[^>]*>(?P<description>[^<]+)</\1>',
  50. webpage, 'description', fatal=False, group='description')
  51. thumbnail = self._og_search_thumbnail(webpage)
  52. duration = int_or_none(self._og_search_property(
  53. 'duration', webpage, 'duration', fatal=False))
  54. timestamp = parse_iso8601(self._search_regex(
  55. r'<time[^>]+\bdatetime="([^"]+)"[^>]+itemprop="uploadDate"',
  56. webpage, 'upload date', fatal=False))
  57. uploader = self._html_search_regex(
  58. r'class="video-uploaded"[^>]*>\s*<a href="/jsecUser/movies/[^"]+"[^>]*>([^<]+)</a>',
  59. webpage, 'uploader', fatal=False)
  60. view_count = int_or_none(self._html_search_regex(
  61. r'<span class="video-views">(\d+) просмотр',
  62. webpage, 'view count', fatal=False))
  63. comment_count = int_or_none(self._html_search_regex(
  64. r'<a[^>]+href="#tab-comments"[^>]*>(\d+) комментари',
  65. webpage, 'comment count', default=None))
  66. # Sets some cookies
  67. self._download_xml(
  68. r'http://%s/video/xml/%s?mode=init' % (host, video_id),
  69. video_id, 'Downloading init XML')
  70. video_xml = self._download_xml(
  71. 'http://%s/video/xml/%s?mode=play' % (host, video_id),
  72. video_id, 'Downloading video XML')
  73. video = xpath_element(video_xml, './/video', 'video', fatal=True)
  74. formats = [{
  75. 'url': xpath_attr(video, '', 'url', 'video URL', fatal=True),
  76. }]
  77. like_count = int_or_none(video.get('ratingPlus'))
  78. dislike_count = int_or_none(video.get('ratingMinus'))
  79. age_limit = 18 if video.get('adult') == 'true' else 0
  80. return {
  81. 'id': video_id,
  82. 'title': title,
  83. 'description': description,
  84. 'thumbnail': thumbnail,
  85. 'uploader': uploader,
  86. 'duration': duration,
  87. 'timestamp': timestamp,
  88. 'view_count': view_count,
  89. 'comment_count': comment_count,
  90. 'like_count': like_count,
  91. 'dislike_count': dislike_count,
  92. 'age_limit': age_limit,
  93. 'formats': formats,
  94. }