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.

269 lines
10 KiB

10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import compat_str
  5. from ..utils import (
  6. fix_xml_ampersands,
  7. float_or_none,
  8. int_or_none,
  9. parse_duration,
  10. str_to_int,
  11. xpath_text,
  12. )
  13. class TNAFlixNetworkBaseIE(InfoExtractor):
  14. # May be overridden in descendants if necessary
  15. _CONFIG_REGEX = [
  16. r'flashvars\.config\s*=\s*escape\("([^"]+)"',
  17. r'<input[^>]+name="config\d?" value="([^"]+)"',
  18. ]
  19. _TITLE_REGEX = r'<input[^>]+name="title" value="([^"]+)"'
  20. _DESCRIPTION_REGEX = r'<input[^>]+name="description" value="([^"]+)"'
  21. _UPLOADER_REGEX = r'<input[^>]+name="username" value="([^"]+)"'
  22. _VIEW_COUNT_REGEX = None
  23. _COMMENT_COUNT_REGEX = None
  24. _AVERAGE_RATING_REGEX = None
  25. _CATEGORIES_REGEX = r'<li[^>]*>\s*<span[^>]+class="infoTitle"[^>]*>Categories:</span>\s*<span[^>]+class="listView"[^>]*>(.+?)</span>\s*</li>'
  26. def _extract_thumbnails(self, flix_xml):
  27. def get_child(elem, names):
  28. for name in names:
  29. child = elem.find(name)
  30. if child is not None:
  31. return child
  32. timeline = get_child(flix_xml, ['timeline', 'rolloverBarImage'])
  33. if timeline is None:
  34. return
  35. pattern_el = get_child(timeline, ['imagePattern', 'pattern'])
  36. if pattern_el is None or not pattern_el.text:
  37. return
  38. first_el = get_child(timeline, ['imageFirst', 'first'])
  39. last_el = get_child(timeline, ['imageLast', 'last'])
  40. if first_el is None or last_el is None:
  41. return
  42. first_text = first_el.text
  43. last_text = last_el.text
  44. if not first_text.isdigit() or not last_text.isdigit():
  45. return
  46. first = int(first_text)
  47. last = int(last_text)
  48. if first > last:
  49. return
  50. width = int_or_none(xpath_text(timeline, './imageWidth', 'thumbnail width'))
  51. height = int_or_none(xpath_text(timeline, './imageHeight', 'thumbnail height'))
  52. return [{
  53. 'url': self._proto_relative_url(pattern_el.text.replace('#', compat_str(i)), 'http:'),
  54. 'width': width,
  55. 'height': height,
  56. } for i in range(first, last + 1)]
  57. def _real_extract(self, url):
  58. mobj = re.match(self._VALID_URL, url)
  59. video_id = mobj.group('id')
  60. display_id = mobj.group('display_id')
  61. webpage = self._download_webpage(url, display_id)
  62. cfg_url = self._proto_relative_url(self._html_search_regex(
  63. self._CONFIG_REGEX, webpage, 'flashvars.config'), 'http:')
  64. cfg_xml = self._download_xml(
  65. cfg_url, display_id, 'Downloading metadata',
  66. transform_source=fix_xml_ampersands)
  67. formats = []
  68. def extract_video_url(vl):
  69. return re.sub('speed=\d+', 'speed=', vl.text)
  70. video_link = cfg_xml.find('./videoLink')
  71. if video_link is not None:
  72. formats.append({
  73. 'url': extract_video_url(video_link),
  74. 'ext': xpath_text(cfg_xml, './videoConfig/type', 'type', default='flv'),
  75. })
  76. for item in cfg_xml.findall('./quality/item'):
  77. video_link = item.find('./videoLink')
  78. if video_link is None:
  79. continue
  80. res = item.find('res')
  81. format_id = None if res is None else res.text
  82. height = int_or_none(self._search_regex(
  83. r'^(\d+)[pP]', format_id, 'height', default=None))
  84. formats.append({
  85. 'url': self._proto_relative_url(extract_video_url(video_link), 'http:'),
  86. 'format_id': format_id,
  87. 'height': height,
  88. })
  89. self._sort_formats(formats)
  90. thumbnail = self._proto_relative_url(
  91. xpath_text(cfg_xml, './startThumb', 'thumbnail'), 'http:')
  92. thumbnails = self._extract_thumbnails(cfg_xml)
  93. title = self._html_search_regex(
  94. self._TITLE_REGEX, webpage, 'title') if self._TITLE_REGEX else self._og_search_title(webpage)
  95. age_limit = self._rta_search(webpage)
  96. duration = parse_duration(self._html_search_meta(
  97. 'duration', webpage, 'duration', default=None))
  98. def extract_field(pattern, name):
  99. return self._html_search_regex(pattern, webpage, name, default=None) if pattern else None
  100. description = extract_field(self._DESCRIPTION_REGEX, 'description')
  101. uploader = extract_field(self._UPLOADER_REGEX, 'uploader')
  102. view_count = str_to_int(extract_field(self._VIEW_COUNT_REGEX, 'view count'))
  103. comment_count = str_to_int(extract_field(self._COMMENT_COUNT_REGEX, 'comment count'))
  104. average_rating = float_or_none(extract_field(self._AVERAGE_RATING_REGEX, 'average rating'))
  105. categories_str = extract_field(self._CATEGORIES_REGEX, 'categories')
  106. categories = categories_str.split(', ') if categories_str is not None else []
  107. return {
  108. 'id': video_id,
  109. 'display_id': display_id,
  110. 'title': title,
  111. 'description': description,
  112. 'thumbnail': thumbnail,
  113. 'thumbnails': thumbnails,
  114. 'duration': duration,
  115. 'age_limit': age_limit,
  116. 'uploader': uploader,
  117. 'view_count': view_count,
  118. 'comment_count': comment_count,
  119. 'average_rating': average_rating,
  120. 'categories': categories,
  121. 'formats': formats,
  122. }
  123. class TNAFlixIE(TNAFlixNetworkBaseIE):
  124. _VALID_URL = r'https?://(?:www\.)?tnaflix\.com/[^/]+/(?P<display_id>[^/]+)/video(?P<id>\d+)'
  125. _TITLE_REGEX = r'<title>(.+?) - TNAFlix Porn Videos</title>'
  126. _DESCRIPTION_REGEX = r'<h3 itemprop="description">([^<]+)</h3>'
  127. _UPLOADER_REGEX = r'(?s)<span[^>]+class="infoTitle"[^>]*>Uploaded By:</span>(.+?)<div'
  128. _TESTS = [{
  129. # anonymous uploader, no categories
  130. 'url': 'http://www.tnaflix.com/porn-stars/Carmella-Decesare-striptease/video553878',
  131. 'md5': 'ecf3498417d09216374fc5907f9c6ec0',
  132. 'info_dict': {
  133. 'id': '553878',
  134. 'display_id': 'Carmella-Decesare-striptease',
  135. 'ext': 'mp4',
  136. 'title': 'Carmella Decesare - striptease',
  137. 'thumbnail': 're:https?://.*\.jpg$',
  138. 'duration': 91,
  139. 'age_limit': 18,
  140. 'uploader': 'Anonymous',
  141. 'categories': [],
  142. }
  143. }, {
  144. # non-anonymous uploader, categories
  145. 'url': 'https://www.tnaflix.com/teen-porn/Educational-xxx-video/video6538',
  146. 'md5': '0f5d4d490dbfd117b8607054248a07c0',
  147. 'info_dict': {
  148. 'id': '6538',
  149. 'display_id': 'Educational-xxx-video',
  150. 'ext': 'mp4',
  151. 'title': 'Educational xxx video',
  152. 'description': 'md5:b4fab8f88a8621c8fabd361a173fe5b8',
  153. 'thumbnail': 're:https?://.*\.jpg$',
  154. 'duration': 164,
  155. 'age_limit': 18,
  156. 'uploader': 'bobwhite39',
  157. 'categories': ['Amateur Porn', 'Squirting Videos', 'Teen Girls 18+'],
  158. }
  159. }, {
  160. 'url': 'https://www.tnaflix.com/amateur-porn/bunzHD-Ms.Donk/video358632',
  161. 'only_matching': True,
  162. }]
  163. class EMPFlixIE(TNAFlixNetworkBaseIE):
  164. _VALID_URL = r'https?://(?:www\.)?empflix\.com/videos/(?P<display_id>.+?)-(?P<id>[0-9]+)\.html'
  165. _UPLOADER_REGEX = r'<span[^>]+class="infoTitle"[^>]*>Uploaded By:</span>(.+?)</li>'
  166. _TESTS = [{
  167. 'url': 'http://www.empflix.com/videos/Amateur-Finger-Fuck-33051.html',
  168. 'md5': 'b1bc15b6412d33902d6e5952035fcabc',
  169. 'info_dict': {
  170. 'id': '33051',
  171. 'display_id': 'Amateur-Finger-Fuck',
  172. 'ext': 'mp4',
  173. 'title': 'Amateur Finger Fuck',
  174. 'description': 'Amateur solo finger fucking.',
  175. 'thumbnail': 're:https?://.*\.jpg$',
  176. 'duration': 83,
  177. 'age_limit': 18,
  178. 'uploader': 'cwbike',
  179. 'categories': ['Amateur', 'Anal', 'Fisting', 'Home made', 'Solo'],
  180. }
  181. }, {
  182. 'url': 'http://www.empflix.com/videos/[AROMA][ARMD-718]-Aoi-Yoshino-Sawa-25826.html',
  183. 'only_matching': True,
  184. }]
  185. class MovieFapIE(TNAFlixNetworkBaseIE):
  186. _VALID_URL = r'https?://(?:www\.)?moviefap\.com/videos/(?P<id>[0-9a-f]+)/(?P<display_id>[^/]+)\.html'
  187. _VIEW_COUNT_REGEX = r'<br>Views\s*<strong>([\d,.]+)</strong>'
  188. _COMMENT_COUNT_REGEX = r'<span[^>]+id="comCount"[^>]*>([\d,.]+)</span>'
  189. _AVERAGE_RATING_REGEX = r'Current Rating\s*<br>\s*<strong>([\d.]+)</strong>'
  190. _CATEGORIES_REGEX = r'(?s)<div[^>]+id="vid_info"[^>]*>\s*<div[^>]*>.+?</div>(.*?)<br>'
  191. _TESTS = [{
  192. # normal, multi-format video
  193. 'url': 'http://www.moviefap.com/videos/be9867c9416c19f54a4a/experienced-milf-amazing-handjob.html',
  194. 'md5': '26624b4e2523051b550067d547615906',
  195. 'info_dict': {
  196. 'id': 'be9867c9416c19f54a4a',
  197. 'display_id': 'experienced-milf-amazing-handjob',
  198. 'ext': 'mp4',
  199. 'title': 'Experienced MILF Amazing Handjob',
  200. 'description': 'Experienced MILF giving an Amazing Handjob',
  201. 'thumbnail': 're:https?://.*\.jpg$',
  202. 'age_limit': 18,
  203. 'uploader': 'darvinfred06',
  204. 'view_count': int,
  205. 'comment_count': int,
  206. 'average_rating': float,
  207. 'categories': ['Amateur', 'Masturbation', 'Mature', 'Flashing'],
  208. }
  209. }, {
  210. # quirky single-format case where the extension is given as fid, but the video is really an flv
  211. 'url': 'http://www.moviefap.com/videos/e5da0d3edce5404418f5/jeune-couple-russe.html',
  212. 'md5': 'fa56683e291fc80635907168a743c9ad',
  213. 'info_dict': {
  214. 'id': 'e5da0d3edce5404418f5',
  215. 'display_id': 'jeune-couple-russe',
  216. 'ext': 'flv',
  217. 'title': 'Jeune Couple Russe',
  218. 'description': 'Amateur',
  219. 'thumbnail': 're:https?://.*\.jpg$',
  220. 'age_limit': 18,
  221. 'uploader': 'whiskeyjar',
  222. 'view_count': int,
  223. 'comment_count': int,
  224. 'average_rating': float,
  225. 'categories': ['Amateur', 'Teen'],
  226. }
  227. }]