]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/vidme.py
[odnoklassniki] Use compat_urllib_parse_unquote
[youtube-dl.git] / youtube_dl / extractor / vidme.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import (
5     int_or_none,
6     float_or_none,
7     str_to_int,
8 )
9
10
11 class VidmeIE(InfoExtractor):
12     _VALID_URL = r'https?://vid\.me/(?:e/)?(?P<id>[\da-zA-Z]+)'
13     _TESTS = [{
14         'url': 'https://vid.me/QNB',
15         'md5': 'f42d05e7149aeaec5c037b17e5d3dc82',
16         'info_dict': {
17             'id': 'QNB',
18             'ext': 'mp4',
19             'title': 'Fishing for piranha - the easy way',
20             'description': 'source: https://www.facebook.com/photo.php?v=312276045600871',
21             'duration': 119.92,
22             'timestamp': 1406313244,
23             'upload_date': '20140725',
24             'thumbnail': 're:^https?://.*\.jpg',
25         },
26     }, {
27         # From http://naked-yogi.tumblr.com/post/118312946248/naked-smoking-stretching
28         'url': 'https://vid.me/e/Wmur',
29         'only_matching': True,
30     }]
31
32     def _real_extract(self, url):
33         url = url.replace('vid.me/e/', 'vid.me/')
34         video_id = self._match_id(url)
35         webpage = self._download_webpage(url, video_id)
36
37         video_url = self._html_search_regex(
38             r'<source src="([^"]+)"', webpage, 'video URL')
39
40         title = self._og_search_title(webpage)
41         description = self._og_search_description(webpage, default='')
42         thumbnail = self._og_search_thumbnail(webpage)
43         timestamp = int_or_none(self._og_search_property('updated_time', webpage, fatal=False))
44         width = int_or_none(self._og_search_property('video:width', webpage, fatal=False))
45         height = int_or_none(self._og_search_property('video:height', webpage, fatal=False))
46         duration = float_or_none(self._html_search_regex(
47             r'data-duration="([^"]+)"', webpage, 'duration', fatal=False))
48         view_count = str_to_int(self._html_search_regex(
49             r'<(?:li|span) class="video_views">\s*([\d,\.]+)\s*plays?', webpage, 'view count', fatal=False))
50         like_count = str_to_int(self._html_search_regex(
51             r'class="score js-video-vote-score"[^>]+data-score="([\d,\.\s]+)">',
52             webpage, 'like count', fatal=False))
53
54         return {
55             'id': video_id,
56             'url': video_url,
57             'title': title,
58             'description': description,
59             'thumbnail': thumbnail,
60             'timestamp': timestamp,
61             'width': width,
62             'height': height,
63             'duration': duration,
64             'view_count': view_count,
65             'like_count': like_count,
66         }