]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/apa.py
[extractor] Use classmethod/property where possible
[yt-dlp.git] / yt_dlp / extractor / apa.py
CommitLineData
cfd7f2a6
S
1import re
2
3from .common import InfoExtractor
cfd7f2a6
S
4from ..utils import (
5 determine_ext,
7c60c33e 6 int_or_none,
3052a30d 7 url_or_none,
cfd7f2a6
S
8)
9
10
11class APAIE(InfoExtractor):
7c60c33e 12 _VALID_URL = r'(?P<base_url>https?://[^/]+\.apa\.at)/embed/(?P<id>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})'
cfd7f2a6
S
13 _TESTS = [{
14 'url': 'http://uvp.apa.at/embed/293f6d17-692a-44e3-9fd5-7b178f3a1029',
15 'md5': '2b12292faeb0a7d930c778c7a5b4759b',
16 'info_dict': {
7c60c33e 17 'id': '293f6d17-692a-44e3-9fd5-7b178f3a1029',
cfd7f2a6 18 'ext': 'mp4',
7c60c33e 19 'title': '293f6d17-692a-44e3-9fd5-7b178f3a1029',
cfd7f2a6 20 'thumbnail': r're:^https?://.*\.jpg$',
cfd7f2a6
S
21 },
22 }, {
23 'url': 'https://uvp-apapublisher.sf.apa.at/embed/2f94e9e6-d945-4db2-9548-f9a41ebf7b78',
24 'only_matching': True,
25 }, {
26 'url': 'http://uvp-rma.sf.apa.at/embed/70404cca-2f47-4855-bbb8-20b1fae58f76',
27 'only_matching': True,
28 }, {
29 'url': 'http://uvp-kleinezeitung.sf.apa.at/embed/f1c44979-dba2-4ebf-b021-e4cf2cac3c81',
30 'only_matching': True,
31 }]
32
33 @staticmethod
34 def _extract_urls(webpage):
35 return [
36 mobj.group('url')
37 for mobj in re.finditer(
38 r'<iframe[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//[^/]+\.apa\.at/embed/[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}.*?)\1',
39 webpage)]
40
41 def _real_extract(self, url):
5ad28e7f 42 mobj = self._match_valid_url(url)
7c60c33e 43 video_id, base_url = mobj.group('id', 'base_url')
cfd7f2a6 44
7c60c33e 45 webpage = self._download_webpage(
46 '%s/player/%s' % (base_url, video_id), video_id)
cfd7f2a6
S
47
48 jwplatform_id = self._search_regex(
49 r'media[iI]d\s*:\s*["\'](?P<id>[a-zA-Z0-9]{8})', webpage,
50 'jwplatform id', default=None)
51
52 if jwplatform_id:
53 return self.url_result(
54 'jwplatform:' + jwplatform_id, ie='JWPlatform',
55 video_id=video_id)
56
7c60c33e 57 def extract(field, name=None):
58 return self._search_regex(
59 r'\b%s["\']\s*:\s*(["\'])(?P<value>(?:(?!\1).)+)\1' % field,
60 webpage, name or field, default=None, group='value')
61
62 title = extract('title') or video_id
63 description = extract('description')
64 thumbnail = extract('poster', 'thumbnail')
cfd7f2a6
S
65
66 formats = []
7c60c33e 67 for format_id in ('hls', 'progressive'):
68 source_url = url_or_none(extract(format_id))
3052a30d 69 if not source_url:
cfd7f2a6
S
70 continue
71 ext = determine_ext(source_url)
72 if ext == 'm3u8':
73 formats.extend(self._extract_m3u8_formats(
74 source_url, video_id, 'mp4', entry_protocol='m3u8_native',
75 m3u8_id='hls', fatal=False))
76 else:
7c60c33e 77 height = int_or_none(self._search_regex(
78 r'(\d+)\.mp4', source_url, 'height', default=None))
cfd7f2a6
S
79 formats.append({
80 'url': source_url,
7c60c33e 81 'format_id': format_id,
82 'height': height,
cfd7f2a6
S
83 })
84 self._sort_formats(formats)
85
cfd7f2a6
S
86 return {
87 'id': video_id,
7c60c33e 88 'title': title,
89 'description': description,
cfd7f2a6
S
90 'thumbnail': thumbnail,
91 'formats': formats,
92 }