logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

tnaflix.py (12219B)


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