[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / sapo.py
blob2b8c078ea02c239921d3c58de5de8abebed4e0f2
1 import re
3 from .common import InfoExtractor
4 from ..utils import (
5 parse_duration,
6 unified_strdate,
10 class SapoIE(InfoExtractor):
11 IE_DESC = 'SAPO Vídeos'
12 _VALID_URL = r'https?://(?:(?:v2|www)\.)?videos\.sapo\.(?:pt|cv|ao|mz|tl)/(?P<id>[\da-zA-Z]{20})'
14 _TESTS = [
16 'url': 'http://videos.sapo.pt/UBz95kOtiWYUMTA5Ghfi',
17 'md5': '79ee523f6ecb9233ac25075dee0eda83',
18 'note': 'SD video',
19 'info_dict': {
20 'id': 'UBz95kOtiWYUMTA5Ghfi',
21 'ext': 'mp4',
22 'title': 'Benfica - Marcas na Hitória',
23 'description': 'md5:c9082000a128c3fd57bf0299e1367f22',
24 'duration': 264,
25 'uploader': 'tiago_1988',
26 'upload_date': '20080229',
27 'categories': ['benfica', 'cabral', 'desporto', 'futebol', 'geovanni', 'hooijdonk', 'joao', 'karel', 'lisboa', 'miccoli'],
31 'url': 'http://videos.sapo.pt/IyusNAZ791ZdoCY5H5IF',
32 'md5': '90a2f283cfb49193fe06e861613a72aa',
33 'note': 'HD video',
34 'info_dict': {
35 'id': 'IyusNAZ791ZdoCY5H5IF',
36 'ext': 'mp4',
37 'title': 'Codebits VII - Report',
38 'description': 'md5:6448d6fd81ce86feac05321f354dbdc8',
39 'duration': 144,
40 'uploader': 'codebits',
41 'upload_date': '20140427',
42 'categories': ['codebits', 'codebits2014'],
46 'url': 'http://v2.videos.sapo.pt/yLqjzPtbTimsn2wWBKHz',
47 'md5': 'e5aa7cc0bdc6db9b33df1a48e49a15ac',
48 'note': 'v2 video',
49 'info_dict': {
50 'id': 'yLqjzPtbTimsn2wWBKHz',
51 'ext': 'mp4',
52 'title': 'Hipnose Condicionativa 4',
53 'description': 'md5:ef0481abf8fb4ae6f525088a6dadbc40',
54 'duration': 692,
55 'uploader': 'sapozen',
56 'upload_date': '20090609',
57 'categories': ['condicionativa', 'heloisa', 'hipnose', 'miranda', 'sapo', 'zen'],
62 def _real_extract(self, url):
63 mobj = self._match_valid_url(url)
64 video_id = mobj.group('id')
66 item = self._download_xml(
67 f'http://rd3.videos.sapo.pt/{video_id}/rss2', video_id).find('./channel/item')
69 title = item.find('./title').text
70 description = item.find('./{http://videos.sapo.pt/mrss/}synopse').text
71 thumbnail = item.find('./{http://search.yahoo.com/mrss/}content').get('url')
72 duration = parse_duration(item.find('./{http://videos.sapo.pt/mrss/}time').text)
73 uploader = item.find('./{http://videos.sapo.pt/mrss/}author').text
74 upload_date = unified_strdate(item.find('./pubDate').text)
75 view_count = int(item.find('./{http://videos.sapo.pt/mrss/}views').text)
76 comment_count = int(item.find('./{http://videos.sapo.pt/mrss/}comment_count').text)
77 tags = item.find('./{http://videos.sapo.pt/mrss/}tags').text
78 categories = tags.split() if tags else []
79 age_limit = 18 if item.find('./{http://videos.sapo.pt/mrss/}m18').text == 'true' else 0
81 video_url = item.find('./{http://videos.sapo.pt/mrss/}videoFile').text
82 video_size = item.find('./{http://videos.sapo.pt/mrss/}videoSize').text.split('x')
84 formats = [{
85 'url': video_url,
86 'ext': 'mp4',
87 'format_id': 'sd',
88 'width': int(video_size[0]),
89 'height': int(video_size[1]),
92 if item.find('./{http://videos.sapo.pt/mrss/}HD').text == 'true':
93 formats.append({
94 'url': re.sub(r'/mov/1$', '/mov/39', video_url),
95 'ext': 'mp4',
96 'format_id': 'hd',
97 'width': 1280,
98 'height': 720,
101 return {
102 'id': video_id,
103 'title': title,
104 'description': description,
105 'thumbnail': thumbnail,
106 'duration': duration,
107 'uploader': uploader,
108 'upload_date': upload_date,
109 'view_count': view_count,
110 'comment_count': comment_count,
111 'categories': categories,
112 'age_limit': age_limit,
113 'formats': formats,