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.

83 lines
2.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_str
  5. from ..utils import (
  6. ExtractorError,
  7. int_or_none,
  8. try_get,
  9. unified_timestamp,
  10. )
  11. class FreshLiveIE(InfoExtractor):
  12. _VALID_URL = r'https?://freshlive\.tv/[^/]+/(?P<id>\d+)'
  13. _TEST = {
  14. 'url': 'https://freshlive.tv/satotv/74712',
  15. 'md5': '9f0cf5516979c4454ce982df3d97f352',
  16. 'info_dict': {
  17. 'id': '74712',
  18. 'ext': 'mp4',
  19. 'title': 'テスト',
  20. 'description': 'テスト',
  21. 'thumbnail': r're:^https?://.*\.jpg$',
  22. 'duration': 1511,
  23. 'timestamp': 1483619655,
  24. 'upload_date': '20170105',
  25. 'uploader': 'サトTV',
  26. 'uploader_id': 'satotv',
  27. 'view_count': int,
  28. 'comment_count': int,
  29. 'is_live': False,
  30. }
  31. }
  32. def _real_extract(self, url):
  33. video_id = self._match_id(url)
  34. webpage = self._download_webpage(url, video_id)
  35. options = self._parse_json(
  36. self._search_regex(
  37. r'window\.__CONTEXT__\s*=\s*({.+?});\s*</script>',
  38. webpage, 'initial context'),
  39. video_id)
  40. info = options['context']['dispatcher']['stores']['ProgramStore']['programs'][video_id]
  41. title = info['title']
  42. if info.get('status') == 'upcoming':
  43. raise ExtractorError('Stream %s is upcoming' % video_id, expected=True)
  44. stream_url = info.get('liveStreamUrl') or info['archiveStreamUrl']
  45. is_live = info.get('liveStreamUrl') is not None
  46. formats = self._extract_m3u8_formats(
  47. stream_url, video_id, 'mp4',
  48. 'm3u8_native', m3u8_id='hls')
  49. if is_live:
  50. title = self._live_title(title)
  51. return {
  52. 'id': video_id,
  53. 'formats': formats,
  54. 'title': title,
  55. 'description': info.get('description'),
  56. 'thumbnail': info.get('thumbnailUrl'),
  57. 'duration': int_or_none(info.get('airTime')),
  58. 'timestamp': unified_timestamp(info.get('createdAt')),
  59. 'uploader': try_get(
  60. info, lambda x: x['channel']['title'], compat_str),
  61. 'uploader_id': try_get(
  62. info, lambda x: x['channel']['code'], compat_str),
  63. 'uploader_url': try_get(
  64. info, lambda x: x['channel']['permalink'], compat_str),
  65. 'view_count': int_or_none(info.get('viewCount')),
  66. 'comment_count': int_or_none(info.get('commentCount')),
  67. 'tags': info.get('tags', []),
  68. 'is_live': is_live,
  69. }