]>
Commit | Line | Data |
---|---|---|
9dac2cec | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..utils import ( | |
9cd42097 S |
6 | int_or_none, |
7 | unified_timestamp, | |
9dac2cec | 8 | ) |
9 | ||
10 | ||
11 | class Zaq1IE(InfoExtractor): | |
9cd42097 | 12 | _VALID_URL = r'https?://(?:www\.)?zaq1\.pl/video/(?P<id>[^/?#&]+)' |
9dac2cec | 13 | _TESTS = [{ |
14 | 'url': 'http://zaq1.pl/video/xev0e', | |
15 | 'md5': '24a5eb3f052e604ae597c4d0d19b351e', | |
16 | 'info_dict': { | |
17 | 'id': 'xev0e', | |
18 | 'title': 'DJ NA WESELE. TANIEC Z FIGURAMI.węgrów/sokołów podlaski/siedlce/mińsk mazowiecki/warszawa', | |
9cd42097 | 19 | 'description': 'www.facebook.com/weseledjKontakt: 728 448 199 / 505 419 147', |
9dac2cec | 20 | 'ext': 'mp4', |
21 | 'duration': 511, | |
9cd42097 | 22 | 'timestamp': 1490896361, |
9dac2cec | 23 | 'uploader': 'Anonim', |
24 | 'upload_date': '20170330', | |
9cd42097 | 25 | 'view_count': int, |
9dac2cec | 26 | } |
27 | }, { | |
9cd42097 S |
28 | # malformed JSON-LD |
29 | 'url': 'http://zaq1.pl/video/x81vn', | |
9dac2cec | 30 | 'info_dict': { |
9cd42097 S |
31 | 'id': 'x81vn', |
32 | 'title': 'SEKRETNE ŻYCIE WALTERA MITTY', | |
9dac2cec | 33 | 'ext': 'mp4', |
9cd42097 S |
34 | 'duration': 6234, |
35 | 'timestamp': 1493494860, | |
9dac2cec | 36 | 'uploader': 'Anonim', |
9cd42097 S |
37 | 'upload_date': '20170429', |
38 | 'view_count': int, | |
39 | }, | |
40 | 'params': { | |
41 | 'skip_download': True, | |
42 | }, | |
43 | 'expected_warnings': ['Failed to parse JSON'], | |
9dac2cec | 44 | }] |
45 | ||
46 | def _real_extract(self, url): | |
47 | video_id = self._match_id(url) | |
48 | ||
49 | webpage = self._download_webpage(url, video_id) | |
50 | ||
9cd42097 S |
51 | video_url = self._search_regex( |
52 | r'data-video-url=(["\'])(?P<url>(?:(?!\1).)+)\1', webpage, | |
53 | 'video url', group='url') | |
54 | ||
55 | info = self._search_json_ld(webpage, video_id, fatal=False) | |
56 | ||
57 | def extract_data(field, name, fatal=False): | |
58 | return self._search_regex( | |
59 | r'data-%s=(["\'])(?P<field>(?:(?!\1).)+)\1' % field, | |
60 | webpage, field, fatal=fatal, group='field') | |
61 | ||
62 | if not info.get('title'): | |
63 | info['title'] = extract_data('file-name', 'title', fatal=True) | |
64 | ||
65 | if not info.get('duration'): | |
66 | info['duration'] = int_or_none(extract_data('duration', 'duration')) | |
9dac2cec | 67 | |
9cd42097 S |
68 | if not info.get('thumbnail'): |
69 | info['thumbnail'] = extract_data('photo-url', 'thumbnail') | |
9dac2cec | 70 | |
9cd42097 S |
71 | if not info.get('timestamp'): |
72 | info['timestamp'] = unified_timestamp(self._html_search_meta( | |
73 | 'uploadDate', webpage, 'timestamp')) | |
9dac2cec | 74 | |
9cd42097 S |
75 | if not info.get('interactionCount'): |
76 | info['view_count'] = int_or_none(self._html_search_meta( | |
77 | 'interactionCount', webpage, 'view count')) | |
9dac2cec | 78 | |
9cd42097 S |
79 | uploader = self._html_search_regex( |
80 | r'Wideo dodał:\s*<a[^>]*>([^<]+)</a>', webpage, 'uploader', | |
81 | fatal=False) | |
82 | ||
83 | width = int_or_none(self._html_search_meta( | |
84 | 'width', webpage, fatal=False)) | |
85 | height = int_or_none(self._html_search_meta( | |
86 | 'height', webpage, fatal=False)) | |
87 | ||
88 | info.update({ | |
9dac2cec | 89 | 'id': video_id, |
9dac2cec | 90 | 'formats': [{ |
91 | 'url': video_url, | |
9cd42097 S |
92 | 'width': width, |
93 | 'height': height, | |
94 | 'http_headers': { | |
95 | 'Referer': url, | |
96 | }, | |
9dac2cec | 97 | }], |
9dac2cec | 98 | 'uploader': uploader, |
9cd42097 S |
99 | }) |
100 | ||
101 | return info |