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.

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