]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/zapiks.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / zapiks.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import (
5 int_or_none,
6 parse_duration,
7 parse_iso8601,
8 xpath_text,
9 xpath_with_ns,
10 )
11
12
13 class ZapiksIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?zapiks\.(?:fr|com)/(?:(?:[a-z]{2}/)?(?P<display_id>.+?)\.html|index\.php\?.*\bmedia_id=(?P<id>\d+))'
15 _EMBED_REGEX = [r'<iframe[^>]+src="(?P<url>https?://(?:www\.)?zapiks\.fr/index\.php\?.+?)"']
16 _TESTS = [
17 {
18 'url': 'http://www.zapiks.fr/ep2s3-bon-appetit-eh-be-viva.html',
19 'md5': 'aeb3c473b2d564b2d46d664d28d5f050',
20 'info_dict': {
21 'id': '80798',
22 'ext': 'mp4',
23 'title': 'EP2S3 - Bon Appétit - Eh bé viva les pyrénées con!',
24 'description': 'md5:7054d6f6f620c6519be1fe710d4da847',
25 'thumbnail': r're:^https?://.*\.jpg$',
26 'duration': 528,
27 'timestamp': 1359044972,
28 'upload_date': '20130124',
29 'view_count': int,
30 },
31 },
32 {
33 'url': 'http://www.zapiks.com/ep3s5-bon-appetit-baqueira-m-1.html',
34 'only_matching': True,
35 },
36 {
37 'url': 'http://www.zapiks.com/nl/ep3s5-bon-appetit-baqueira-m-1.html',
38 'only_matching': True,
39 },
40 {
41 'url': 'http://www.zapiks.fr/index.php?action=playerIframe&amp;media_id=118046&amp;width=640&amp;height=360&amp;autoStart=false&amp;language=fr',
42 'only_matching': True,
43 },
44 ]
45
46 def _real_extract(self, url):
47 mobj = self._match_valid_url(url)
48 video_id = mobj.group('id')
49 display_id = mobj.group('display_id') or video_id
50
51 webpage = self._download_webpage(url, display_id)
52
53 if not video_id:
54 video_id = self._search_regex(
55 r'data-media-id="(\d+)"', webpage, 'video id')
56
57 playlist = self._download_xml(
58 'http://www.zapiks.fr/view/index.php?action=playlist&media_id=%s&lang=en' % video_id,
59 display_id)
60
61 NS_MAP = {
62 'jwplayer': 'http://rss.jwpcdn.com/'
63 }
64
65 def ns(path):
66 return xpath_with_ns(path, NS_MAP)
67
68 item = playlist.find('./channel/item')
69
70 title = xpath_text(item, 'title', 'title') or self._og_search_title(webpage)
71 description = self._og_search_description(webpage, default=None)
72 thumbnail = xpath_text(
73 item, ns('./jwplayer:image'), 'thumbnail') or self._og_search_thumbnail(webpage, default=None)
74 duration = parse_duration(self._html_search_meta(
75 'duration', webpage, 'duration', default=None))
76 timestamp = parse_iso8601(self._html_search_meta(
77 'uploadDate', webpage, 'upload date', default=None), ' ')
78
79 view_count = int_or_none(self._search_regex(
80 r'UserPlays:(\d+)', webpage, 'view count', default=None))
81 comment_count = int_or_none(self._search_regex(
82 r'UserComments:(\d+)', webpage, 'comment count', default=None))
83
84 formats = []
85 for source in item.findall(ns('./jwplayer:source')):
86 format_id = source.attrib['label']
87 f = {
88 'url': source.attrib['file'],
89 'format_id': format_id,
90 }
91 m = re.search(r'^(?P<height>\d+)[pP]', format_id)
92 if m:
93 f['height'] = int(m.group('height'))
94 formats.append(f)
95
96 return {
97 'id': video_id,
98 'title': title,
99 'description': description,
100 'thumbnail': thumbnail,
101 'duration': duration,
102 'timestamp': timestamp,
103 'view_count': view_count,
104 'comment_count': comment_count,
105 'formats': formats,
106 }