vidlii.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. HEADRequest,
  5. format_field,
  6. float_or_none,
  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. 'https://www.vidlii.com/watch?v=%s' % 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. height = int(self._search_regex(r'(\d+).mp4', source, 'height', default=360))
  68. if self._request_webpage(HEADRequest(source), video_id, f'Checking {height}p url', errnote=False):
  69. formats.append({
  70. 'url': source,
  71. 'format_id': f'{height}p',
  72. 'height': height,
  73. })
  74. title = self._search_regex(
  75. (r'<h1>([^<]+)</h1>', r'<title>([^<]+) - VidLii<'), webpage,
  76. 'title')
  77. description = self._html_search_meta(
  78. ('description', 'twitter:description'), webpage,
  79. default=None) or strip_or_none(
  80. get_element_by_id('des_text', webpage))
  81. thumbnail = self._html_search_meta(
  82. 'twitter:image', webpage, default=None)
  83. if not thumbnail:
  84. thumbnail_path = self._search_regex(
  85. r'img\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
  86. 'thumbnail', fatal=False, group='url')
  87. if thumbnail_path:
  88. thumbnail = urljoin(url, thumbnail_path)
  89. uploader = self._search_regex(
  90. r'<div[^>]+class=["\']wt_person[^>]+>\s*<a[^>]+\bhref=["\']/user/[^>]+>([^<]+)',
  91. webpage, 'uploader', fatal=False)
  92. uploader_url = format_field(uploader, None, 'https://www.vidlii.com/user/%s')
  93. upload_date = unified_strdate(self._html_search_meta(
  94. 'datePublished', webpage, default=None) or self._search_regex(
  95. r'<date>([^<]+)', webpage, 'upload date', fatal=False))
  96. duration = int_or_none(self._html_search_meta(
  97. 'video:duration', webpage, 'duration',
  98. default=None) or self._search_regex(
  99. r'duration\s*:\s*(\d+)', webpage, 'duration', fatal=False))
  100. view_count = str_to_int(self._search_regex(
  101. (r'<strong>([,0-9]+)</strong> views',
  102. r'Views\s*:\s*<strong>([,0-9]+)</strong>'),
  103. webpage, 'view count', fatal=False))
  104. comment_count = int_or_none(self._search_regex(
  105. (r'<span[^>]+id=["\']cmt_num[^>]+>(\d+)',
  106. r'Comments\s*:\s*<strong>(\d+)'),
  107. webpage, 'comment count', fatal=False))
  108. average_rating = float_or_none(self._search_regex(
  109. r'rating\s*:\s*([\d.]+)', webpage, 'average rating', fatal=False))
  110. category = self._html_search_regex(
  111. r'<div>Category\s*:\s*</div>\s*<div>\s*<a[^>]+>([^<]+)', webpage,
  112. 'category', fatal=False)
  113. categories = [category] if category else None
  114. tags = [
  115. strip_or_none(tag)
  116. for tag in re.findall(
  117. r'<a[^>]+\bhref=["\']/results\?.*?q=[^>]*>([^<]+)',
  118. webpage) if strip_or_none(tag)
  119. ] or None
  120. return {
  121. 'id': video_id,
  122. 'title': title,
  123. 'description': description,
  124. 'thumbnail': thumbnail,
  125. 'uploader': uploader,
  126. 'formats': formats,
  127. 'uploader_url': uploader_url,
  128. 'upload_date': upload_date,
  129. 'duration': duration,
  130. 'view_count': view_count,
  131. 'comment_count': comment_count,
  132. 'average_rating': average_rating,
  133. 'categories': categories,
  134. 'tags': tags,
  135. }