pinkbike.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. int_or_none,
  5. remove_end,
  6. remove_start,
  7. str_to_int,
  8. unified_strdate,
  9. )
  10. class PinkbikeIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:(?:www\.)?pinkbike\.com/video/|es\.pinkbike\.org/i/kvid/kvid-y5\.swf\?id=)(?P<id>[0-9]+)'
  12. _TESTS = [{
  13. 'url': 'http://www.pinkbike.com/video/402811/',
  14. 'md5': '4814b8ca7651034cd87e3361d5c2155a',
  15. 'info_dict': {
  16. 'id': '402811',
  17. 'ext': 'mp4',
  18. 'title': 'Brandon Semenuk - RAW 100',
  19. 'description': 'Official release: www.redbull.ca/rupertwalker',
  20. 'thumbnail': r're:^https?://.*\.jpg$',
  21. 'duration': 100,
  22. 'upload_date': '20150406',
  23. 'uploader': 'revelco',
  24. 'location': 'Victoria, British Columbia, Canada',
  25. 'view_count': int,
  26. 'comment_count': int,
  27. },
  28. }, {
  29. 'url': 'http://es.pinkbike.org/i/kvid/kvid-y5.swf?id=406629',
  30. 'only_matching': True,
  31. }]
  32. def _real_extract(self, url):
  33. video_id = self._match_id(url)
  34. webpage = self._download_webpage(
  35. f'http://www.pinkbike.com/video/{video_id}', video_id)
  36. formats = []
  37. for _, format_id, src in re.findall(
  38. r'data-quality=((?:\\)?["\'])(.+?)\1[^>]+src=\1(.+?)\1', webpage):
  39. height = int_or_none(self._search_regex(
  40. r'^(\d+)[pP]$', format_id, 'height', default=None))
  41. formats.append({
  42. 'url': src,
  43. 'format_id': format_id,
  44. 'height': height,
  45. })
  46. title = remove_end(self._og_search_title(webpage), ' Video - Pinkbike')
  47. description = self._html_search_regex(
  48. r'(?s)id="media-description"[^>]*>(.+?)<',
  49. webpage, 'description', default=None) or remove_start(
  50. self._og_search_description(webpage), title + '. ')
  51. thumbnail = self._og_search_thumbnail(webpage)
  52. duration = int_or_none(self._html_search_meta(
  53. 'video:duration', webpage, 'duration'))
  54. uploader = self._search_regex(
  55. r'<a[^>]+\brel=["\']author[^>]+>([^<]+)', webpage,
  56. 'uploader', fatal=False)
  57. upload_date = unified_strdate(self._search_regex(
  58. r'class="fullTime"[^>]+title="([^"]+)"',
  59. webpage, 'upload date', fatal=False))
  60. location = self._html_search_regex(
  61. r'(?s)<dt>Location</dt>\s*<dd>(.+?)<',
  62. webpage, 'location', fatal=False)
  63. def extract_count(webpage, label):
  64. return str_to_int(self._search_regex(
  65. rf'<span[^>]+class="stat-num"[^>]*>([\d,.]+)</span>\s*<span[^>]+class="stat-label"[^>]*>{label}',
  66. webpage, label, fatal=False))
  67. view_count = extract_count(webpage, 'Views')
  68. comment_count = extract_count(webpage, 'Comments')
  69. return {
  70. 'id': video_id,
  71. 'title': title,
  72. 'description': description,
  73. 'thumbnail': thumbnail,
  74. 'duration': duration,
  75. 'upload_date': upload_date,
  76. 'uploader': uploader,
  77. 'location': location,
  78. 'view_count': view_count,
  79. 'comment_count': comment_count,
  80. 'formats': formats,
  81. }