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