fourtube.py 11 KB

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