2 from __future__
import unicode_literals
5 from .common
import InfoExtractor
6 from ..compat
import compat_str
14 class LineTVIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://tv\.line\.me/v/(?P<id>\d+)_[^/]+-(?P<segment>ep\d+-\d+)'
18 'url': 'https://tv.line.me/v/793123_goodbye-mrblack-ep1-1/list/69246',
22 'title': 'Goodbye Mr.Black | EP.1-1',
23 'thumbnail': r
're:^https?://.*\.jpg$',
28 'url': 'https://tv.line.me/v/2587507_%E6%B4%BE%E9%81%A3%E5%A5%B3%E9%86%ABx-ep1-02/list/185245',
29 'only_matching': True,
32 def _real_extract(self
, url
):
33 series_id
, segment
= self
._match
_valid
_url
(url
).groups()
34 video_id
= '%s_%s' % (series_id
, segment
)
36 webpage
= self
._download
_webpage
(url
, video_id
)
38 player_params
= self
._parse
_json
(self
._search
_regex
(
39 r
'naver\.WebPlayer\(({[^}]+})\)', webpage
, 'player parameters'),
40 video_id
, transform_source
=js_to_json
)
42 video_info
= self
._download
_json
(
43 'https://global-nvapis.line.me/linetv/rmcnmv/vod_play_videoInfo.json',
45 'videoId': player_params
['videoId'],
46 'key': player_params
['key'],
49 stream
= video_info
['streams'][0]
50 extra_query
= '?__gda__=' + stream
['key']['value']
51 formats
= self
._extract
_m
3u8_formats
(
52 stream
['source'] + extra_query
, video_id
, ext
='mp4',
53 entry_protocol
='m3u8_native', m3u8_id
='hls')
55 for a_format
in formats
:
56 a_format
['url'] += extra_query
59 for video
in video_info
.get('videos', {}).get('list', []):
60 encoding_option
= video
.get('encodingOption', {})
61 abr
= video
['bitrate']['audio']
62 vbr
= video
['bitrate']['video']
65 'url': video
['source'],
66 'format_id': 'http-%d' % int(tbr
),
67 'height': encoding_option
.get('height'),
68 'width': encoding_option
.get('width'),
71 'filesize': video
.get('size'),
73 if video
.get('duration') and duration
is None:
74 duration
= video
['duration']
76 self
._sort
_formats
(formats
)
78 if formats
and not formats
[0].get('width'):
79 formats
[0]['vcodec'] = 'none'
81 title
= self
._og
_search
_title
(webpage
)
83 # like_count requires an additional API request https://tv.line.me/api/likeit/getCount
89 'extra_param_to_segment_url': extra_query
[1:],
91 'thumbnails': [{'url': thumbnail['source']}
92 for thumbnail
in video_info
.get('thumbnails', {}).get('list', [])],
93 'view_count': video_info
.get('meta', {}).get('count'),
97 class LineLiveBaseIE(InfoExtractor
):
98 _API_BASE_URL
= 'https://live-api.line-apps.com/web/v4.0/channel/'
100 def _parse_broadcast_item(self
, item
):
101 broadcast_id
= compat_str(item
['id'])
102 title
= item
['title']
103 is_live
= item
.get('isBroadcastingNow')
106 for thumbnail_id
, thumbnail_url
in (item
.get('thumbnailURLs') or {}).items():
107 if not thumbnail_url
:
111 'url': thumbnail_url
,
114 channel
= item
.get('channel') or {}
115 channel_id
= str_or_none(channel
.get('id'))
119 'title': self
._live
_title
(title
) if is_live
else title
,
120 'thumbnails': thumbnails
,
121 'timestamp': int_or_none(item
.get('createdAt')),
122 'channel': channel
.get('name'),
123 'channel_id': channel_id
,
124 'channel_url': 'https://live.line.me/channels/' + channel_id
if channel_id
else None,
125 'duration': int_or_none(item
.get('archiveDuration')),
126 'view_count': int_or_none(item
.get('viewerCount')),
127 'comment_count': int_or_none(item
.get('chatCount')),
132 class LineLiveIE(LineLiveBaseIE
):
133 _VALID_URL
= r
'https?://live\.line\.me/channels/(?P<channel_id>\d+)/broadcast/(?P<id>\d+)'
135 'url': 'https://live.line.me/channels/4867368/broadcast/16331360',
136 'md5': 'bc931f26bf1d4f971e3b0982b3fab4a3',
139 'title': '振りコピ講座😙😙😙',
141 'timestamp': 1617095132,
142 'upload_date': '20210330',
144 'channel_id': '4867368',
146 'comment_count': int,
150 # archiveStatus == 'DELETED'
151 'url': 'https://live.line.me/channels/4778159/broadcast/16378488',
152 'only_matching': True,
155 def _real_extract(self
, url
):
156 channel_id
, broadcast_id
= self
._match
_valid
_url
(url
).groups()
157 broadcast
= self
._download
_json
(
158 self
._API
_BASE
_URL
+ '%s/broadcast/%s' % (channel_id
, broadcast_id
),
160 item
= broadcast
['item']
161 info
= self
._parse
_broadcast
_item
(item
)
162 protocol
= 'm3u8' if info
['is_live'] else 'm3u8_native'
164 for k
, v
in (broadcast
.get(('live' if info
['is_live'] else 'archived') + 'HLSURLs') or {}).items():
168 formats
.extend(self
._extract
_m
3u8_formats
(
169 v
, broadcast_id
, 'mp4', protocol
,
170 m3u8_id
='hls', fatal
=False))
174 'format_id': 'hls-' + k
,
175 'protocol': protocol
,
182 archive_status
= item
.get('archiveStatus')
183 if archive_status
!= 'ARCHIVED':
184 self
.raise_no_formats('this video has been ' + archive_status
.lower(), expected
=True)
185 self
._sort
_formats
(formats
)
186 info
['formats'] = formats
190 class LineLiveChannelIE(LineLiveBaseIE
):
191 _VALID_URL
= r
'https?://live\.line\.me/channels/(?P<id>\d+)(?!/broadcast/\d+)(?:[/?&#]|$)'
193 'url': 'https://live.line.me/channels/5893542',
197 'description': 'md5:c3a4af801f43b2fac0b02294976580be',
199 'playlist_mincount': 29
202 def _archived_broadcasts_entries(self
, archived_broadcasts
, channel_id
):
204 for row
in (archived_broadcasts
.get('rows') or []):
205 share_url
= str_or_none(row
.get('shareURL'))
208 info
= self
._parse
_broadcast
_item
(row
)
212 'ie_key': LineLiveIE
.ie_key(),
215 if not archived_broadcasts
.get('hasNextPage'):
217 archived_broadcasts
= self
._download
_json
(
218 self
._API
_BASE
_URL
+ channel_id
+ '/archived_broadcasts',
220 'lastId': info
['id'],
223 def _real_extract(self
, url
):
224 channel_id
= self
._match
_id
(url
)
225 channel
= self
._download
_json
(self
._API
_BASE
_URL
+ channel_id
, channel_id
)
226 return self
.playlist_result(
227 self
._archived
_broadcasts
_entries
(channel
.get('archivedBroadcasts') or {}, channel_id
),
228 channel_id
, channel
.get('title'), channel
.get('information'))