[zaq1] Add new extractor
[youtube-dl] / youtube_dl / extractor / zaq1.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     unified_strdate,
7     int_or_none
8 )
9
10
11 class Zaq1IE(InfoExtractor):
12     _VALID_URL = r'http://(?:www\.)?zaq1\.pl/video/(?P<id>[^/?#&]+)'
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',
19             'ext': 'mp4',
20             'duration': 511,
21             'uploader': 'Anonim',
22             'upload_date': '20170330',
23         }
24     }, {
25         'url': 'http://zaq1.pl/video/x80nc',
26         'md5': '1245973520adc78139928a820959d9c5',
27         'info_dict': {
28             'id': 'x80nc',
29             'title': 'DIY Inspiration Challenge #86 | koraliki | gwiazdka na choinkę z koralików i drutu',
30             'ext': 'mp4',
31             'duration': 438,
32             'uploader': 'Anonim',
33             'upload_date': '20170404',
34         }
35     }]
36
37     def _real_extract(self, url):
38         video_id = self._match_id(url)
39
40         webpage = self._download_webpage(url, video_id)
41
42         title = self._html_search_regex(
43             r'(?s)<h1>\s*<span.+class="watch-title".+title="([^"]+)">\1\s*</span>\s*</h1>', webpage, 'title')
44
45         div = self._search_regex(r'(?s)(?P<div><div.+id=(["\'])video_player\2.+</div>)', webpage, 'video url', group='div')
46         video_url = self._search_regex(r'data-video-url="(http[^"]+)"', div, 'video url')
47
48         ext = self._search_regex(r'data-file-extension="([^"]+)"', div, 'ext', None, False)
49         duration = int_or_none(self._search_regex(r'data-duration="([^"]+)"', div, 'duration', None, False))
50         thumbnail = self._search_regex(r'data-photo-url="([^"]+)"', div, 'thumbnail', None, False)
51
52         upload_date = unified_strdate(self._search_regex(r'<strong\s+class="watch-time-text">\s*Opublikowany\s+([0-9]{4}-[0-9]{2}-[0-9]{2})', webpage, 'upload date'))
53         uploader = self._search_regex(r'<div\s+id="watch7-user-header">.*Wideo dodał:\s*<a[^>]*>\s*([^<]+)\s*</a>', webpage, 'uploader')
54
55         return {
56             'id': video_id,
57             'title': title,
58             'formats': [{
59                 'url': video_url,
60                 'ext': ext,
61                 'http_headers': {'Referer': url},
62             }],
63             'thumbnail': thumbnail,
64             'uploader': uploader,
65             'upload_date': upload_date,
66             'duration': duration,
67         }