apa.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. determine_ext,
  4. int_or_none,
  5. url_or_none,
  6. )
  7. class APAIE(InfoExtractor):
  8. _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})'
  9. _EMBED_REGEX = [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']
  10. _TESTS = [{
  11. 'url': 'http://uvp.apa.at/embed/293f6d17-692a-44e3-9fd5-7b178f3a1029',
  12. 'md5': '2b12292faeb0a7d930c778c7a5b4759b',
  13. 'info_dict': {
  14. 'id': '293f6d17-692a-44e3-9fd5-7b178f3a1029',
  15. 'ext': 'mp4',
  16. 'title': '293f6d17-692a-44e3-9fd5-7b178f3a1029',
  17. 'thumbnail': r're:^https?://.*\.jpg$',
  18. },
  19. }, {
  20. 'url': 'https://uvp-apapublisher.sf.apa.at/embed/2f94e9e6-d945-4db2-9548-f9a41ebf7b78',
  21. 'only_matching': True,
  22. }, {
  23. 'url': 'http://uvp-rma.sf.apa.at/embed/70404cca-2f47-4855-bbb8-20b1fae58f76',
  24. 'only_matching': True,
  25. }, {
  26. 'url': 'http://uvp-kleinezeitung.sf.apa.at/embed/f1c44979-dba2-4ebf-b021-e4cf2cac3c81',
  27. 'only_matching': True,
  28. }]
  29. def _real_extract(self, url):
  30. mobj = self._match_valid_url(url)
  31. video_id, base_url = mobj.group('id', 'base_url')
  32. webpage = self._download_webpage(
  33. f'{base_url}/player/{video_id}', video_id)
  34. jwplatform_id = self._search_regex(
  35. r'media[iI]d\s*:\s*["\'](?P<id>[a-zA-Z0-9]{8})', webpage,
  36. 'jwplatform id', default=None)
  37. if jwplatform_id:
  38. return self.url_result(
  39. 'jwplatform:' + jwplatform_id, ie='JWPlatform',
  40. video_id=video_id)
  41. def extract(field, name=None):
  42. return self._search_regex(
  43. rf'\b{field}["\']\s*:\s*(["\'])(?P<value>(?:(?!\1).)+)\1',
  44. webpage, name or field, default=None, group='value')
  45. title = extract('title') or video_id
  46. description = extract('description')
  47. thumbnail = extract('poster', 'thumbnail')
  48. formats = []
  49. for format_id in ('hls', 'progressive'):
  50. source_url = url_or_none(extract(format_id))
  51. if not source_url:
  52. continue
  53. ext = determine_ext(source_url)
  54. if ext == 'm3u8':
  55. formats.extend(self._extract_m3u8_formats(
  56. source_url, video_id, 'mp4', entry_protocol='m3u8_native',
  57. m3u8_id='hls', fatal=False))
  58. else:
  59. height = int_or_none(self._search_regex(
  60. r'(\d+)\.mp4', source_url, 'height', default=None))
  61. formats.append({
  62. 'url': source_url,
  63. 'format_id': format_id,
  64. 'height': height,
  65. })
  66. return {
  67. 'id': video_id,
  68. 'title': title,
  69. 'description': description,
  70. 'thumbnail': thumbnail,
  71. 'formats': formats,
  72. }