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.

102 lines
3.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. parse_iso8601,
  6. int_or_none,
  7. xpath_attr,
  8. xpath_element,
  9. )
  10. class TwentyFourVideoIE(InfoExtractor):
  11. IE_NAME = '24video'
  12. _VALID_URL = r'https?://(?:www\.)?24video\.net/(?:video/(?:view|xml)/|player/new24_play\.swf\?id=)(?P<id>\d+)'
  13. _TESTS = [
  14. {
  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': '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. {
  33. 'url': 'http://www.24video.net/player/new24_play.swf?id=1044982',
  34. 'only_matching': True,
  35. }
  36. ]
  37. def _real_extract(self, url):
  38. video_id = self._match_id(url)
  39. webpage = self._download_webpage(
  40. 'http://www.24video.net/video/view/%s' % video_id, video_id)
  41. title = self._og_search_title(webpage)
  42. description = self._html_search_regex(
  43. r'<span itemprop="description">([^<]+)</span>', webpage, 'description', fatal=False)
  44. thumbnail = self._og_search_thumbnail(webpage)
  45. duration = int_or_none(self._og_search_property(
  46. 'duration', webpage, 'duration', fatal=False))
  47. timestamp = parse_iso8601(self._search_regex(
  48. r'<time id="video-timeago" datetime="([^"]+)" itemprop="uploadDate">',
  49. webpage, 'upload date'))
  50. uploader = self._html_search_regex(
  51. r'class="video-uploaded"[^>]*>\s*<a href="/jsecUser/movies/[^"]+"[^>]*>([^<]+)</a>',
  52. webpage, 'uploader', fatal=False)
  53. view_count = int_or_none(self._html_search_regex(
  54. r'<span class="video-views">(\d+) просмотр',
  55. webpage, 'view count', fatal=False))
  56. comment_count = int_or_none(self._html_search_regex(
  57. r'<div class="comments-title" id="comments-count">(\d+) комментари',
  58. webpage, 'comment count', fatal=False))
  59. # Sets some cookies
  60. self._download_xml(
  61. r'http://www.24video.net/video/xml/%s?mode=init' % video_id,
  62. video_id, 'Downloading init XML')
  63. video_xml = self._download_xml(
  64. 'http://www.24video.net/video/xml/%s?mode=play' % video_id,
  65. video_id, 'Downloading video XML')
  66. video = xpath_element(video_xml, './/video', 'video', fatal=True)
  67. formats = [{
  68. 'url': xpath_attr(video, '', 'url', 'video URL', fatal=True),
  69. }]
  70. like_count = int_or_none(video.get('ratingPlus'))
  71. dislike_count = int_or_none(video.get('ratingMinus'))
  72. age_limit = 18 if video.get('adult') == 'true' else 0
  73. return {
  74. 'id': video_id,
  75. 'title': title,
  76. 'description': description,
  77. 'thumbnail': thumbnail,
  78. 'uploader': uploader,
  79. 'duration': duration,
  80. 'timestamp': timestamp,
  81. 'view_count': view_count,
  82. 'comment_count': comment_count,
  83. 'like_count': like_count,
  84. 'dislike_count': dislike_count,
  85. 'age_limit': age_limit,
  86. 'formats': formats,
  87. }