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.

308 lines
11 KiB

10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_b64decode,
  6. compat_str,
  7. compat_urllib_parse_unquote,
  8. compat_urlparse,
  9. )
  10. from ..utils import (
  11. int_or_none,
  12. parse_duration,
  13. parse_iso8601,
  14. str_or_none,
  15. str_to_int,
  16. try_get,
  17. unified_timestamp,
  18. url_or_none,
  19. )
  20. class FourTubeBaseIE(InfoExtractor):
  21. _TKN_HOST = 'tkn.kodicdn.com'
  22. def _extract_formats(self, url, video_id, media_id, sources):
  23. token_url = 'https://%s/%s/desktop/%s' % (
  24. self._TKN_HOST, media_id, '+'.join(sources))
  25. parsed_url = compat_urlparse.urlparse(url)
  26. tokens = self._download_json(token_url, video_id, data=b'', headers={
  27. 'Origin': '%s://%s' % (parsed_url.scheme, parsed_url.hostname),
  28. 'Referer': url,
  29. })
  30. formats = [{
  31. 'url': tokens[format]['token'],
  32. 'format_id': format + 'p',
  33. 'resolution': format + 'p',
  34. 'quality': int(format),
  35. } for format in sources]
  36. self._sort_formats(formats)
  37. return formats
  38. def _real_extract(self, url):
  39. mobj = re.match(self._VALID_URL, url)
  40. kind, video_id, display_id = mobj.group('kind', 'id', 'display_id')
  41. if kind == 'm' or not display_id:
  42. url = self._URL_TEMPLATE % video_id
  43. webpage = self._download_webpage(url, video_id)
  44. title = self._html_search_meta('name', webpage)
  45. timestamp = parse_iso8601(self._html_search_meta(
  46. 'uploadDate', webpage))
  47. thumbnail = self._html_search_meta('thumbnailUrl', webpage)
  48. uploader_id = self._html_search_regex(
  49. r'<a class="item-to-subscribe" href="[^"]+/(?:channel|user)s?/([^/"]+)" title="Go to [^"]+ page">',
  50. webpage, 'uploader id', fatal=False)
  51. uploader = self._html_search_regex(
  52. r'<a class="item-to-subscribe" href="[^"]+/(?:channel|user)s?/[^/"]+" title="Go to ([^"]+) page">',
  53. webpage, 'uploader', fatal=False)
  54. categories_html = self._search_regex(
  55. r'(?s)><i class="icon icon-tag"></i>\s*Categories / Tags\s*.*?<ul class="[^"]*?list[^"]*?">(.*?)</ul>',
  56. webpage, 'categories', fatal=False)
  57. categories = None
  58. if categories_html:
  59. categories = [
  60. c.strip() for c in re.findall(
  61. r'(?s)<li><a.*?>(.*?)</a>', categories_html)]
  62. view_count = str_to_int(self._search_regex(
  63. r'<meta[^>]+itemprop="interactionCount"[^>]+content="UserPlays:([0-9,]+)">',
  64. webpage, 'view count', default=None))
  65. like_count = str_to_int(self._search_regex(
  66. r'<meta[^>]+itemprop="interactionCount"[^>]+content="UserLikes:([0-9,]+)">',
  67. webpage, 'like count', default=None))
  68. duration = parse_duration(self._html_search_meta('duration', webpage))
  69. media_id = self._search_regex(
  70. r'<button[^>]+data-id=(["\'])(?P<id>\d+)\1[^>]+data-quality=', webpage,
  71. 'media id', default=None, group='id')
  72. sources = [
  73. quality
  74. for _, quality in re.findall(r'<button[^>]+data-quality=(["\'])(.+?)\1', webpage)]
  75. if not (media_id and sources):
  76. player_js = self._download_webpage(
  77. self._search_regex(
  78. r'<script[^>]id=(["\'])playerembed\1[^>]+src=(["\'])(?P<url>.+?)\2',
  79. webpage, 'player JS', group='url'),
  80. video_id, 'Downloading player JS')
  81. params_js = self._search_regex(
  82. r'\$\.ajax\(url,\ opts\);\s*\}\s*\}\)\(([0-9,\[\] ]+)\)',
  83. player_js, 'initialization parameters')
  84. params = self._parse_json('[%s]' % params_js, video_id)
  85. media_id = params[0]
  86. sources = ['%s' % p for p in params[2]]
  87. formats = self._extract_formats(url, video_id, media_id, sources)
  88. return {
  89. 'id': video_id,
  90. 'title': title,
  91. 'formats': formats,
  92. 'categories': categories,
  93. 'thumbnail': thumbnail,
  94. 'uploader': uploader,
  95. 'uploader_id': uploader_id,
  96. 'timestamp': timestamp,
  97. 'like_count': like_count,
  98. 'view_count': view_count,
  99. 'duration': duration,
  100. 'age_limit': 18,
  101. }
  102. class FourTubeIE(FourTubeBaseIE):
  103. IE_NAME = '4tube'
  104. _VALID_URL = r'https?://(?:(?P<kind>www|m)\.)?4tube\.com/(?:videos|embed)/(?P<id>\d+)(?:/(?P<display_id>[^/?#&]+))?'
  105. _URL_TEMPLATE = 'https://www.4tube.com/videos/%s/video'
  106. _TESTS = [{
  107. 'url': 'http://www.4tube.com/videos/209733/hot-babe-holly-michaels-gets-her-ass-stuffed-by-black',
  108. 'md5': '6516c8ac63b03de06bc8eac14362db4f',
  109. 'info_dict': {
  110. 'id': '209733',
  111. 'ext': 'mp4',
  112. 'title': 'Hot Babe Holly Michaels gets her ass stuffed by black',
  113. 'uploader': 'WCP Club',
  114. 'uploader_id': 'wcp-club',
  115. 'upload_date': '20131031',
  116. 'timestamp': 1383263892,
  117. 'duration': 583,
  118. 'view_count': int,
  119. 'like_count': int,
  120. 'categories': list,
  121. 'age_limit': 18,
  122. },
  123. }, {
  124. 'url': 'http://www.4tube.com/embed/209733',
  125. 'only_matching': True,
  126. }, {
  127. 'url': 'http://m.4tube.com/videos/209733/hot-babe-holly-michaels-gets-her-ass-stuffed-by-black',
  128. 'only_matching': True,
  129. }]
  130. class FuxIE(FourTubeBaseIE):
  131. _VALID_URL = r'https?://(?:(?P<kind>www|m)\.)?fux\.com/(?:video|embed)/(?P<id>\d+)(?:/(?P<display_id>[^/?#&]+))?'
  132. _URL_TEMPLATE = 'https://www.fux.com/video/%s/video'
  133. _TESTS = [{
  134. 'url': 'https://www.fux.com/video/195359/awesome-fucking-kitchen-ends-cum-swallow',
  135. 'info_dict': {
  136. 'id': '195359',
  137. 'ext': 'mp4',
  138. 'title': 'Awesome fucking in the kitchen ends with cum swallow',
  139. 'uploader': 'alenci2342',
  140. 'uploader_id': 'alenci2342',
  141. 'upload_date': '20131230',
  142. 'timestamp': 1388361660,
  143. 'duration': 289,
  144. 'view_count': int,
  145. 'like_count': int,
  146. 'categories': list,
  147. 'age_limit': 18,
  148. },
  149. 'params': {
  150. 'skip_download': True,
  151. },
  152. }, {
  153. 'url': 'https://www.fux.com/embed/195359',
  154. 'only_matching': True,
  155. }, {
  156. 'url': 'https://www.fux.com/video/195359/awesome-fucking-kitchen-ends-cum-swallow',
  157. 'only_matching': True,
  158. }]
  159. class PornTubeIE(FourTubeBaseIE):
  160. _VALID_URL = r'https?://(?:(?P<kind>www|m)\.)?porntube\.com/(?:videos/(?P<display_id>[^/]+)_|embed/)(?P<id>\d+)'
  161. _URL_TEMPLATE = 'https://www.porntube.com/videos/video_%s'
  162. _TKN_HOST = 'tkn.porntube.com'
  163. _TESTS = [{
  164. 'url': 'https://www.porntube.com/videos/teen-couple-doing-anal_7089759',
  165. 'info_dict': {
  166. 'id': '7089759',
  167. 'ext': 'mp4',
  168. 'title': 'Teen couple doing anal',
  169. 'uploader': 'Alexy',
  170. 'uploader_id': '91488',
  171. 'upload_date': '20150606',
  172. 'timestamp': 1433595647,
  173. 'duration': 5052,
  174. 'view_count': int,
  175. 'like_count': int,
  176. 'age_limit': 18,
  177. },
  178. 'params': {
  179. 'skip_download': True,
  180. },
  181. }, {
  182. 'url': 'https://www.porntube.com/videos/squirting-teen-ballerina-ecg_1331406',
  183. 'info_dict': {
  184. 'id': '1331406',
  185. 'ext': 'mp4',
  186. 'title': 'Squirting Teen Ballerina on ECG',
  187. 'uploader': 'Exploited College Girls',
  188. 'uploader_id': '665',
  189. 'channel': 'Exploited College Girls',
  190. 'channel_id': '665',
  191. 'upload_date': '20130920',
  192. 'timestamp': 1379685485,
  193. 'duration': 851,
  194. 'view_count': int,
  195. 'like_count': int,
  196. 'age_limit': 18,
  197. },
  198. 'params': {
  199. 'skip_download': True,
  200. },
  201. }, {
  202. 'url': 'https://www.porntube.com/embed/7089759',
  203. 'only_matching': True,
  204. }, {
  205. 'url': 'https://m.porntube.com/videos/teen-couple-doing-anal_7089759',
  206. 'only_matching': True,
  207. }]
  208. def _real_extract(self, url):
  209. mobj = re.match(self._VALID_URL, url)
  210. video_id, display_id = mobj.group('id', 'display_id')
  211. webpage = self._download_webpage(url, display_id)
  212. video = self._parse_json(
  213. self._search_regex(
  214. r'INITIALSTATE\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1',
  215. webpage, 'data', group='value'), video_id,
  216. transform_source=lambda x: compat_urllib_parse_unquote(
  217. compat_b64decode(x).decode('utf-8')))['page']['video']
  218. title = video['title']
  219. media_id = video['mediaId']
  220. sources = [compat_str(e['height'])
  221. for e in video['encodings'] if e.get('height')]
  222. formats = self._extract_formats(url, video_id, media_id, sources)
  223. thumbnail = url_or_none(video.get('masterThumb'))
  224. uploader = try_get(video, lambda x: x['user']['username'], compat_str)
  225. uploader_id = str_or_none(try_get(
  226. video, lambda x: x['user']['id'], int))
  227. channel = try_get(video, lambda x: x['channel']['name'], compat_str)
  228. channel_id = str_or_none(try_get(
  229. video, lambda x: x['channel']['id'], int))
  230. like_count = int_or_none(video.get('likes'))
  231. dislike_count = int_or_none(video.get('dislikes'))
  232. view_count = int_or_none(video.get('playsQty'))
  233. duration = int_or_none(video.get('durationInSeconds'))
  234. timestamp = unified_timestamp(video.get('publishedAt'))
  235. return {
  236. 'id': video_id,
  237. 'title': title,
  238. 'formats': formats,
  239. 'thumbnail': thumbnail,
  240. 'uploader': uploader or channel,
  241. 'uploader_id': uploader_id or channel_id,
  242. 'channel': channel,
  243. 'channel_id': channel_id,
  244. 'timestamp': timestamp,
  245. 'like_count': like_count,
  246. 'dislike_count': dislike_count,
  247. 'view_count': view_count,
  248. 'duration': duration,
  249. 'age_limit': 18,
  250. }
  251. class PornerBrosIE(FourTubeBaseIE):
  252. _VALID_URL = r'https?://(?:(?P<kind>www|m)\.)?pornerbros\.com/(?:videos/(?P<display_id>[^/]+)_|embed/)(?P<id>\d+)'
  253. _URL_TEMPLATE = 'https://www.pornerbros.com/videos/video_%s'
  254. _TESTS = [{
  255. 'url': 'https://www.pornerbros.com/videos/skinny-brunette-takes-big-cock-down-her-anal-hole_181369',
  256. 'md5': '6516c8ac63b03de06bc8eac14362db4f',
  257. 'info_dict': {
  258. 'id': '181369',
  259. 'ext': 'mp4',
  260. 'title': 'Skinny brunette takes big cock down her anal hole',
  261. 'uploader': 'PornerBros HD',
  262. 'uploader_id': 'pornerbros-hd',
  263. 'upload_date': '20130130',
  264. 'timestamp': 1359527401,
  265. 'duration': 1224,
  266. 'view_count': int,
  267. 'categories': list,
  268. 'age_limit': 18,
  269. },
  270. 'params': {
  271. 'skip_download': True,
  272. },
  273. }, {
  274. 'url': 'https://www.pornerbros.com/embed/181369',
  275. 'only_matching': True,
  276. }, {
  277. 'url': 'https://m.pornerbros.com/videos/skinny-brunette-takes-big-cock-down-her-anal-hole_181369',
  278. 'only_matching': True,
  279. }]