]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/esri.py
[ie/box] Fix formats extraction (#8649)
[yt-dlp.git] / yt_dlp / extractor / esri.py
CommitLineData
8b8c1093
SW
1import re
2
3from .common import InfoExtractor
3aa697f9 4from ..compat import compat_urlparse
8b8c1093 5from ..utils import (
3aa697f9
S
6 int_or_none,
7 parse_filesize,
8 unified_strdate,
8b8c1093
SW
9)
10
11
9c21f229 12class EsriVideoIE(InfoExtractor):
8b8c1093
SW
13 _VALID_URL = r'https?://video\.esri\.com/watch/(?P<id>[0-9]+)'
14 _TEST = {
3aa697f9
S
15 'url': 'https://video.esri.com/watch/1124/arcgis-online-_dash_-developing-applications',
16 'md5': 'd4aaf1408b221f1b38227a9bbaeb95bc',
8b8c1093 17 'info_dict': {
3aa697f9 18 'id': '1124',
8b8c1093 19 'ext': 'mp4',
3aa697f9
S
20 'title': 'ArcGIS Online - Developing Applications',
21 'description': 'Jeremy Bartley demonstrates how to develop applications with ArcGIS Online.',
ec85ded8 22 'thumbnail': r're:^https?://.*\.jpg$',
3aa697f9
S
23 'duration': 185,
24 'upload_date': '20120419',
8b8c1093
SW
25 }
26 }
27
28 def _real_extract(self, url):
29 video_id = self._match_id(url)
8b8c1093 30
3aa697f9 31 webpage = self._download_webpage(url, video_id)
8b8c1093 32
3aa697f9
S
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 })
3aa697f9
S
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)
8b8c1093 54
3aa697f9
S
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))
8b8c1093 58
3aa697f9 59 upload_date = unified_strdate(self._html_search_meta(
62bdc9fe 60 'last-modified', webpage, 'upload date', fatal=False))
8b8c1093 61
3aa697f9 62 return {
8b8c1093
SW
63 'id': video_id,
64 'title': title,
3aa697f9
S
65 'description': description,
66 'thumbnail': thumbnail,
67 'duration': duration,
8b8c1093 68 'upload_date': upload_date,
3aa697f9 69 'formats': formats
8b8c1093 70 }