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.

325 lines
12 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. unescapeHTML,
  12. xpath_text,
  13. )
  14. class TNAFlixNetworkBaseIE(InfoExtractor):
  15. # May be overridden in descendants if necessary
  16. _CONFIG_REGEX = [
  17. r'flashvars\.config\s*=\s*escape\("([^"]+)"',
  18. r'<input[^>]+name="config\d?" value="([^"]+)"',
  19. ]
  20. _HOST = 'tna'
  21. _VKEY_SUFFIX = ''
  22. _TITLE_REGEX = r'<input[^>]+name="title" value="([^"]+)"'
  23. _DESCRIPTION_REGEX = r'<input[^>]+name="description" value="([^"]+)"'
  24. _UPLOADER_REGEX = r'<input[^>]+name="username" value="([^"]+)"'
  25. _VIEW_COUNT_REGEX = None
  26. _COMMENT_COUNT_REGEX = None
  27. _AVERAGE_RATING_REGEX = None
  28. _CATEGORIES_REGEX = r'<li[^>]*>\s*<span[^>]+class="infoTitle"[^>]*>Categories:</span>\s*<span[^>]+class="listView"[^>]*>(.+?)</span>\s*</li>'
  29. def _extract_thumbnails(self, flix_xml):
  30. def get_child(elem, names):
  31. for name in names:
  32. child = elem.find(name)
  33. if child is not None:
  34. return child
  35. timeline = get_child(flix_xml, ['timeline', 'rolloverBarImage'])
  36. if timeline is None:
  37. return
  38. pattern_el = get_child(timeline, ['imagePattern', 'pattern'])
  39. if pattern_el is None or not pattern_el.text:
  40. return
  41. first_el = get_child(timeline, ['imageFirst', 'first'])
  42. last_el = get_child(timeline, ['imageLast', 'last'])
  43. if first_el is None or last_el is None:
  44. return
  45. first_text = first_el.text
  46. last_text = last_el.text
  47. if not first_text.isdigit() or not last_text.isdigit():
  48. return
  49. first = int(first_text)
  50. last = int(last_text)
  51. if first > last:
  52. return
  53. width = int_or_none(xpath_text(timeline, './imageWidth', 'thumbnail width'))
  54. height = int_or_none(xpath_text(timeline, './imageHeight', 'thumbnail height'))
  55. return [{
  56. 'url': self._proto_relative_url(pattern_el.text.replace('#', compat_str(i)), 'http:'),
  57. 'width': width,
  58. 'height': height,
  59. } for i in range(first, last + 1)]
  60. def _real_extract(self, url):
  61. mobj = re.match(self._VALID_URL, url)
  62. video_id = mobj.group('id')
  63. for display_id_key in ('display_id', 'display_id_2'):
  64. if display_id_key in mobj.groupdict():
  65. display_id = mobj.group(display_id_key)
  66. if display_id:
  67. break
  68. else:
  69. display_id = video_id
  70. webpage = self._download_webpage(url, display_id)
  71. cfg_url = self._proto_relative_url(self._html_search_regex(
  72. self._CONFIG_REGEX, webpage, 'flashvars.config', default=None), 'http:')
  73. if not cfg_url:
  74. inputs = self._hidden_inputs(webpage)
  75. cfg_url = ('https://cdn-fck.%sflix.com/%sflix/%s%s.fid?key=%s&VID=%s&premium=1&vip=1&alpha'
  76. % (self._HOST, self._HOST, inputs['vkey'], self._VKEY_SUFFIX, inputs['nkey'], video_id))
  77. cfg_xml = self._download_xml(
  78. cfg_url, display_id, 'Downloading metadata',
  79. transform_source=fix_xml_ampersands)
  80. formats = []
  81. def extract_video_url(vl):
  82. # Any URL modification now results in HTTP Error 403: Forbidden
  83. return unescapeHTML(vl.text)
  84. video_link = cfg_xml.find('./videoLink')
  85. if video_link is not None:
  86. formats.append({
  87. 'url': extract_video_url(video_link),
  88. 'ext': xpath_text(cfg_xml, './videoConfig/type', 'type', default='flv'),
  89. })
  90. for item in cfg_xml.findall('./quality/item'):
  91. video_link = item.find('./videoLink')
  92. if video_link is None:
  93. continue
  94. res = item.find('res')
  95. format_id = None if res is None else res.text
  96. height = int_or_none(self._search_regex(
  97. r'^(\d+)[pP]', format_id, 'height', default=None))
  98. formats.append({
  99. 'url': self._proto_relative_url(extract_video_url(video_link), 'http:'),
  100. 'format_id': format_id,
  101. 'height': height,
  102. })
  103. self._sort_formats(formats)
  104. thumbnail = self._proto_relative_url(
  105. xpath_text(cfg_xml, './startThumb', 'thumbnail'), 'http:')
  106. thumbnails = self._extract_thumbnails(cfg_xml)
  107. title = None
  108. if self._TITLE_REGEX:
  109. title = self._html_search_regex(
  110. self._TITLE_REGEX, webpage, 'title', default=None)
  111. if not title:
  112. title = self._og_search_title(webpage)
  113. age_limit = self._rta_search(webpage) or 18
  114. duration = parse_duration(self._html_search_meta(
  115. 'duration', webpage, 'duration', default=None))
  116. def extract_field(pattern, name):
  117. return self._html_search_regex(pattern, webpage, name, default=None) if pattern else None
  118. description = extract_field(self._DESCRIPTION_REGEX, 'description')
  119. uploader = extract_field(self._UPLOADER_REGEX, 'uploader')
  120. view_count = str_to_int(extract_field(self._VIEW_COUNT_REGEX, 'view count'))
  121. comment_count = str_to_int(extract_field(self._COMMENT_COUNT_REGEX, 'comment count'))
  122. average_rating = float_or_none(extract_field(self._AVERAGE_RATING_REGEX, 'average rating'))
  123. categories_str = extract_field(self._CATEGORIES_REGEX, 'categories')
  124. categories = [c.strip() for c in categories_str.split(',')] if categories_str is not None else []
  125. return {
  126. 'id': video_id,
  127. 'display_id': display_id,
  128. 'title': title,
  129. 'description': description,
  130. 'thumbnail': thumbnail,
  131. 'thumbnails': thumbnails,
  132. 'duration': duration,
  133. 'age_limit': age_limit,
  134. 'uploader': uploader,
  135. 'view_count': view_count,
  136. 'comment_count': comment_count,
  137. 'average_rating': average_rating,
  138. 'categories': categories,
  139. 'formats': formats,
  140. }
  141. class TNAFlixNetworkEmbedIE(TNAFlixNetworkBaseIE):
  142. _VALID_URL = r'https?://player\.(?:tna|emp)flix\.com/video/(?P<id>\d+)'
  143. _TITLE_REGEX = r'<title>([^<]+)</title>'
  144. _TESTS = [{
  145. 'url': 'https://player.tnaflix.com/video/6538',
  146. 'info_dict': {
  147. 'id': '6538',
  148. 'display_id': '6538',
  149. 'ext': 'mp4',
  150. 'title': 'Educational xxx video',
  151. 'thumbnail': r're:https?://.*\.jpg$',
  152. 'age_limit': 18,
  153. },
  154. 'params': {
  155. 'skip_download': True,
  156. },
  157. }, {
  158. 'url': 'https://player.empflix.com/video/33051',
  159. 'only_matching': True,
  160. }]
  161. @staticmethod
  162. def _extract_urls(webpage):
  163. return [url for _, url in re.findall(
  164. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.(?:tna|emp)flix\.com/video/\d+)\1',
  165. webpage)]
  166. class TNAEMPFlixBaseIE(TNAFlixNetworkBaseIE):
  167. _DESCRIPTION_REGEX = r'(?s)>Description:</[^>]+>(.+?)<'
  168. _UPLOADER_REGEX = r'<span>by\s*<a[^>]+\bhref=["\']/profile/[^>]+>([^<]+)<'
  169. _CATEGORIES_REGEX = r'(?s)<span[^>]*>Categories:</span>(.+?)</div>'
  170. class TNAFlixIE(TNAEMPFlixBaseIE):
  171. _VALID_URL = r'https?://(?:www\.)?tnaflix\.com/[^/]+/(?P<display_id>[^/]+)/video(?P<id>\d+)'
  172. _TITLE_REGEX = r'<title>(.+?) - (?:TNAFlix Porn Videos|TNAFlix\.com)</title>'
  173. _TESTS = [{
  174. # anonymous uploader, no categories
  175. 'url': 'http://www.tnaflix.com/porn-stars/Carmella-Decesare-striptease/video553878',
  176. 'md5': '7e569419fe6d69543d01e6be22f5f7c4',
  177. 'info_dict': {
  178. 'id': '553878',
  179. 'display_id': 'Carmella-Decesare-striptease',
  180. 'ext': 'mp4',
  181. 'title': 'Carmella Decesare - striptease',
  182. 'thumbnail': r're:https?://.*\.jpg$',
  183. 'duration': 91,
  184. 'age_limit': 18,
  185. 'categories': ['Porn Stars'],
  186. }
  187. }, {
  188. # non-anonymous uploader, categories
  189. 'url': 'https://www.tnaflix.com/teen-porn/Educational-xxx-video/video6538',
  190. 'md5': '0f5d4d490dbfd117b8607054248a07c0',
  191. 'info_dict': {
  192. 'id': '6538',
  193. 'display_id': 'Educational-xxx-video',
  194. 'ext': 'mp4',
  195. 'title': 'Educational xxx video',
  196. 'description': 'md5:b4fab8f88a8621c8fabd361a173fe5b8',
  197. 'thumbnail': r're:https?://.*\.jpg$',
  198. 'duration': 164,
  199. 'age_limit': 18,
  200. 'uploader': 'bobwhite39',
  201. 'categories': list,
  202. }
  203. }, {
  204. 'url': 'https://www.tnaflix.com/amateur-porn/bunzHD-Ms.Donk/video358632',
  205. 'only_matching': True,
  206. }]
  207. class EMPFlixIE(TNAEMPFlixBaseIE):
  208. _VALID_URL = r'https?://(?:www\.)?empflix\.com/(?:videos/(?P<display_id>.+?)-|[^/]+/(?P<display_id_2>[^/]+)/video)(?P<id>[0-9]+)'
  209. _HOST = 'emp'
  210. _VKEY_SUFFIX = '-1'
  211. _TESTS = [{
  212. 'url': 'http://www.empflix.com/videos/Amateur-Finger-Fuck-33051.html',
  213. 'md5': 'bc30d48b91a7179448a0bda465114676',
  214. 'info_dict': {
  215. 'id': '33051',
  216. 'display_id': 'Amateur-Finger-Fuck',
  217. 'ext': 'mp4',
  218. 'title': 'Amateur Finger Fuck',
  219. 'description': 'Amateur solo finger fucking.',
  220. 'thumbnail': r're:https?://.*\.jpg$',
  221. 'duration': 83,
  222. 'age_limit': 18,
  223. 'uploader': 'cwbike',
  224. 'categories': ['Amateur', 'Anal', 'Fisting', 'Home made', 'Solo'],
  225. }
  226. }, {
  227. 'url': 'http://www.empflix.com/videos/[AROMA][ARMD-718]-Aoi-Yoshino-Sawa-25826.html',
  228. 'only_matching': True,
  229. }, {
  230. 'url': 'https://www.empflix.com/amateur-porn/Amateur-Finger-Fuck/video33051',
  231. 'only_matching': True,
  232. }]
  233. class MovieFapIE(TNAFlixNetworkBaseIE):
  234. _VALID_URL = r'https?://(?:www\.)?moviefap\.com/videos/(?P<id>[0-9a-f]+)/(?P<display_id>[^/]+)\.html'
  235. _VIEW_COUNT_REGEX = r'<br>Views\s*<strong>([\d,.]+)</strong>'
  236. _COMMENT_COUNT_REGEX = r'<span[^>]+id="comCount"[^>]*>([\d,.]+)</span>'
  237. _AVERAGE_RATING_REGEX = r'Current Rating\s*<br>\s*<strong>([\d.]+)</strong>'
  238. _CATEGORIES_REGEX = r'(?s)<div[^>]+id="vid_info"[^>]*>\s*<div[^>]*>.+?</div>(.*?)<br>'
  239. _TESTS = [{
  240. # normal, multi-format video
  241. 'url': 'http://www.moviefap.com/videos/be9867c9416c19f54a4a/experienced-milf-amazing-handjob.html',
  242. 'md5': '26624b4e2523051b550067d547615906',
  243. 'info_dict': {
  244. 'id': 'be9867c9416c19f54a4a',
  245. 'display_id': 'experienced-milf-amazing-handjob',
  246. 'ext': 'mp4',
  247. 'title': 'Experienced MILF Amazing Handjob',
  248. 'description': 'Experienced MILF giving an Amazing Handjob',
  249. 'thumbnail': r're:https?://.*\.jpg$',
  250. 'age_limit': 18,
  251. 'uploader': 'darvinfred06',
  252. 'view_count': int,
  253. 'comment_count': int,
  254. 'average_rating': float,
  255. 'categories': ['Amateur', 'Masturbation', 'Mature', 'Flashing'],
  256. }
  257. }, {
  258. # quirky single-format case where the extension is given as fid, but the video is really an flv
  259. 'url': 'http://www.moviefap.com/videos/e5da0d3edce5404418f5/jeune-couple-russe.html',
  260. 'md5': 'fa56683e291fc80635907168a743c9ad',
  261. 'info_dict': {
  262. 'id': 'e5da0d3edce5404418f5',
  263. 'display_id': 'jeune-couple-russe',
  264. 'ext': 'flv',
  265. 'title': 'Jeune Couple Russe',
  266. 'description': 'Amateur',
  267. 'thumbnail': r're:https?://.*\.jpg$',
  268. 'age_limit': 18,
  269. 'uploader': 'whiskeyjar',
  270. 'view_count': int,
  271. 'comment_count': int,
  272. 'average_rating': float,
  273. 'categories': ['Amateur', 'Teen'],
  274. }
  275. }]