vidlii.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import re
  2. from .common import InfoExtractor
  3. from ..networking import HEADRequest
  4. from ..utils import (
  5. float_or_none,
  6. format_field,
  7. get_element_by_id,
  8. int_or_none,
  9. str_to_int,
  10. strip_or_none,
  11. unified_strdate,
  12. urljoin,
  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. 'url': 'https://www.vidlii.com/watch?v=zTAtaAgOLKt',
  37. 'md5': '5778f7366aa4c569b77002f8bf6b614f',
  38. 'info_dict': {
  39. 'id': 'zTAtaAgOLKt',
  40. 'ext': 'mp4',
  41. 'title': 'FULPTUBE SUCKS.',
  42. 'description': 'md5:087b2ca355d4c8f8f77e97c43e72d711',
  43. 'thumbnail': 'https://www.vidlii.com/usfi/thmp/zTAtaAgOLKt.jpg',
  44. 'uploader': 'Homicide',
  45. 'uploader_url': 'https://www.vidlii.com/user/Homicide',
  46. 'upload_date': '20210612',
  47. 'duration': 89,
  48. 'view_count': int,
  49. 'comment_count': int,
  50. 'average_rating': float,
  51. 'categories': ['News & Politics'],
  52. 'tags': ['fulp', 'tube', 'sucks', 'bad', 'fulptube'],
  53. },
  54. }, {
  55. 'url': 'https://www.vidlii.com/embed?v=tJluaH4BJ3v&a=0',
  56. 'only_matching': True,
  57. }]
  58. def _real_extract(self, url):
  59. video_id = self._match_id(url)
  60. webpage = self._download_webpage(
  61. f'https://www.vidlii.com/watch?v={video_id}', video_id)
  62. formats = []
  63. sources = [source[1] for source in re.findall(
  64. r'src\s*:\s*(["\'])(?P<url>(?:https?://)?(?:(?!\1).)+)\1',
  65. webpage) or []]
  66. for source in sources:
  67. source = urljoin(url, source)
  68. height = int(self._search_regex(r'(\d+).mp4', source, 'height', default=360))
  69. if self._request_webpage(HEADRequest(source), video_id, f'Checking {height}p url', errnote=False):
  70. formats.append({
  71. 'url': source,
  72. 'format_id': f'{height}p',
  73. 'height': height,
  74. })
  75. title = self._search_regex(
  76. (r'<h1>([^<]+)</h1>', r'<title>([^<]+) - VidLii<'), webpage,
  77. 'title')
  78. description = self._html_search_meta(
  79. ('description', 'twitter:description'), webpage,
  80. default=None) or strip_or_none(
  81. get_element_by_id('des_text', webpage))
  82. thumbnail = self._html_search_meta(
  83. 'twitter:image', webpage, default=None)
  84. if not thumbnail:
  85. thumbnail_path = self._search_regex(
  86. r'img\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
  87. 'thumbnail', fatal=False, group='url')
  88. if thumbnail_path:
  89. thumbnail = urljoin(url, thumbnail_path)
  90. uploader = self._search_regex(
  91. r'<div[^>]+class=["\']wt_person[^>]+>\s*<a[^>]+\bhref=["\']/user/[^>]+>([^<]+)',
  92. webpage, 'uploader', fatal=False)
  93. uploader_url = format_field(uploader, None, 'https://www.vidlii.com/user/%s')
  94. upload_date = unified_strdate(self._html_search_meta(
  95. 'datePublished', webpage, default=None) or self._search_regex(
  96. r'<date>([^<]+)', webpage, 'upload date', fatal=False))
  97. duration = int_or_none(self._html_search_meta(
  98. 'video:duration', webpage, 'duration',
  99. default=None) or self._search_regex(
  100. r'duration\s*:\s*(\d+)', webpage, 'duration', fatal=False))
  101. view_count = str_to_int(self._search_regex(
  102. (r'<strong>([,0-9]+)</strong> views',
  103. r'Views\s*:\s*<strong>([,0-9]+)</strong>'),
  104. webpage, 'view count', fatal=False))
  105. comment_count = int_or_none(self._search_regex(
  106. (r'<span[^>]+id=["\']cmt_num[^>]+>(\d+)',
  107. r'Comments\s*:\s*<strong>(\d+)'),
  108. webpage, 'comment count', fatal=False))
  109. average_rating = float_or_none(self._search_regex(
  110. r'rating\s*:\s*([\d.]+)', webpage, 'average rating', fatal=False))
  111. category = self._html_search_regex(
  112. r'<div>Category\s*:\s*</div>\s*<div>\s*<a[^>]+>([^<]+)', webpage,
  113. 'category', fatal=False)
  114. categories = [category] if category else None
  115. tags = [
  116. strip_or_none(tag)
  117. for tag in re.findall(
  118. r'<a[^>]+\bhref=["\']/results\?.*?q=[^>]*>([^<]+)',
  119. webpage) if strip_or_none(tag)
  120. ] or None
  121. return {
  122. 'id': video_id,
  123. 'title': title,
  124. 'description': description,
  125. 'thumbnail': thumbnail,
  126. 'uploader': uploader,
  127. 'formats': formats,
  128. 'uploader_url': uploader_url,
  129. 'upload_date': upload_date,
  130. 'duration': duration,
  131. 'view_count': view_count,
  132. 'comment_count': comment_count,
  133. 'average_rating': average_rating,
  134. 'categories': categories,
  135. 'tags': tags,
  136. }