tnaflix.py 12 KB

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