]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/kamcord.py
Merge tag 'upstream/2016.08.17'
[youtubedl] / youtube_dl / extractor / kamcord.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..compat import compat_str
5 from ..utils import (
6 int_or_none,
7 qualities,
8 )
9
10
11 class KamcordIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?kamcord\.com/v/(?P<id>[^/?#&]+)'
13 _TEST = {
14 'url': 'https://www.kamcord.com/v/hNYRduDgWb4',
15 'md5': 'c3180e8a9cfac2e86e1b88cb8751b54c',
16 'info_dict': {
17 'id': 'hNYRduDgWb4',
18 'ext': 'mp4',
19 'title': 'Drinking Madness',
20 'uploader': 'jacksfilms',
21 'uploader_id': '3044562',
22 'view_count': int,
23 'like_count': int,
24 'comment_count': int,
25 },
26 }
27
28 def _real_extract(self, url):
29 video_id = self._match_id(url)
30
31 webpage = self._download_webpage(url, video_id)
32
33 video = self._parse_json(
34 self._search_regex(
35 r'window\.__props\s*=\s*({.+?});?(?:\n|\s*</script)',
36 webpage, 'video'),
37 video_id)['video']
38
39 title = video['title']
40
41 formats = self._extract_m3u8_formats(
42 video['play']['hls'], video_id, 'mp4', entry_protocol='m3u8_native')
43 self._sort_formats(formats)
44
45 uploader = video.get('user', {}).get('username')
46 uploader_id = video.get('user', {}).get('id')
47
48 view_count = int_or_none(video.get('viewCount'))
49 like_count = int_or_none(video.get('heartCount'))
50 comment_count = int_or_none(video.get('messageCount'))
51
52 preference_key = qualities(('small', 'medium', 'large'))
53
54 thumbnails = [{
55 'url': thumbnail_url,
56 'id': thumbnail_id,
57 'preference': preference_key(thumbnail_id),
58 } for thumbnail_id, thumbnail_url in (video.get('thumbnail') or {}).items()
59 if isinstance(thumbnail_id, compat_str) and isinstance(thumbnail_url, compat_str)]
60
61 return {
62 'id': video_id,
63 'title': title,
64 'uploader': uploader,
65 'uploader_id': uploader_id,
66 'view_count': view_count,
67 'like_count': like_count,
68 'comment_count': comment_count,
69 'thumbnails': thumbnails,
70 'formats': formats,
71 }