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.

202 lines
7.5 KiB

10 years ago
  1. from __future__ import unicode_literals
  2. import datetime
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_urlparse
  6. from ..utils import (
  7. ExtractorError,
  8. InAdvancePagedList,
  9. orderedSet,
  10. str_to_int,
  11. unified_strdate,
  12. )
  13. class MotherlessIE(InfoExtractor):
  14. _VALID_URL = r'https?://(?:www\.)?motherless\.com/(?:g/[a-z0-9_]+/)?(?P<id>[A-Z0-9]+)'
  15. _TESTS = [{
  16. 'url': 'http://motherless.com/AC3FFE1',
  17. 'md5': '310f62e325a9fafe64f68c0bccb6e75f',
  18. 'info_dict': {
  19. 'id': 'AC3FFE1',
  20. 'ext': 'mp4',
  21. 'title': 'Fucked in the ass while playing PS3',
  22. 'categories': ['Gaming', 'anal', 'reluctant', 'rough', 'Wife'],
  23. 'upload_date': '20100913',
  24. 'uploader_id': 'famouslyfuckedup',
  25. 'thumbnail': r're:http://.*\.jpg',
  26. 'age_limit': 18,
  27. }
  28. }, {
  29. 'url': 'http://motherless.com/532291B',
  30. 'md5': 'bc59a6b47d1f958e61fbd38a4d31b131',
  31. 'info_dict': {
  32. 'id': '532291B',
  33. 'ext': 'mp4',
  34. 'title': 'Amazing girl playing the omegle game, PERFECT!',
  35. 'categories': ['Amateur', 'webcam', 'omegle', 'pink', 'young', 'masturbate', 'teen',
  36. 'game', 'hairy'],
  37. 'upload_date': '20140622',
  38. 'uploader_id': 'Sulivana7x',
  39. 'thumbnail': r're:http://.*\.jpg',
  40. 'age_limit': 18,
  41. },
  42. 'skip': '404',
  43. }, {
  44. 'url': 'http://motherless.com/g/cosplay/633979F',
  45. 'md5': '0b2a43f447a49c3e649c93ad1fafa4a0',
  46. 'info_dict': {
  47. 'id': '633979F',
  48. 'ext': 'mp4',
  49. 'title': 'Turtlette',
  50. 'categories': ['superheroine heroine superher'],
  51. 'upload_date': '20140827',
  52. 'uploader_id': 'shade0230',
  53. 'thumbnail': r're:http://.*\.jpg',
  54. 'age_limit': 18,
  55. }
  56. }, {
  57. # no keywords
  58. 'url': 'http://motherless.com/8B4BBC1',
  59. 'only_matching': True,
  60. }]
  61. def _real_extract(self, url):
  62. video_id = self._match_id(url)
  63. webpage = self._download_webpage(url, video_id)
  64. if any(p in webpage for p in (
  65. '<title>404 - MOTHERLESS.COM<',
  66. ">The page you're looking for cannot be found.<")):
  67. raise ExtractorError('Video %s does not exist' % video_id, expected=True)
  68. if '>The content you are trying to view is for friends only.' in webpage:
  69. raise ExtractorError('Video %s is for friends only' % video_id, expected=True)
  70. title = self._html_search_regex(
  71. r'id="view-upload-title">\s+([^<]+)<', webpage, 'title')
  72. video_url = self._html_search_regex(
  73. r'setup\(\{\s+"file".+: "([^"]+)",', webpage, 'video URL')
  74. age_limit = self._rta_search(webpage)
  75. view_count = str_to_int(self._html_search_regex(
  76. r'<strong>Views</strong>\s+([^<]+)<',
  77. webpage, 'view count', fatal=False))
  78. like_count = str_to_int(self._html_search_regex(
  79. r'<strong>Favorited</strong>\s+([^<]+)<',
  80. webpage, 'like count', fatal=False))
  81. upload_date = self._html_search_regex(
  82. r'<strong>Uploaded</strong>\s+([^<]+)<', webpage, 'upload date')
  83. if 'Ago' in upload_date:
  84. days = int(re.search(r'([0-9]+)', upload_date).group(1))
  85. upload_date = (datetime.datetime.now() - datetime.timedelta(days=days)).strftime('%Y%m%d')
  86. else:
  87. upload_date = unified_strdate(upload_date)
  88. comment_count = webpage.count('class="media-comment-contents"')
  89. uploader_id = self._html_search_regex(
  90. r'"thumb-member-username">\s+<a href="/m/([^"]+)"',
  91. webpage, 'uploader_id')
  92. categories = self._html_search_meta('keywords', webpage, default=None)
  93. if categories:
  94. categories = [cat.strip() for cat in categories.split(',')]
  95. return {
  96. 'id': video_id,
  97. 'title': title,
  98. 'upload_date': upload_date,
  99. 'uploader_id': uploader_id,
  100. 'thumbnail': self._og_search_thumbnail(webpage),
  101. 'categories': categories,
  102. 'view_count': view_count,
  103. 'like_count': like_count,
  104. 'comment_count': comment_count,
  105. 'age_limit': age_limit,
  106. 'url': video_url,
  107. }
  108. class MotherlessGroupIE(InfoExtractor):
  109. _VALID_URL = 'https?://(?:www\.)?motherless\.com/gv?/(?P<id>[a-z0-9_]+)'
  110. _TESTS = [{
  111. 'url': 'http://motherless.com/g/movie_scenes',
  112. 'info_dict': {
  113. 'id': 'movie_scenes',
  114. 'title': 'Movie Scenes',
  115. 'description': 'Hot and sexy scenes from "regular" movies... '
  116. 'Beautiful actresses fully nude... A looot of '
  117. 'skin! :)Enjoy!',
  118. },
  119. 'playlist_mincount': 662,
  120. }, {
  121. 'url': 'http://motherless.com/gv/sex_must_be_funny',
  122. 'info_dict': {
  123. 'id': 'sex_must_be_funny',
  124. 'title': 'Sex must be funny',
  125. 'description': 'Sex can be funny. Wide smiles,laugh, games, fun of '
  126. 'any kind!'
  127. },
  128. 'playlist_mincount': 9,
  129. }]
  130. @classmethod
  131. def suitable(cls, url):
  132. return (False if MotherlessIE.suitable(url)
  133. else super(MotherlessGroupIE, cls).suitable(url))
  134. def _extract_entries(self, webpage, base):
  135. entries = []
  136. for mobj in re.finditer(
  137. r'href="(?P<href>/[^"]+)"[^>]*>(?:\s*<img[^>]+alt="[^-]+-\s(?P<title>[^"]+)")?',
  138. webpage):
  139. video_url = compat_urlparse.urljoin(base, mobj.group('href'))
  140. if not MotherlessIE.suitable(video_url):
  141. continue
  142. video_id = MotherlessIE._match_id(video_url)
  143. title = mobj.group('title')
  144. entries.append(self.url_result(
  145. video_url, ie=MotherlessIE.ie_key(), video_id=video_id,
  146. video_title=title))
  147. # Alternative fallback
  148. if not entries:
  149. entries = [
  150. self.url_result(
  151. compat_urlparse.urljoin(base, '/' + video_id),
  152. ie=MotherlessIE.ie_key(), video_id=video_id)
  153. for video_id in orderedSet(re.findall(
  154. r'data-codename=["\']([A-Z0-9]+)', webpage))]
  155. return entries
  156. def _real_extract(self, url):
  157. group_id = self._match_id(url)
  158. page_url = compat_urlparse.urljoin(url, '/gv/%s' % group_id)
  159. webpage = self._download_webpage(page_url, group_id)
  160. title = self._search_regex(
  161. r'<title>([\w\s]+\w)\s+-', webpage, 'title', fatal=False)
  162. description = self._html_search_meta(
  163. 'description', webpage, fatal=False)
  164. page_count = self._int(self._search_regex(
  165. r'(\d+)</(?:a|span)><(?:a|span)[^>]+>\s*NEXT',
  166. webpage, 'page_count'), 'page_count')
  167. PAGE_SIZE = 80
  168. def _get_page(idx):
  169. webpage = self._download_webpage(
  170. page_url, group_id, query={'page': idx + 1},
  171. note='Downloading page %d/%d' % (idx + 1, page_count)
  172. )
  173. for entry in self._extract_entries(webpage, url):
  174. yield entry
  175. playlist = InAdvancePagedList(_get_page, page_count, PAGE_SIZE)
  176. return {
  177. '_type': 'playlist',
  178. 'id': group_id,
  179. 'title': title,
  180. 'description': description,
  181. 'entries': playlist
  182. }