]>
Commit | Line | Data |
---|---|---|
08250b69 | 1 | from .common import InfoExtractor |
f7ad7160 | 2 | from ..compat import compat_str |
3 | from ..utils import ( | |
e0ddbd02 | 4 | format_field, |
f7ad7160 | 5 | int_or_none, |
f7ad7160 | 6 | str_or_none, |
7 | ) | |
08250b69 CHY |
8 | |
9 | ||
f7ad7160 | 10 | class LineLiveBaseIE(InfoExtractor): |
11 | _API_BASE_URL = 'https://live-api.line-apps.com/web/v4.0/channel/' | |
12 | ||
13 | def _parse_broadcast_item(self, item): | |
14 | broadcast_id = compat_str(item['id']) | |
15 | title = item['title'] | |
16 | is_live = item.get('isBroadcastingNow') | |
17 | ||
18 | thumbnails = [] | |
19 | for thumbnail_id, thumbnail_url in (item.get('thumbnailURLs') or {}).items(): | |
20 | if not thumbnail_url: | |
21 | continue | |
22 | thumbnails.append({ | |
23 | 'id': thumbnail_id, | |
24 | 'url': thumbnail_url, | |
25 | }) | |
26 | ||
27 | channel = item.get('channel') or {} | |
28 | channel_id = str_or_none(channel.get('id')) | |
29 | ||
30 | return { | |
31 | 'id': broadcast_id, | |
39ca3b5c | 32 | 'title': title, |
f7ad7160 | 33 | 'thumbnails': thumbnails, |
34 | 'timestamp': int_or_none(item.get('createdAt')), | |
35 | 'channel': channel.get('name'), | |
36 | 'channel_id': channel_id, | |
a70635b8 | 37 | 'channel_url': format_field(channel_id, None, 'https://live.line.me/channels/%s'), |
f7ad7160 | 38 | 'duration': int_or_none(item.get('archiveDuration')), |
39 | 'view_count': int_or_none(item.get('viewerCount')), | |
40 | 'comment_count': int_or_none(item.get('chatCount')), | |
41 | 'is_live': is_live, | |
42 | } | |
43 | ||
44 | ||
45 | class LineLiveIE(LineLiveBaseIE): | |
46 | _VALID_URL = r'https?://live\.line\.me/channels/(?P<channel_id>\d+)/broadcast/(?P<id>\d+)' | |
47 | _TESTS = [{ | |
935f5a42 | 48 | 'url': 'https://live.line.me/channels/5833718/broadcast/18373277', |
49 | 'md5': '2c15843b8cb3acd55009ddcb2db91f7c', | |
f7ad7160 | 50 | 'info_dict': { |
935f5a42 | 51 | 'id': '18373277', |
52 | 'title': '2021/12/05 (15分犬)定例譲渡会🐶', | |
f7ad7160 | 53 | 'ext': 'mp4', |
935f5a42 | 54 | 'timestamp': 1638674925, |
55 | 'upload_date': '20211205', | |
56 | 'thumbnail': 'md5:e1f5817e60f4a72b7e43377cf308d7ef', | |
57 | 'channel_url': 'https://live.line.me/channels/5833718', | |
58 | 'channel': 'Yahooニュース掲載🗞プロフ見てね🐕🐕', | |
59 | 'channel_id': '5833718', | |
60 | 'duration': 937, | |
f7ad7160 | 61 | 'view_count': int, |
62 | 'comment_count': int, | |
63 | 'is_live': False, | |
64 | } | |
65 | }, { | |
66 | # archiveStatus == 'DELETED' | |
67 | 'url': 'https://live.line.me/channels/4778159/broadcast/16378488', | |
68 | 'only_matching': True, | |
69 | }] | |
70 | ||
71 | def _real_extract(self, url): | |
5ad28e7f | 72 | channel_id, broadcast_id = self._match_valid_url(url).groups() |
f7ad7160 | 73 | broadcast = self._download_json( |
74 | self._API_BASE_URL + '%s/broadcast/%s' % (channel_id, broadcast_id), | |
75 | broadcast_id) | |
76 | item = broadcast['item'] | |
77 | info = self._parse_broadcast_item(item) | |
78 | protocol = 'm3u8' if info['is_live'] else 'm3u8_native' | |
79 | formats = [] | |
80 | for k, v in (broadcast.get(('live' if info['is_live'] else 'archived') + 'HLSURLs') or {}).items(): | |
81 | if not v: | |
82 | continue | |
83 | if k == 'abr': | |
84 | formats.extend(self._extract_m3u8_formats( | |
85 | v, broadcast_id, 'mp4', protocol, | |
86 | m3u8_id='hls', fatal=False)) | |
87 | continue | |
88 | f = { | |
89 | 'ext': 'mp4', | |
90 | 'format_id': 'hls-' + k, | |
91 | 'protocol': protocol, | |
92 | 'url': v, | |
93 | } | |
94 | if not k.isdigit(): | |
95 | f['vcodec'] = 'none' | |
96 | formats.append(f) | |
97 | if not formats: | |
98 | archive_status = item.get('archiveStatus') | |
99 | if archive_status != 'ARCHIVED': | |
b7da73eb | 100 | self.raise_no_formats('this video has been ' + archive_status.lower(), expected=True) |
f7ad7160 | 101 | self._sort_formats(formats) |
102 | info['formats'] = formats | |
103 | return info | |
104 | ||
105 | ||
106 | class LineLiveChannelIE(LineLiveBaseIE): | |
107 | _VALID_URL = r'https?://live\.line\.me/channels/(?P<id>\d+)(?!/broadcast/\d+)(?:[/?&#]|$)' | |
108 | _TEST = { | |
109 | 'url': 'https://live.line.me/channels/5893542', | |
110 | 'info_dict': { | |
111 | 'id': '5893542', | |
935f5a42 | 112 | 'title': 'いくらちゃんだよぉ🦒', |
113 | 'description': 'md5:4d418087973ad081ceb1b3481f0b1816', | |
f7ad7160 | 114 | }, |
115 | 'playlist_mincount': 29 | |
116 | } | |
117 | ||
118 | def _archived_broadcasts_entries(self, archived_broadcasts, channel_id): | |
119 | while True: | |
120 | for row in (archived_broadcasts.get('rows') or []): | |
121 | share_url = str_or_none(row.get('shareURL')) | |
122 | if not share_url: | |
123 | continue | |
124 | info = self._parse_broadcast_item(row) | |
125 | info.update({ | |
126 | '_type': 'url', | |
127 | 'url': share_url, | |
128 | 'ie_key': LineLiveIE.ie_key(), | |
129 | }) | |
130 | yield info | |
131 | if not archived_broadcasts.get('hasNextPage'): | |
132 | return | |
133 | archived_broadcasts = self._download_json( | |
134 | self._API_BASE_URL + channel_id + '/archived_broadcasts', | |
135 | channel_id, query={ | |
136 | 'lastId': info['id'], | |
137 | }) | |
138 | ||
139 | def _real_extract(self, url): | |
140 | channel_id = self._match_id(url) | |
141 | channel = self._download_json(self._API_BASE_URL + channel_id, channel_id) | |
142 | return self.playlist_result( | |
143 | self._archived_broadcasts_entries(channel.get('archivedBroadcasts') or {}, channel_id), | |
144 | channel_id, channel.get('title'), channel.get('information')) |