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.

92 lines
3.0 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. determine_ext,
  6. int_or_none,
  7. str_to_int,
  8. urlencode_postdata,
  9. )
  10. class ManyVidsIE(InfoExtractor):
  11. _VALID_URL = r'(?i)https?://(?:www\.)?manyvids\.com/video/(?P<id>\d+)'
  12. _TESTS = [{
  13. # preview video
  14. 'url': 'https://www.manyvids.com/Video/133957/everthing-about-me/',
  15. 'md5': '03f11bb21c52dd12a05be21a5c7dcc97',
  16. 'info_dict': {
  17. 'id': '133957',
  18. 'ext': 'mp4',
  19. 'title': 'everthing about me (Preview)',
  20. 'view_count': int,
  21. 'like_count': int,
  22. },
  23. }, {
  24. # full video
  25. 'url': 'https://www.manyvids.com/Video/935718/MY-FACE-REVEAL/',
  26. 'md5': 'f3e8f7086409e9b470e2643edb96bdcc',
  27. 'info_dict': {
  28. 'id': '935718',
  29. 'ext': 'mp4',
  30. 'title': 'MY FACE REVEAL',
  31. 'view_count': int,
  32. 'like_count': int,
  33. },
  34. }]
  35. def _real_extract(self, url):
  36. video_id = self._match_id(url)
  37. webpage = self._download_webpage(url, video_id)
  38. video_url = self._search_regex(
  39. r'data-(?:video-filepath|meta-video)\s*=s*(["\'])(?P<url>(?:(?!\1).)+)\1',
  40. webpage, 'video URL', group='url')
  41. title = self._html_search_regex(
  42. (r'<span[^>]+class=["\']item-title[^>]+>([^<]+)',
  43. r'<h2[^>]+class=["\']h2 m-0["\'][^>]*>([^<]+)'),
  44. webpage, 'title', default=None) or self._html_search_meta(
  45. 'twitter:title', webpage, 'title', fatal=True)
  46. if any(p in webpage for p in ('preview_videos', '_preview.mp4')):
  47. title += ' (Preview)'
  48. mv_token = self._search_regex(
  49. r'data-mvtoken=(["\'])(?P<value>(?:(?!\1).)+)\1', webpage,
  50. 'mv token', default=None, group='value')
  51. if mv_token:
  52. # Sets some cookies
  53. self._download_webpage(
  54. 'https://www.manyvids.com/includes/ajax_repository/you_had_me_at_hello.php',
  55. video_id, fatal=False, data=urlencode_postdata({
  56. 'mvtoken': mv_token,
  57. 'vid': video_id,
  58. }), headers={
  59. 'Referer': url,
  60. 'X-Requested-With': 'XMLHttpRequest'
  61. })
  62. if determine_ext(video_url) == 'm3u8':
  63. formats = self._extract_m3u8_formats(
  64. video_url, video_id, 'mp4', entry_protocol='m3u8_native',
  65. m3u8_id='hls')
  66. else:
  67. formats = [{'url': video_url}]
  68. like_count = int_or_none(self._search_regex(
  69. r'data-likes=["\'](\d+)', webpage, 'like count', default=None))
  70. view_count = str_to_int(self._html_search_regex(
  71. r'(?s)<span[^>]+class="views-wrapper"[^>]*>(.+?)</span', webpage,
  72. 'view count', default=None))
  73. return {
  74. 'id': video_id,
  75. 'title': title,
  76. 'view_count': view_count,
  77. 'like_count': like_count,
  78. 'formats': formats,
  79. }