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.

90 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 js_to_json
  6. class LineTVIE(InfoExtractor):
  7. _VALID_URL = r'https?://tv\.line\.me/v/(?P<id>\d+)_[^/]+-(?P<segment>ep\d+-\d+)'
  8. _TESTS = [{
  9. 'url': 'https://tv.line.me/v/793123_goodbye-mrblack-ep1-1/list/69246',
  10. 'info_dict': {
  11. 'id': '793123_ep1-1',
  12. 'ext': 'mp4',
  13. 'title': 'Goodbye Mr.Black | EP.1-1',
  14. 'thumbnail': r're:^https?://.*\.jpg$',
  15. 'duration': 998.509,
  16. 'view_count': int,
  17. },
  18. }, {
  19. 'url': 'https://tv.line.me/v/2587507_%E6%B4%BE%E9%81%A3%E5%A5%B3%E9%86%ABx-ep1-02/list/185245',
  20. 'only_matching': True,
  21. }]
  22. def _real_extract(self, url):
  23. series_id, segment = re.match(self._VALID_URL, url).groups()
  24. video_id = '%s_%s' % (series_id, segment)
  25. webpage = self._download_webpage(url, video_id)
  26. player_params = self._parse_json(self._search_regex(
  27. r'naver\.WebPlayer\(({[^}]+})\)', webpage, 'player parameters'),
  28. video_id, transform_source=js_to_json)
  29. video_info = self._download_json(
  30. 'https://global-nvapis.line.me/linetv/rmcnmv/vod_play_videoInfo.json',
  31. video_id, query={
  32. 'videoId': player_params['videoId'],
  33. 'key': player_params['key'],
  34. })
  35. stream = video_info['streams'][0]
  36. extra_query = '?__gda__=' + stream['key']['value']
  37. formats = self._extract_m3u8_formats(
  38. stream['source'] + extra_query, video_id, ext='mp4',
  39. entry_protocol='m3u8_native', m3u8_id='hls')
  40. for a_format in formats:
  41. a_format['url'] += extra_query
  42. duration = None
  43. for video in video_info.get('videos', {}).get('list', []):
  44. encoding_option = video.get('encodingOption', {})
  45. abr = video['bitrate']['audio']
  46. vbr = video['bitrate']['video']
  47. tbr = abr + vbr
  48. formats.append({
  49. 'url': video['source'],
  50. 'format_id': 'http-%d' % int(tbr),
  51. 'height': encoding_option.get('height'),
  52. 'width': encoding_option.get('width'),
  53. 'abr': abr,
  54. 'vbr': vbr,
  55. 'filesize': video.get('size'),
  56. })
  57. if video.get('duration') and duration is None:
  58. duration = video['duration']
  59. self._sort_formats(formats)
  60. if not formats[0].get('width'):
  61. formats[0]['vcodec'] = 'none'
  62. title = self._og_search_title(webpage)
  63. # like_count requires an additional API request https://tv.line.me/api/likeit/getCount
  64. return {
  65. 'id': video_id,
  66. 'title': title,
  67. 'formats': formats,
  68. 'extra_param_to_segment_url': extra_query[1:],
  69. 'duration': duration,
  70. 'thumbnails': [{'url': thumbnail['source']}
  71. for thumbnail in video_info.get('thumbnails', {}).get('list', [])],
  72. 'view_count': video_info.get('meta', {}).get('count'),
  73. }