logo

youtube-dl

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

vidlii.py (5887B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. float_or_none,
  7. get_element_by_id,
  8. int_or_none,
  9. strip_or_none,
  10. unified_strdate,
  11. urljoin,
  12. str_to_int,
  13. )
  14. class VidLiiIE(InfoExtractor):
  15. _VALID_URL = r'https?://(?:www\.)?vidlii\.com/(?:watch|embed)\?.*?\bv=(?P<id>[0-9A-Za-z_-]{11})'
  16. _TESTS = [{
  17. 'url': 'https://www.vidlii.com/watch?v=tJluaH4BJ3v',
  18. 'md5': '9bf7d1e005dfa909b6efb0a1ff5175e2',
  19. 'info_dict': {
  20. 'id': 'tJluaH4BJ3v',
  21. 'ext': 'mp4',
  22. 'title': 'Vidlii is against me',
  23. 'description': 'md5:fa3f119287a2bfb922623b52b1856145',
  24. 'thumbnail': 're:https://.*.jpg',
  25. 'uploader': 'APPle5auc31995',
  26. 'uploader_url': 'https://www.vidlii.com/user/APPle5auc31995',
  27. 'upload_date': '20171107',
  28. 'duration': 212,
  29. 'view_count': int,
  30. 'comment_count': int,
  31. 'average_rating': float,
  32. 'categories': ['News & Politics'],
  33. 'tags': ['Vidlii', 'Jan', 'Videogames'],
  34. }
  35. }, {
  36. # HD
  37. 'url': 'https://www.vidlii.com/watch?v=2Ng8Abj2Fkl',
  38. 'md5': '450e7da379c884788c3a4fa02a3ce1a4',
  39. 'info_dict': {
  40. 'id': '2Ng8Abj2Fkl',
  41. 'ext': 'mp4',
  42. 'title': 'test',
  43. 'description': 'md5:cc55a86032a7b6b3cbfd0f6b155b52e9',
  44. 'thumbnail': 'https://www.vidlii.com/usfi/thmp/2Ng8Abj2Fkl.jpg',
  45. 'uploader': 'VidLii',
  46. 'uploader_url': 'https://www.vidlii.com/user/VidLii',
  47. 'upload_date': '20200927',
  48. 'duration': 5,
  49. 'view_count': int,
  50. 'comment_count': int,
  51. 'average_rating': float,
  52. 'categories': ['Film & Animation'],
  53. 'tags': list,
  54. },
  55. }, {
  56. 'url': 'https://www.vidlii.com/embed?v=tJluaH4BJ3v&a=0',
  57. 'only_matching': True,
  58. }]
  59. def _real_extract(self, url):
  60. video_id = self._match_id(url)
  61. webpage = self._download_webpage(
  62. 'https://www.vidlii.com/watch?v=%s' % video_id, video_id)
  63. formats = []
  64. def add_format(format_url, height=None):
  65. height = int(self._search_regex(r'(\d+)\.mp4',
  66. format_url, 'height', default=360))
  67. formats.append({
  68. 'url': format_url,
  69. 'format_id': '%dp' % height if height else None,
  70. 'height': height,
  71. })
  72. sources = re.findall(
  73. r'src\s*:\s*(["\'])(?P<url>(?:https?://)?(?:(?!\1).)+)\1',
  74. webpage)
  75. formats = []
  76. if len(sources) > 1:
  77. add_format(sources[1][1])
  78. self._check_formats(formats, video_id)
  79. if len(sources) > 0:
  80. add_format(sources[0][1])
  81. self._sort_formats(formats)
  82. title = self._html_search_regex(
  83. (r'<h1>([^<]+)</h1>', r'<title>([^<]+) - VidLii<'), webpage,
  84. 'title')
  85. description = self._html_search_meta(
  86. ('description', 'twitter:description'), webpage,
  87. default=None) or strip_or_none(
  88. get_element_by_id('des_text', webpage))
  89. thumbnail = self._html_search_meta(
  90. 'twitter:image', webpage, default=None)
  91. if not thumbnail:
  92. thumbnail_path = self._search_regex(
  93. r'img\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
  94. 'thumbnail', fatal=False, group='url')
  95. if thumbnail_path:
  96. thumbnail = urljoin(url, thumbnail_path)
  97. uploader = self._search_regex(
  98. r'<div[^>]+class=["\']wt_person[^>]+>\s*<a[^>]+\bhref=["\']/user/[^>]+>([^<]+)',
  99. webpage, 'uploader', fatal=False)
  100. uploader_url = 'https://www.vidlii.com/user/%s' % uploader if uploader else None
  101. upload_date = unified_strdate(self._html_search_meta(
  102. 'datePublished', webpage, default=None) or self._search_regex(
  103. r'<date>([^<]+)', webpage, 'upload date', fatal=False))
  104. duration = int_or_none(self._html_search_meta(
  105. 'video:duration', webpage, 'duration',
  106. default=None) or self._search_regex(
  107. r'duration\s*:\s*(\d+)', webpage, 'duration', fatal=False))
  108. view_count = str_to_int(self._html_search_regex(
  109. (r'<strong>([\d,.]+)</strong> views',
  110. r'Views\s*:\s*<strong>([\d,.]+)</strong>'),
  111. webpage, 'view count', fatal=False))
  112. comment_count = int_or_none(self._search_regex(
  113. (r'<span[^>]+id=["\']cmt_num[^>]+>(\d+)',
  114. r'Comments\s*:\s*<strong>(\d+)'),
  115. webpage, 'comment count', fatal=False))
  116. average_rating = float_or_none(self._search_regex(
  117. r'rating\s*:\s*([\d.]+)', webpage, 'average rating', fatal=False))
  118. category = self._html_search_regex(
  119. r'<div>Category\s*:\s*</div>\s*<div>\s*<a[^>]+>([^<]+)', webpage,
  120. 'category', fatal=False)
  121. categories = [category] if category else None
  122. tags = [
  123. strip_or_none(tag)
  124. for tag in re.findall(
  125. r'<a[^>]+\bhref=["\']/results\?.*?q=[^>]*>([^<]+)',
  126. webpage) if strip_or_none(tag)
  127. ] or None
  128. return {
  129. 'id': video_id,
  130. 'formats': formats,
  131. 'title': title,
  132. 'description': description,
  133. 'thumbnail': thumbnail,
  134. 'uploader': uploader,
  135. 'uploader_url': uploader_url,
  136. 'upload_date': upload_date,
  137. 'duration': duration,
  138. 'view_count': view_count,
  139. 'comment_count': comment_count,
  140. 'average_rating': average_rating,
  141. 'categories': categories,
  142. 'tags': tags,
  143. }