logo

youtube-dl

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

nuvid.py (3917B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_str
  5. from ..utils import (
  6. parse_duration,
  7. int_or_none,
  8. try_get,
  9. url_or_none,
  10. )
  11. import re
  12. class NuvidIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www|m)\.nuvid\.com/video/(?P<id>[0-9]+)'
  14. _TESTS = [{
  15. 'url': 'https://www.nuvid.com/video/6513023/italian-babe',
  16. 'md5': '772d2f8288f3d3c5c45f7a41761c7844',
  17. 'info_dict': {
  18. 'id': '6513023',
  19. 'ext': 'mp4',
  20. 'title': 'italian babe',
  21. 'format_id': '360p',
  22. 'duration': 321.0,
  23. 'age_limit': 18,
  24. 'thumbnail': r're:https?://.+\.jpg',
  25. 'thumbnails': list,
  26. }
  27. }, {
  28. 'url': 'https://m.nuvid.com/video/6523263',
  29. 'md5': 'ebd22ce8e47e1d9a4d0756a15c67da52',
  30. 'info_dict': {
  31. 'id': '6523263',
  32. 'ext': 'mp4',
  33. 'title': 'Slut brunette college student anal dorm',
  34. 'format_id': '720p',
  35. 'duration': 421.0,
  36. 'age_limit': 18,
  37. 'thumbnail': r're:https?://.+\.jpg',
  38. 'thumbnails': list,
  39. }
  40. }, {
  41. 'url': 'http://m.nuvid.com/video/6415801/',
  42. 'md5': '638d5ececb138d5753593f751ae3f697',
  43. 'info_dict': {
  44. 'id': '6415801',
  45. 'ext': 'mp4',
  46. 'title': 'My best friend wanted to fuck my wife for a long time',
  47. 'format_id': '720p',
  48. 'duration': 1882,
  49. 'age_limit': 18,
  50. 'thumbnail': r're:https?://.+\.jpg',
  51. 'thumbnails': list,
  52. }
  53. }]
  54. def _real_extract(self, url):
  55. video_id = self._match_id(url)
  56. qualities = {
  57. 'lq': '360p',
  58. 'hq': '720p',
  59. }
  60. json_url = 'https://www.nuvid.com/player_config_json/?vid={video_id}&aid=0&domain_id=0&embed=0&check_speed=0'.format(**locals())
  61. video_data = self._download_json(
  62. json_url, video_id, headers={
  63. 'Accept': 'application/json, text/javascript, */*; q = 0.01',
  64. 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
  65. }) or {}
  66. # nice to have, not required
  67. webpage = self._download_webpage(
  68. 'http://m.nuvid.com/video/%s' % (video_id, ),
  69. video_id, 'Downloading video page', fatal=False) or ''
  70. title = (
  71. try_get(video_data, lambda x: x['title'], compat_str)
  72. or self._html_search_regex(
  73. (r'''<span\s[^>]*?\btitle\s*=\s*(?P<q>"|'|\b)(?P<title>[^"]+)(?P=q)\s*>''',
  74. r'''<div\s[^>]*?\bclass\s*=\s*(?P<q>"|'|\b)thumb-holder video(?P=q)>\s*<h5\b[^>]*>(?P<title>[^<]+)</h5''',
  75. r'''<span\s[^>]*?\bclass\s*=\s*(?P<q>"|'|\b)title_thumb(?P=q)>(?P<title>[^<]+)</span'''),
  76. webpage, 'title', group='title')).strip()
  77. formats = [{
  78. 'url': source,
  79. 'format_id': qualities.get(quality),
  80. 'height': int_or_none(qualities.get(quality)[:-1]),
  81. } for quality, source in video_data.get('files').items() if source]
  82. self._check_formats(formats, video_id)
  83. self._sort_formats(formats)
  84. duration = parse_duration(video_data.get('duration') or video_data.get('duration_format'))
  85. thumbnails = [
  86. {'url': thumb_url, }
  87. for thumb_url in (
  88. url_or_none(src) for src in re.findall(
  89. r'<div\s+class\s*=\s*"video-tmb-wrap"\s*>\s*<img\s+src\s*=\s*"([^"]+)"\s*/>',
  90. webpage))
  91. ]
  92. return {
  93. 'id': video_id,
  94. 'formats': formats,
  95. 'title': title,
  96. 'thumbnail': url_or_none(video_data.get('poster')),
  97. 'thumbnails': thumbnails,
  98. 'duration': duration,
  99. 'age_limit': 18,
  100. }