1
0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-12-15 17:21:24 +01:00
youtube-dl/youtube_dl/extractor/pinkbike.py

98 lines
3.4 KiB
Python
Raw Normal View History

2015-05-24 22:26:59 +02:00
# coding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..utils import (
int_or_none,
remove_end,
2015-06-19 20:10:08 +02:00
remove_start,
str_to_int,
unified_strdate,
)
2015-05-24 22:26:59 +02:00
class PinkbikeIE(InfoExtractor):
2015-06-19 20:10:08 +02:00
_VALID_URL = r'https?://(?:(?:www\.)?pinkbike\.com/video/|es\.pinkbike\.org/i/kvid/kvid-y5\.swf\?id=)(?P<id>[0-9]+)'
2015-05-24 22:26:59 +02:00
_TESTS = [{
'url': 'http://www.pinkbike.com/video/402811/',
'md5': '4814b8ca7651034cd87e3361d5c2155a',
'info_dict': {
'id': '402811',
'ext': 'mp4',
'title': 'Brandon Semenuk - RAW 100',
2015-06-19 20:10:08 +02:00
'description': 'Official release: www.redbull.ca/rupertwalker',
'thumbnail': r're:^https?://.*\.jpg$',
2015-06-19 20:10:08 +02:00
'duration': 100,
2015-05-24 22:26:59 +02:00
'upload_date': '20150406',
2015-06-19 20:10:08 +02:00
'uploader': 'revelco',
'location': 'Victoria, British Columbia, Canada',
'view_count': int,
'comment_count': int,
2015-05-24 22:26:59 +02:00
}
}, {
2015-06-19 20:10:08 +02:00
'url': 'http://es.pinkbike.org/i/kvid/kvid-y5.swf?id=406629',
'only_matching': True,
2015-05-24 22:26:59 +02:00
}]
def _real_extract(self, url):
video_id = self._match_id(url)
2015-06-19 20:10:08 +02:00
webpage = self._download_webpage(
'http://www.pinkbike.com/video/%s' % video_id, video_id)
2015-05-24 22:26:59 +02:00
2015-06-19 20:10:08 +02:00
formats = []
for _, format_id, src in re.findall(
2015-06-21 12:22:19 +02:00
r'data-quality=((?:\\)?["\'])(.+?)\1[^>]+src=\1(.+?)\1', webpage):
2015-06-19 20:10:08 +02:00
height = int_or_none(self._search_regex(
r'^(\d+)[pP]$', format_id, 'height', default=None))
formats.append({
'url': src,
'format_id': format_id,
'height': height,
})
self._sort_formats(formats)
2015-06-19 20:10:08 +02:00
title = remove_end(self._og_search_title(webpage), ' Video - Pinkbike')
description = self._html_search_regex(
r'(?s)id="media-description"[^>]*>(.+?)<',
webpage, 'description', default=None) or remove_start(
self._og_search_description(webpage), title + '. ')
thumbnail = self._og_search_thumbnail(webpage)
duration = int_or_none(self._html_search_meta(
'video:duration', webpage, 'duration'))
2015-05-24 22:26:59 +02:00
2015-06-19 20:10:08 +02:00
uploader = self._search_regex(
r'<a[^>]+\brel=["\']author[^>]+>([^<]+)', webpage,
'uploader', fatal=False)
2015-06-19 20:10:08 +02:00
upload_date = unified_strdate(self._search_regex(
r'class="fullTime"[^>]+title="([^"]+)"',
webpage, 'upload date', fatal=False))
2015-05-24 22:26:59 +02:00
location = self._html_search_regex(
2015-06-19 20:10:08 +02:00
r'(?s)<dt>Location</dt>\s*<dd>(.+?)<',
webpage, 'location', fatal=False)
2015-05-24 22:26:59 +02:00
2015-06-19 20:10:08 +02:00
def extract_count(webpage, label):
return str_to_int(self._search_regex(
r'<span[^>]+class="stat-num"[^>]*>([\d,.]+)</span>\s*<span[^>]+class="stat-label"[^>]*>%s' % label,
webpage, label, fatal=False))
2015-05-24 22:26:59 +02:00
2015-06-19 20:10:08 +02:00
view_count = extract_count(webpage, 'Views')
comment_count = extract_count(webpage, 'Comments')
2015-05-24 22:26:59 +02:00
return {
'id': video_id,
'title': title,
'description': description,
2015-06-19 20:10:08 +02:00
'thumbnail': thumbnail,
'duration': duration,
2015-05-24 22:26:59 +02:00
'upload_date': upload_date,
2015-06-19 20:10:08 +02:00
'uploader': uploader,
2015-05-24 22:26:59 +02:00
'location': location,
2015-06-19 20:10:08 +02:00
'view_count': view_count,
'comment_count': comment_count,
2015-05-24 22:26:59 +02:00
'formats': formats
}