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.

116 lines
4.3 KiB

10 years ago
  1. from __future__ import unicode_literals
  2. import datetime
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. str_to_int,
  8. unified_strdate,
  9. )
  10. class MotherlessIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?motherless\.com/(?:g/[a-z0-9_]+/)?(?P<id>[A-Z0-9]+)'
  12. _TESTS = [{
  13. 'url': 'http://motherless.com/AC3FFE1',
  14. 'md5': '310f62e325a9fafe64f68c0bccb6e75f',
  15. 'info_dict': {
  16. 'id': 'AC3FFE1',
  17. 'ext': 'mp4',
  18. 'title': 'Fucked in the ass while playing PS3',
  19. 'categories': ['Gaming', 'anal', 'reluctant', 'rough', 'Wife'],
  20. 'upload_date': '20100913',
  21. 'uploader_id': 'famouslyfuckedup',
  22. 'thumbnail': r're:http://.*\.jpg',
  23. 'age_limit': 18,
  24. }
  25. }, {
  26. 'url': 'http://motherless.com/532291B',
  27. 'md5': 'bc59a6b47d1f958e61fbd38a4d31b131',
  28. 'info_dict': {
  29. 'id': '532291B',
  30. 'ext': 'mp4',
  31. 'title': 'Amazing girl playing the omegle game, PERFECT!',
  32. 'categories': ['Amateur', 'webcam', 'omegle', 'pink', 'young', 'masturbate', 'teen',
  33. 'game', 'hairy'],
  34. 'upload_date': '20140622',
  35. 'uploader_id': 'Sulivana7x',
  36. 'thumbnail': r're:http://.*\.jpg',
  37. 'age_limit': 18,
  38. },
  39. 'skip': '404',
  40. }, {
  41. 'url': 'http://motherless.com/g/cosplay/633979F',
  42. 'md5': '0b2a43f447a49c3e649c93ad1fafa4a0',
  43. 'info_dict': {
  44. 'id': '633979F',
  45. 'ext': 'mp4',
  46. 'title': 'Turtlette',
  47. 'categories': ['superheroine heroine superher'],
  48. 'upload_date': '20140827',
  49. 'uploader_id': 'shade0230',
  50. 'thumbnail': r're:http://.*\.jpg',
  51. 'age_limit': 18,
  52. }
  53. }, {
  54. # no keywords
  55. 'url': 'http://motherless.com/8B4BBC1',
  56. 'only_matching': True,
  57. }]
  58. def _real_extract(self, url):
  59. video_id = self._match_id(url)
  60. webpage = self._download_webpage(url, video_id)
  61. if any(p in webpage for p in (
  62. '<title>404 - MOTHERLESS.COM<',
  63. ">The page you're looking for cannot be found.<")):
  64. raise ExtractorError('Video %s does not exist' % video_id, expected=True)
  65. if '>The content you are trying to view is for friends only.' in webpage:
  66. raise ExtractorError('Video %s is for friends only' % video_id, expected=True)
  67. title = self._html_search_regex(
  68. r'id="view-upload-title">\s+([^<]+)<', webpage, 'title')
  69. video_url = self._html_search_regex(
  70. r'setup\(\{\s+"file".+: "([^"]+)",', webpage, 'video URL')
  71. age_limit = self._rta_search(webpage)
  72. view_count = str_to_int(self._html_search_regex(
  73. r'<strong>Views</strong>\s+([^<]+)<',
  74. webpage, 'view count', fatal=False))
  75. like_count = str_to_int(self._html_search_regex(
  76. r'<strong>Favorited</strong>\s+([^<]+)<',
  77. webpage, 'like count', fatal=False))
  78. upload_date = self._html_search_regex(
  79. r'<strong>Uploaded</strong>\s+([^<]+)<', webpage, 'upload date')
  80. if 'Ago' in upload_date:
  81. days = int(re.search(r'([0-9]+)', upload_date).group(1))
  82. upload_date = (datetime.datetime.now() - datetime.timedelta(days=days)).strftime('%Y%m%d')
  83. else:
  84. upload_date = unified_strdate(upload_date)
  85. comment_count = webpage.count('class="media-comment-contents"')
  86. uploader_id = self._html_search_regex(
  87. r'"thumb-member-username">\s+<a href="/m/([^"]+)"',
  88. webpage, 'uploader_id')
  89. categories = self._html_search_meta('keywords', webpage, default=None)
  90. if categories:
  91. categories = [cat.strip() for cat in categories.split(',')]
  92. return {
  93. 'id': video_id,
  94. 'title': title,
  95. 'upload_date': upload_date,
  96. 'uploader_id': uploader_id,
  97. 'thumbnail': self._og_search_thumbnail(webpage),
  98. 'categories': categories,
  99. 'view_count': view_count,
  100. 'like_count': like_count,
  101. 'comment_count': comment_count,
  102. 'age_limit': age_limit,
  103. 'url': video_url,
  104. }