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