motherless.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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:https?://.*\.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:https?://.*\.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:https?://.*\.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'(?s)<div[^>]+\bclass=["\']media-meta-title[^>]+>(.+?)</div>',
  72. r'id="view-upload-title">\s+([^<]+)<'), webpage, 'title')
  73. video_url = (self._html_search_regex(
  74. (r'setup\(\{\s*["\']file["\']\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1',
  75. r'fileurl\s*=\s*(["\'])(?P<url>(?:(?!\1).)+)\1'),
  76. webpage, 'video URL', default=None, group='url')
  77. or 'http://cdn4.videos.motherlessmedia.com/videos/%s.mp4?fs=opencloud' % video_id)
  78. age_limit = self._rta_search(webpage)
  79. view_count = str_to_int(self._html_search_regex(
  80. (r'>(\d+)\s+Views<', r'<strong>Views</strong>\s+([^<]+)<'),
  81. webpage, 'view count', fatal=False))
  82. like_count = str_to_int(self._html_search_regex(
  83. (r'>(\d+)\s+Favorites<', r'<strong>Favorited</strong>\s+([^<]+)<'),
  84. webpage, 'like count', fatal=False))
  85. upload_date = self._html_search_regex(
  86. (r'class=["\']count[^>]+>(\d+\s+[a-zA-Z]{3}\s+\d{4})<',
  87. r'<strong>Uploaded</strong>\s+([^<]+)<'), webpage, 'upload date')
  88. if 'Ago' in upload_date:
  89. days = int(re.search(r'([0-9]+)', upload_date).group(1))
  90. upload_date = (datetime.datetime.now() - datetime.timedelta(days=days)).strftime('%Y%m%d')
  91. else:
  92. upload_date = unified_strdate(upload_date)
  93. comment_count = webpage.count('class="media-comment-contents"')
  94. uploader_id = self._html_search_regex(
  95. r'"thumb-member-username">\s+<a href="/m/([^"]+)"',
  96. webpage, 'uploader_id')
  97. categories = self._html_search_meta('keywords', webpage, default=None)
  98. if categories:
  99. categories = [cat.strip() for cat in categories.split(',')]
  100. return {
  101. 'id': video_id,
  102. 'title': title,
  103. 'upload_date': upload_date,
  104. 'uploader_id': uploader_id,
  105. 'thumbnail': self._og_search_thumbnail(webpage),
  106. 'categories': categories,
  107. 'view_count': view_count,
  108. 'like_count': like_count,
  109. 'comment_count': comment_count,
  110. 'age_limit': age_limit,
  111. 'url': video_url,
  112. }
  113. class MotherlessGroupIE(InfoExtractor):
  114. _VALID_URL = r'https?://(?:www\.)?motherless\.com/gv?/(?P<id>[a-z0-9_]+)'
  115. _TESTS = [{
  116. 'url': 'http://motherless.com/g/movie_scenes',
  117. 'info_dict': {
  118. 'id': 'movie_scenes',
  119. 'title': 'Movie Scenes',
  120. 'description': 'Hot and sexy scenes from "regular" movies... '
  121. 'Beautiful actresses fully nude... A looot of '
  122. 'skin! :)Enjoy!',
  123. },
  124. 'playlist_mincount': 662,
  125. }, {
  126. 'url': 'http://motherless.com/gv/sex_must_be_funny',
  127. 'info_dict': {
  128. 'id': 'sex_must_be_funny',
  129. 'title': 'Sex must be funny',
  130. 'description': 'Sex can be funny. Wide smiles,laugh, games, fun of '
  131. 'any kind!'
  132. },
  133. 'playlist_mincount': 9,
  134. }]
  135. @classmethod
  136. def suitable(cls, url):
  137. return (False if MotherlessIE.suitable(url)
  138. else super(MotherlessGroupIE, cls).suitable(url))
  139. def _extract_entries(self, webpage, base):
  140. entries = []
  141. for mobj in re.finditer(
  142. r'href="(?P<href>/[^"]+)"[^>]*>(?:\s*<img[^>]+alt="[^-]+-\s(?P<title>[^"]+)")?',
  143. webpage):
  144. video_url = compat_urlparse.urljoin(base, mobj.group('href'))
  145. if not MotherlessIE.suitable(video_url):
  146. continue
  147. video_id = MotherlessIE._match_id(video_url)
  148. title = mobj.group('title')
  149. entries.append(self.url_result(
  150. video_url, ie=MotherlessIE.ie_key(), video_id=video_id,
  151. video_title=title))
  152. # Alternative fallback
  153. if not entries:
  154. entries = [
  155. self.url_result(
  156. compat_urlparse.urljoin(base, '/' + entry_id),
  157. ie=MotherlessIE.ie_key(), video_id=entry_id)
  158. for entry_id in orderedSet(re.findall(
  159. r'data-codename=["\']([A-Z0-9]+)', webpage))]
  160. return entries
  161. def _real_extract(self, url):
  162. group_id = self._match_id(url)
  163. page_url = compat_urlparse.urljoin(url, '/gv/%s' % group_id)
  164. webpage = self._download_webpage(page_url, group_id)
  165. title = self._search_regex(
  166. r'<title>([\w\s]+\w)\s+-', webpage, 'title', fatal=False)
  167. description = self._html_search_meta(
  168. 'description', webpage, fatal=False)
  169. page_count = self._int(self._search_regex(
  170. r'(\d+)</(?:a|span)><(?:a|span)[^>]+>\s*NEXT',
  171. webpage, 'page_count'), 'page_count')
  172. PAGE_SIZE = 80
  173. def _get_page(idx):
  174. webpage = self._download_webpage(
  175. page_url, group_id, query={'page': idx + 1},
  176. note='Downloading page %d/%d' % (idx + 1, page_count)
  177. )
  178. for entry in self._extract_entries(webpage, url):
  179. yield entry
  180. playlist = InAdvancePagedList(_get_page, page_count, PAGE_SIZE)
  181. return {
  182. '_type': 'playlist',
  183. 'id': group_id,
  184. 'title': title,
  185. 'description': description,
  186. 'entries': playlist
  187. }