]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vidme.py
Imported Upstream version 2015.05.15
[youtubedl] / 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 _TEST = {
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
28 def _real_extract(self, url):
29 video_id = self._match_id(url)
30 webpage = self._download_webpage(url, video_id)
31
32 video_url = self._html_search_regex(
33 r'<source src="([^"]+)"', webpage, 'video URL')
34
35 title = self._og_search_title(webpage)
36 description = self._og_search_description(webpage, default='')
37 thumbnail = self._og_search_thumbnail(webpage)
38 timestamp = int_or_none(self._og_search_property('updated_time', webpage, fatal=False))
39 width = int_or_none(self._og_search_property('video:width', webpage, fatal=False))
40 height = int_or_none(self._og_search_property('video:height', webpage, fatal=False))
41 duration = float_or_none(self._html_search_regex(
42 r'data-duration="([^"]+)"', webpage, 'duration', fatal=False))
43 view_count = str_to_int(self._html_search_regex(
44 r'<(?:li|span) class="video_views">\s*([\d,\.]+)\s*plays?', webpage, 'view count', fatal=False))
45 like_count = str_to_int(self._html_search_regex(
46 r'class="score js-video-vote-score"[^>]+data-score="([\d,\.\s]+)">',
47 webpage, 'like count', fatal=False))
48
49 return {
50 'id': video_id,
51 'url': video_url,
52 'title': title,
53 'description': description,
54 'thumbnail': thumbnail,
55 'timestamp': timestamp,
56 'width': width,
57 'height': height,
58 'duration': duration,
59 'view_count': view_count,
60 'like_count': like_count,
61 }