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.

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