2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_str
16 class LineTVIE(InfoExtractor
):
17 _VALID_URL
= r
'https?://tv\.line\.me/v/(?P<id>\d+)_[^/]+-(?P<segment>ep\d+-\d+)'
20 'url': 'https://tv.line.me/v/793123_goodbye-mrblack-ep1-1/list/69246',
24 'title': 'Goodbye Mr.Black | EP.1-1',
25 'thumbnail': r
're:^https?://.*\.jpg$',
30 'url': 'https://tv.line.me/v/2587507_%E6%B4%BE%E9%81%A3%E5%A5%B3%E9%86%ABx-ep1-02/list/185245',
31 'only_matching': True,
34 def _real_extract(self
, url
):
35 series_id
, segment
= re
.match(self
._VALID
_URL
, url
).groups()
36 video_id
= '%s_%s' % (series_id
, segment
)
38 webpage
= self
._download
_webpage
(url
, video_id
)
40 player_params
= self
._parse
_json
(self
._search
_regex
(
41 r
'naver\.WebPlayer\(({[^}]+})\)', webpage
, 'player parameters'),
42 video_id
, transform_source
=js_to_json
)
44 video_info
= self
._download
_json
(
45 'https://global-nvapis.line.me/linetv/rmcnmv/vod_play_videoInfo.json',
47 'videoId': player_params
['videoId'],
48 'key': player_params
['key'],
51 stream
= video_info
['streams'][0]
52 extra_query
= '?__gda__=' + stream
['key']['value']
53 formats
= self
._extract
_m
3u8_formats
(
54 stream
['source'] + extra_query
, video_id
, ext
='mp4',
55 entry_protocol
='m3u8_native', m3u8_id
='hls')
57 for a_format
in formats
:
58 a_format
['url'] += extra_query
61 for video
in video_info
.get('videos', {}).get('list', []):
62 encoding_option
= video
.get('encodingOption', {})
63 abr
= video
['bitrate']['audio']
64 vbr
= video
['bitrate']['video']
67 'url': video
['source'],
68 'format_id': 'http-%d' % int(tbr
),
69 'height': encoding_option
.get('height'),
70 'width': encoding_option
.get('width'),
73 'filesize': video
.get('size'),
75 if video
.get('duration') and duration
is None:
76 duration
= video
['duration']
78 self
._sort
_formats
(formats
)
80 if not formats
[0].get('width'):
81 formats
[0]['vcodec'] = 'none'
83 title
= self
._og
_search
_title
(webpage
)
85 # like_count requires an additional API request https://tv.line.me/api/likeit/getCount
91 'extra_param_to_segment_url': extra_query
[1:],
93 'thumbnails': [{'url': thumbnail['source']}
94 for thumbnail
in video_info
.get('thumbnails', {}).get('list', [])],
95 'view_count': video_info
.get('meta', {}).get('count'),
99 class LineLiveBaseIE(InfoExtractor
):
100 _API_BASE_URL
= 'https://live-api.line-apps.com/web/v4.0/channel/'
102 def _parse_broadcast_item(self
, item
):
103 broadcast_id
= compat_str(item
['id'])
104 title
= item
['title']
105 is_live
= item
.get('isBroadcastingNow')
108 for thumbnail_id
, thumbnail_url
in (item
.get('thumbnailURLs') or {}).items():
109 if not thumbnail_url
:
113 'url': thumbnail_url
,
116 channel
= item
.get('channel') or {}
117 channel_id
= str_or_none(channel
.get('id'))
121 'title': self
._live
_title
(title
) if is_live
else title
,
122 'thumbnails': thumbnails
,
123 'timestamp': int_or_none(item
.get('createdAt')),
124 'channel': channel
.get('name'),
125 'channel_id': channel_id
,
126 'channel_url': 'https://live.line.me/channels/' + channel_id
if channel_id
else None,
127 'duration': int_or_none(item
.get('archiveDuration')),
128 'view_count': int_or_none(item
.get('viewerCount')),
129 'comment_count': int_or_none(item
.get('chatCount')),
134 class LineLiveIE(LineLiveBaseIE
):
135 _VALID_URL
= r
'https?://live\.line\.me/channels/(?P<channel_id>\d+)/broadcast/(?P<id>\d+)'
137 'url': 'https://live.line.me/channels/4867368/broadcast/16331360',
138 'md5': 'bc931f26bf1d4f971e3b0982b3fab4a3',
141 'title': '振りコピ講座😙😙😙',
143 'timestamp': 1617095132,
144 'upload_date': '20210330',
146 'channel_id': '4867368',
148 'comment_count': int,
152 # archiveStatus == 'DELETED'
153 'url': 'https://live.line.me/channels/4778159/broadcast/16378488',
154 'only_matching': True,
157 def _real_extract(self
, url
):
158 channel_id
, broadcast_id
= re
.match(self
._VALID
_URL
, url
).groups()
159 broadcast
= self
._download
_json
(
160 self
._API
_BASE
_URL
+ '%s/broadcast/%s' % (channel_id
, broadcast_id
),
162 item
= broadcast
['item']
163 info
= self
._parse
_broadcast
_item
(item
)
164 protocol
= 'm3u8' if info
['is_live'] else 'm3u8_native'
166 for k
, v
in (broadcast
.get(('live' if info
['is_live'] else 'archived') + 'HLSURLs') or {}).items():
170 formats
.extend(self
._extract
_m
3u8_formats
(
171 v
, broadcast_id
, 'mp4', protocol
,
172 m3u8_id
='hls', fatal
=False))
176 'format_id': 'hls-' + k
,
177 'protocol': protocol
,
184 archive_status
= item
.get('archiveStatus')
185 if archive_status
!= 'ARCHIVED':
186 raise ExtractorError('this video has been ' + archive_status
.lower(), expected
=True)
187 self
._sort
_formats
(formats
)
188 info
['formats'] = formats
192 class LineLiveChannelIE(LineLiveBaseIE
):
193 _VALID_URL
= r
'https?://live\.line\.me/channels/(?P<id>\d+)(?!/broadcast/\d+)(?:[/?&#]|$)'
195 'url': 'https://live.line.me/channels/5893542',
199 'description': 'md5:c3a4af801f43b2fac0b02294976580be',
201 'playlist_mincount': 29
204 def _archived_broadcasts_entries(self
, archived_broadcasts
, channel_id
):
206 for row
in (archived_broadcasts
.get('rows') or []):
207 share_url
= str_or_none(row
.get('shareURL'))
210 info
= self
._parse
_broadcast
_item
(row
)
214 'ie_key': LineLiveIE
.ie_key(),
217 if not archived_broadcasts
.get('hasNextPage'):
219 archived_broadcasts
= self
._download
_json
(
220 self
._API
_BASE
_URL
+ channel_id
+ '/archived_broadcasts',
222 'lastId': info
['id'],
225 def _real_extract(self
, url
):
226 channel_id
= self
._match
_id
(url
)
227 channel
= self
._download
_json
(self
._API
_BASE
_URL
+ channel_id
, channel_id
)
228 return self
.playlist_result(
229 self
._archived
_broadcasts
_entries
(channel
.get('archivedBroadcasts') or {}, channel_id
),
230 channel_id
, channel
.get('title'), channel
.get('information'))