apa.py 2.8 KB

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