piaulizaportal.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. int_or_none,
  5. parse_qs,
  6. time_seconds,
  7. traverse_obj,
  8. )
  9. class PIAULIZAPortalIE(InfoExtractor):
  10. IE_DESC = 'ulizaportal.jp - PIA LIVE STREAM'
  11. _VALID_URL = r'https?://(?:www\.)?ulizaportal\.jp/pages/(?P<id>[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12})'
  12. _TESTS = [{
  13. 'url': 'https://ulizaportal.jp/pages/005f18b7-e810-5618-cb82-0987c5755d44',
  14. 'info_dict': {
  15. 'id': '005f18b7-e810-5618-cb82-0987c5755d44',
  16. 'title': 'プレゼンテーションプレイヤーのサンプル',
  17. 'live_status': 'not_live',
  18. },
  19. 'params': {
  20. 'skip_download': True,
  21. 'ignore_no_formats_error': True,
  22. },
  23. }, {
  24. 'url': 'https://ulizaportal.jp/pages/005e1b23-fe93-5780-19a0-98e917cc4b7d?expires=4102412400&signature=f422a993b683e1068f946caf406d211c17d1ef17da8bef3df4a519502155aa91&version=1',
  25. 'info_dict': {
  26. 'id': '005e1b23-fe93-5780-19a0-98e917cc4b7d',
  27. 'title': '【確認用】視聴サンプルページ(ULIZA)',
  28. 'live_status': 'not_live',
  29. },
  30. 'params': {
  31. 'skip_download': True,
  32. 'ignore_no_formats_error': True,
  33. },
  34. }]
  35. def _real_extract(self, url):
  36. video_id = self._match_id(url)
  37. expires = int_or_none(traverse_obj(parse_qs(url), ('expires', 0)))
  38. if expires and expires <= time_seconds():
  39. raise ExtractorError('The link is expired.', video_id=video_id, expected=True)
  40. webpage = self._download_webpage(url, video_id)
  41. player_data = self._download_webpage(
  42. self._search_regex(
  43. r'<script [^>]*\bsrc="(https://player-api\.p\.uliza\.jp/v1/players/[^"]+)"',
  44. webpage, 'player data url'),
  45. video_id, headers={'Referer': 'https://ulizaportal.jp/'},
  46. note='Fetching player data', errnote='Unable to fetch player data')
  47. formats = self._extract_m3u8_formats(
  48. self._search_regex(
  49. r'["\'](https://vms-api\.p\.uliza\.jp/v1/prog-index\.m3u8[^"\']+)', player_data,
  50. 'm3u8 url', default=None),
  51. video_id, fatal=False)
  52. m3u8_type = self._search_regex(
  53. r'/hls/(dvr|video)/', traverse_obj(formats, (0, 'url')), 'm3u8 type', default=None)
  54. return {
  55. 'id': video_id,
  56. 'title': self._html_extract_title(webpage),
  57. 'formats': formats,
  58. 'live_status': {
  59. 'video': 'is_live',
  60. 'dvr': 'was_live', # short-term archives
  61. }.get(m3u8_type, 'not_live'), # VOD or long-term archives
  62. }