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.

78 lines
2.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. class PinkbikeIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?pinkbike\.com/video/(?P<id>[0-9]+)'
  7. _TESTS = [{
  8. 'url': 'http://www.pinkbike.com/video/402811/',
  9. 'md5': '4814b8ca7651034cd87e3361d5c2155a',
  10. 'info_dict': {
  11. 'id': '402811',
  12. 'ext': 'mp4',
  13. 'title': 'Brandon Semenuk - RAW 100',
  14. 'thumbnail': 're:^https?://.*\.jpg$',
  15. 'location': 'Victoria, British Columbia, Canada',
  16. 'uploader_id': 'revelco',
  17. 'upload_date': '20150406',
  18. 'description': 'Official release: www.redbull.ca/rupertwalker',
  19. 'duration': 100
  20. }
  21. }, {
  22. 'url': 'http://www.pinkbike.com/video/406629/',
  23. 'md5': 'c7a3e19a2bd5cde5a1cda6b2b46caa74',
  24. 'info_dict': {
  25. 'id': '406629',
  26. 'ext': 'mp4',
  27. 'title': 'Chromag: Reece Wallace in Utah',
  28. 'thumbnail': 're:^https?://.*\.jpg$',
  29. 'location': 'Whistler, British Columbia, Canada',
  30. 'uploader_id': 'Chromagbikes',
  31. 'upload_date': '20150505',
  32. 'description': 'Reece Wallace shredding Virgin, Utah. Video by Virtu Media.',
  33. 'duration': 180
  34. }
  35. }]
  36. def _real_extract(self, url):
  37. video_id = self._match_id(url)
  38. webpage = self._download_webpage(url, video_id)
  39. title = self._html_search_regex(r'<title>(.*?)</title>', webpage, 'title')
  40. title = title[:-len(' Video - Pinkbike')]
  41. description = self._html_search_meta('description', webpage, 'description')
  42. description = description[len(title + '. '):]
  43. uploader_id = self._html_search_regex(r'un:\s*"(.*?)"', webpage, 'uploader_id')
  44. upload_date = self._html_search_regex(
  45. r'class="fullTime"\s*title="([0-9]{4}(?:-[0-9]{2}){2})"',
  46. webpage, 'upload_date')
  47. upload_date = upload_date.replace('-', '')
  48. location = self._html_search_regex(
  49. r'<dt>Location</dt>\n?\s*<dd>\n?(.*?)\s*<img',
  50. webpage, 'location')
  51. formats = re.findall(
  52. r'<source data-quality=\\"([0-9]+)p\\" src=\\"(.*?)\\">',
  53. webpage)
  54. formats = [{'url': fmt[1], 'height': fmt[0]} for fmt in formats]
  55. return {
  56. 'id': video_id,
  57. 'title': title,
  58. 'description': description,
  59. 'duration': int(self._html_search_meta('video:duration', webpage, 'duration')),
  60. 'thumbnail': self._html_search_meta('og:image', webpage, 'thumbnail'),
  61. 'uploader_id': uploader_id,
  62. 'upload_date': upload_date,
  63. 'location': location,
  64. 'formats': formats
  65. }