]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/sapo.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / yt_dlp / extractor / sapo.py
CommitLineData
604f292a
S
1import re
2
3from .common import InfoExtractor
4from ..utils import (
5 parse_duration,
6 unified_strdate,
7)
8
9
10class 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})'
13
14 _TESTS = [
15 {
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'],
28 },
29 },
30 {
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'],
43 },
44 },
45 {
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'],
58 },
59 },
60 ]
61
62 def _real_extract(self, url):
5ad28e7f 63 mobj = self._match_valid_url(url)
604f292a
S
64 video_id = mobj.group('id')
65
66 item = self._download_xml(
add96eb9 67 f'http://rd3.videos.sapo.pt/{video_id}/rss2', video_id).find('./channel/item')
604f292a
S
68
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
80
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')
83
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]),
90 }]
91
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,
99 })
100
604f292a
S
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,
114 }