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.

125 lines
4.4 KiB

  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. )
  13. class VidLiiIE(InfoExtractor):
  14. _VALID_URL = r'https?://(?:www\.)?vidlii\.com/(?:watch|embed)\?.*?\bv=(?P<id>[0-9A-Za-z_-]{11})'
  15. _TESTS = [{
  16. 'url': 'https://www.vidlii.com/watch?v=tJluaH4BJ3v',
  17. 'md5': '9bf7d1e005dfa909b6efb0a1ff5175e2',
  18. 'info_dict': {
  19. 'id': 'tJluaH4BJ3v',
  20. 'ext': 'mp4',
  21. 'title': 'Vidlii is against me',
  22. 'description': 'md5:fa3f119287a2bfb922623b52b1856145',
  23. 'thumbnail': 're:https://.*.jpg',
  24. 'uploader': 'APPle5auc31995',
  25. 'uploader_url': 'https://www.vidlii.com/user/APPle5auc31995',
  26. 'upload_date': '20171107',
  27. 'duration': 212,
  28. 'view_count': int,
  29. 'comment_count': int,
  30. 'average_rating': float,
  31. 'categories': ['News & Politics'],
  32. 'tags': ['Vidlii', 'Jan', 'Videogames'],
  33. }
  34. }, {
  35. 'url': 'https://www.vidlii.com/embed?v=tJluaH4BJ3v&a=0',
  36. 'only_matching': True,
  37. }]
  38. def _real_extract(self, url):
  39. video_id = self._match_id(url)
  40. webpage = self._download_webpage(
  41. 'https://www.vidlii.com/watch?v=%s' % video_id, video_id)
  42. video_url = self._search_regex(
  43. r'src\s*:\s*(["\'])(?P<url>(?:https?://)?(?:(?!\1).)+)\1', webpage,
  44. 'video url', group='url')
  45. title = self._search_regex(
  46. (r'<h1>([^<]+)</h1>', r'<title>([^<]+) - VidLii<'), webpage,
  47. 'title')
  48. description = self._html_search_meta(
  49. ('description', 'twitter:description'), webpage,
  50. default=None) or strip_or_none(
  51. get_element_by_id('des_text', webpage))
  52. thumbnail = self._html_search_meta(
  53. 'twitter:image', webpage, default=None)
  54. if not thumbnail:
  55. thumbnail_path = self._search_regex(
  56. r'img\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
  57. 'thumbnail', fatal=False, group='url')
  58. if thumbnail_path:
  59. thumbnail = urljoin(url, thumbnail_path)
  60. uploader = self._search_regex(
  61. r'<div[^>]+class=["\']wt_person[^>]+>\s*<a[^>]+\bhref=["\']/user/[^>]+>([^<]+)',
  62. webpage, 'uploader', fatal=False)
  63. uploader_url = 'https://www.vidlii.com/user/%s' % uploader if uploader else None
  64. upload_date = unified_strdate(self._html_search_meta(
  65. 'datePublished', webpage, default=None) or self._search_regex(
  66. r'<date>([^<]+)', webpage, 'upload date', fatal=False))
  67. duration = int_or_none(self._html_search_meta(
  68. 'video:duration', webpage, 'duration',
  69. default=None) or self._search_regex(
  70. r'duration\s*:\s*(\d+)', webpage, 'duration', fatal=False))
  71. view_count = int_or_none(self._search_regex(
  72. (r'<strong>(\d+)</strong> views',
  73. r'Views\s*:\s*<strong>(\d+)</strong>'),
  74. webpage, 'view count', fatal=False))
  75. comment_count = int_or_none(self._search_regex(
  76. (r'<span[^>]+id=["\']cmt_num[^>]+>(\d+)',
  77. r'Comments\s*:\s*<strong>(\d+)'),
  78. webpage, 'comment count', fatal=False))
  79. average_rating = float_or_none(self._search_regex(
  80. r'rating\s*:\s*([\d.]+)', webpage, 'average rating', fatal=False))
  81. category = self._html_search_regex(
  82. r'<div>Category\s*:\s*</div>\s*<div>\s*<a[^>]+>([^<]+)', webpage,
  83. 'category', fatal=False)
  84. categories = [category] if category else None
  85. tags = [
  86. strip_or_none(tag)
  87. for tag in re.findall(
  88. r'<a[^>]+\bhref=["\']/results\?.*?q=[^>]*>([^<]+)',
  89. webpage) if strip_or_none(tag)
  90. ] or None
  91. return {
  92. 'id': video_id,
  93. 'url': video_url,
  94. 'title': title,
  95. 'description': description,
  96. 'thumbnail': thumbnail,
  97. 'uploader': uploader,
  98. 'uploader_url': uploader_url,
  99. 'upload_date': upload_date,
  100. 'duration': duration,
  101. 'view_count': view_count,
  102. 'comment_count': comment_count,
  103. 'average_rating': average_rating,
  104. 'categories': categories,
  105. 'tags': tags,
  106. }