]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/vidme.py
Merge pull request #6392 from dstftw/generalized-fragmented-fd
[yt-dlp.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 'view_count': int,
26 'like_count': int,
27 },
28 }, {
29 # tests uploader field
30 'url': 'https://vid.me/4Iib',
31 'info_dict': {
32 'id': '4Iib',
33 'ext': 'mp4',
34 'title': 'The Carver',
35 'description': 'md5:e9c24870018ae8113be936645b93ba3c',
36 'duration': 97.859999999999999,
37 'timestamp': 1433203629,
38 'upload_date': '20150602',
39 'uploader': 'Thomas',
40 'thumbnail': 're:^https?://.*\.jpg',
41 'view_count': int,
42 'like_count': int,
43 },
44 'params': {
45 'skip_download': True,
46 },
47 }, {
48 # From http://naked-yogi.tumblr.com/post/118312946248/naked-smoking-stretching
49 'url': 'https://vid.me/e/Wmur',
50 'only_matching': True,
51 }]
52
53 def _real_extract(self, url):
54 url = url.replace('vid.me/e/', 'vid.me/')
55 video_id = self._match_id(url)
56 webpage = self._download_webpage(url, video_id)
57
58 video_url = self._html_search_regex(
59 r'<source src="([^"]+)"', webpage, 'video URL')
60
61 title = self._og_search_title(webpage)
62 description = self._og_search_description(webpage, default='')
63 thumbnail = self._og_search_thumbnail(webpage)
64 timestamp = int_or_none(self._og_search_property(
65 'updated_time', webpage, fatal=False))
66 width = int_or_none(self._og_search_property(
67 'video:width', webpage, fatal=False))
68 height = int_or_none(self._og_search_property(
69 'video:height', webpage, fatal=False))
70 duration = float_or_none(self._html_search_regex(
71 r'data-duration="([^"]+)"', webpage, 'duration', fatal=False))
72 view_count = str_to_int(self._html_search_regex(
73 r'<(?:li|span) class="video_views">\s*([\d,\.]+)\s*plays?',
74 webpage, 'view count', fatal=False))
75 like_count = str_to_int(self._html_search_regex(
76 r'class="score js-video-vote-score"[^>]+data-score="([\d,\.\s]+)">',
77 webpage, 'like count', fatal=False))
78 uploader = self._html_search_regex(
79 'class="video_author_username"[^>]*>([^<]+)',
80 webpage, 'uploader', default=None)
81
82 return {
83 'id': video_id,
84 'url': video_url,
85 'title': title,
86 'description': description,
87 'thumbnail': thumbnail,
88 'timestamp': timestamp,
89 'width': width,
90 'height': height,
91 'duration': duration,
92 'view_count': view_count,
93 'like_count': like_count,
94 'uploader': uploader,
95 }