2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_str
15 class LineTVIE(InfoExtractor
):
16 _VALID_URL
= r
'https?://tv\.line\.me/v/(?P<id>\d+)_[^/]+-(?P<segment>ep\d+-\d+)'
19 'url': 'https://tv.line.me/v/793123_goodbye-mrblack-ep1-1/list/69246',
23 'title': 'Goodbye Mr.Black | EP.1-1',
24 'thumbnail': r
're:^https?://.*\.jpg$',
29 'url': 'https://tv.line.me/v/2587507_%E6%B4%BE%E9%81%A3%E5%A5%B3%E9%86%ABx-ep1-02/list/185245',
30 'only_matching': True,
33 def _real_extract(self
, url
):
34 series_id
, segment
= re
.match(self
._VALID
_URL
, url
).groups()
35 video_id
= '%s_%s' % (series_id
, segment
)
37 webpage
= self
._download
_webpage
(url
, video_id
)
39 player_params
= self
._parse
_json
(self
._search
_regex
(
40 r
'naver\.WebPlayer\(({[^}]+})\)', webpage
, 'player parameters'),
41 video_id
, transform_source
=js_to_json
)
43 video_info
= self
._download
_json
(
44 'https://global-nvapis.line.me/linetv/rmcnmv/vod_play_videoInfo.json',
46 'videoId': player_params
['videoId'],
47 'key': player_params
['key'],
50 stream
= video_info
['streams'][0]
51 extra_query
= '?__gda__=' + stream
['key']['value']
52 formats
= self
._extract
_m
3u8_formats
(
53 stream
['source'] + extra_query
, video_id
, ext
='mp4',
54 entry_protocol
='m3u8_native', m3u8_id
='hls')
56 for a_format
in formats
:
57 a_format
['url'] += extra_query
60 for video
in video_info
.get('videos', {}).get('list', []):
61 encoding_option
= video
.get('encodingOption', {})
62 abr
= video
['bitrate']['audio']
63 vbr
= video
['bitrate']['video']
66 'url': video
['source'],
67 'format_id': 'http-%d' % int(tbr
),
68 'height': encoding_option
.get('height'),
69 'width': encoding_option
.get('width'),
72 'filesize': video
.get('size'),
74 if video
.get('duration') and duration
is None:
75 duration
= video
['duration']
77 self
._sort
_formats
(formats
)
79 if formats
and not formats
[0].get('width'):
80 formats
[0]['vcodec'] = 'none'
82 title
= self
._og
_search
_title
(webpage
)
84 # like_count requires an additional API request https://tv.line.me/api/likeit/getCount
90 'extra_param_to_segment_url': extra_query
[1:],
92 'thumbnails': [{'url': thumbnail['source']}
93 for thumbnail
in video_info
.get('thumbnails', {}).get('list', [])],
94 'view_count': video_info
.get('meta', {}).get('count'),
98 class LineLiveBaseIE(InfoExtractor
):
99 _API_BASE_URL
= 'https://live-api.line-apps.com/web/v4.0/channel/'
101 def _parse_broadcast_item(self
, item
):
102 broadcast_id
= compat_str(item
['id'])
103 title
= item
['title']
104 is_live
= item
.get('isBroadcastingNow')
107 for thumbnail_id
, thumbnail_url
in (item
.get('thumbnailURLs') or {}).items():
108 if not thumbnail_url
:
112 'url': thumbnail_url
,
115 channel
= item
.get('channel') or {}
116 channel_id
= str_or_none(channel
.get('id'))
120 'title': self
._live
_title
(title
) if is_live
else title
,
121 'thumbnails': thumbnails
,
122 'timestamp': int_or_none(item
.get('createdAt')),
123 'channel': channel
.get('name'),
124 'channel_id': channel_id
,
125 'channel_url': 'https://live.line.me/channels/' + channel_id
if channel_id
else None,
126 'duration': int_or_none(item
.get('archiveDuration')),
127 'view_count': int_or_none(item
.get('viewerCount')),
128 'comment_count': int_or_none(item
.get('chatCount')),
133 class LineLiveIE(LineLiveBaseIE
):
134 _VALID_URL
= r
'https?://live\.line\.me/channels/(?P<channel_id>\d+)/broadcast/(?P<id>\d+)'
136 'url': 'https://live.line.me/channels/4867368/broadcast/16331360',
137 'md5': 'bc931f26bf1d4f971e3b0982b3fab4a3',
140 'title': '振りコピ講座😙😙😙',
142 'timestamp': 1617095132,
143 'upload_date': '20210330',
145 'channel_id': '4867368',
147 'comment_count': int,
151 # archiveStatus == 'DELETED'
152 'url': 'https://live.line.me/channels/4778159/broadcast/16378488',
153 'only_matching': True,
156 def _real_extract(self
, url
):
157 channel_id
, broadcast_id
= re
.match(self
._VALID
_URL
, url
).groups()
158 broadcast
= self
._download
_json
(
159 self
._API
_BASE
_URL
+ '%s/broadcast/%s' % (channel_id
, broadcast_id
),
161 item
= broadcast
['item']
162 info
= self
._parse
_broadcast
_item
(item
)
163 protocol
= 'm3u8' if info
['is_live'] else 'm3u8_native'
165 for k
, v
in (broadcast
.get(('live' if info
['is_live'] else 'archived') + 'HLSURLs') or {}).items():
169 formats
.extend(self
._extract
_m
3u8_formats
(
170 v
, broadcast_id
, 'mp4', protocol
,
171 m3u8_id
='hls', fatal
=False))
175 'format_id': 'hls-' + k
,
176 'protocol': protocol
,
183 archive_status
= item
.get('archiveStatus')
184 if archive_status
!= 'ARCHIVED':
185 self
.raise_no_formats('this video has been ' + archive_status
.lower(), expected
=True)
186 self
._sort
_formats
(formats
)
187 info
['formats'] = formats
191 class LineLiveChannelIE(LineLiveBaseIE
):
192 _VALID_URL
= r
'https?://live\.line\.me/channels/(?P<id>\d+)(?!/broadcast/\d+)(?:[/?&#]|$)'
194 'url': 'https://live.line.me/channels/5893542',
198 'description': 'md5:c3a4af801f43b2fac0b02294976580be',
200 'playlist_mincount': 29
203 def _archived_broadcasts_entries(self
, archived_broadcasts
, channel_id
):
205 for row
in (archived_broadcasts
.get('rows') or []):
206 share_url
= str_or_none(row
.get('shareURL'))
209 info
= self
._parse
_broadcast
_item
(row
)
213 'ie_key': LineLiveIE
.ie_key(),
216 if not archived_broadcasts
.get('hasNextPage'):
218 archived_broadcasts
= self
._download
_json
(
219 self
._API
_BASE
_URL
+ channel_id
+ '/archived_broadcasts',
221 'lastId': info
['id'],
224 def _real_extract(self
, url
):
225 channel_id
= self
._match
_id
(url
)
226 channel
= self
._download
_json
(self
._API
_BASE
_URL
+ channel_id
, channel_id
)
227 return self
.playlist_result(
228 self
._archived
_broadcasts
_entries
(channel
.get('archivedBroadcasts') or {}, channel_id
),
229 channel_id
, channel
.get('title'), channel
.get('information'))