You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
3.1 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. determine_ext,
  7. js_to_json,
  8. url_or_none,
  9. )
  10. class APAIE(InfoExtractor):
  11. _VALID_URL = r'https?://[^/]+\.apa\.at/embed/(?P<id>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})'
  12. _TESTS = [{
  13. 'url': 'http://uvp.apa.at/embed/293f6d17-692a-44e3-9fd5-7b178f3a1029',
  14. 'md5': '2b12292faeb0a7d930c778c7a5b4759b',
  15. 'info_dict': {
  16. 'id': 'jjv85FdZ',
  17. 'ext': 'mp4',
  18. 'title': '"Blau ist mysteriös": Die Blue Man Group im Interview',
  19. 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
  20. 'thumbnail': r're:^https?://.*\.jpg$',
  21. 'duration': 254,
  22. 'timestamp': 1519211149,
  23. 'upload_date': '20180221',
  24. },
  25. }, {
  26. 'url': 'https://uvp-apapublisher.sf.apa.at/embed/2f94e9e6-d945-4db2-9548-f9a41ebf7b78',
  27. 'only_matching': True,
  28. }, {
  29. 'url': 'http://uvp-rma.sf.apa.at/embed/70404cca-2f47-4855-bbb8-20b1fae58f76',
  30. 'only_matching': True,
  31. }, {
  32. 'url': 'http://uvp-kleinezeitung.sf.apa.at/embed/f1c44979-dba2-4ebf-b021-e4cf2cac3c81',
  33. 'only_matching': True,
  34. }]
  35. @staticmethod
  36. def _extract_urls(webpage):
  37. return [
  38. mobj.group('url')
  39. for mobj in re.finditer(
  40. 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',
  41. webpage)]
  42. def _real_extract(self, url):
  43. video_id = self._match_id(url)
  44. webpage = self._download_webpage(url, video_id)
  45. jwplatform_id = self._search_regex(
  46. r'media[iI]d\s*:\s*["\'](?P<id>[a-zA-Z0-9]{8})', webpage,
  47. 'jwplatform id', default=None)
  48. if jwplatform_id:
  49. return self.url_result(
  50. 'jwplatform:' + jwplatform_id, ie='JWPlatform',
  51. video_id=video_id)
  52. sources = self._parse_json(
  53. self._search_regex(
  54. r'sources\s*=\s*(\[.+?\])\s*;', webpage, 'sources'),
  55. video_id, transform_source=js_to_json)
  56. formats = []
  57. for source in sources:
  58. if not isinstance(source, dict):
  59. continue
  60. source_url = url_or_none(source.get('file'))
  61. if not source_url:
  62. continue
  63. ext = determine_ext(source_url)
  64. if ext == 'm3u8':
  65. formats.extend(self._extract_m3u8_formats(
  66. source_url, video_id, 'mp4', entry_protocol='m3u8_native',
  67. m3u8_id='hls', fatal=False))
  68. else:
  69. formats.append({
  70. 'url': source_url,
  71. })
  72. self._sort_formats(formats)
  73. thumbnail = self._search_regex(
  74. r'image\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
  75. 'thumbnail', fatal=False, group='url')
  76. return {
  77. 'id': video_id,
  78. 'title': video_id,
  79. 'thumbnail': thumbnail,
  80. 'formats': formats,
  81. }