]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/esri.py
[ie/box] Fix formats extraction (#8649)
[yt-dlp.git] / yt_dlp / extractor / esri.py
1 import re
2
3 from .common import InfoExtractor
4 from ..compat import compat_urlparse
5 from ..utils import (
6 int_or_none,
7 parse_filesize,
8 unified_strdate,
9 )
10
11
12 class EsriVideoIE(InfoExtractor):
13 _VALID_URL = r'https?://video\.esri\.com/watch/(?P<id>[0-9]+)'
14 _TEST = {
15 'url': 'https://video.esri.com/watch/1124/arcgis-online-_dash_-developing-applications',
16 'md5': 'd4aaf1408b221f1b38227a9bbaeb95bc',
17 'info_dict': {
18 'id': '1124',
19 'ext': 'mp4',
20 'title': 'ArcGIS Online - Developing Applications',
21 'description': 'Jeremy Bartley demonstrates how to develop applications with ArcGIS Online.',
22 'thumbnail': r're:^https?://.*\.jpg$',
23 'duration': 185,
24 'upload_date': '20120419',
25 }
26 }
27
28 def _real_extract(self, url):
29 video_id = self._match_id(url)
30
31 webpage = self._download_webpage(url, video_id)
32
33 formats = []
34 for width, height, content in re.findall(
35 r'(?s)<li><strong>(\d+)x(\d+):</strong>(.+?)</li>', webpage):
36 for video_url, ext, filesize in re.findall(
37 r'<a[^>]+href="([^"]+)">([^<]+)&nbsp;\(([^<]+)\)</a>', content):
38 formats.append({
39 'url': compat_urlparse.urljoin(url, video_url),
40 'ext': ext.lower(),
41 'format_id': '%s-%s' % (ext.lower(), height),
42 'width': int(width),
43 'height': int(height),
44 'filesize_approx': parse_filesize(filesize),
45 })
46
47 title = self._html_search_meta('title', webpage, 'title')
48 description = self._html_search_meta(
49 'description', webpage, 'description', fatal=False)
50
51 thumbnail = self._html_search_meta('thumbnail', webpage, 'thumbnail', fatal=False)
52 if thumbnail:
53 thumbnail = re.sub(r'_[st]\.jpg$', '_x.jpg', thumbnail)
54
55 duration = int_or_none(self._search_regex(
56 [r'var\s+videoSeconds\s*=\s*(\d+)', r"'duration'\s*:\s*(\d+)"],
57 webpage, 'duration', fatal=False))
58
59 upload_date = unified_strdate(self._html_search_meta(
60 'last-modified', webpage, 'upload date', fatal=False))
61
62 return {
63 'id': video_id,
64 'title': title,
65 'description': description,
66 'thumbnail': thumbnail,
67 'duration': duration,
68 'upload_date': upload_date,
69 'formats': formats
70 }