logo

youtube-dl

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

fourtube.py (11586B)


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