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.

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