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.

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