forked from exe12356/LINELIVERecorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinelive.py
74 lines (58 loc) · 2.11 KB
/
linelive.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import requests
import sys
import os
import subprocess
import time
import getopt
G_channel_id = '3573156'
def rec_hls(filename, m3u8, format):
m3u8 = str(m3u8).replace('240/chunklist.m3u8', '720/chunklist.m3u8')
filename = str(filename).replace('/', '_')
nowtime = time.strftime("%Y%m%d%H%M%S", time.localtime())
filename = '[' + nowtime + ']' + filename
command = 'ffmpeg -c copy "' + filename + \
'.' + format + '"' + ' -i "' + m3u8 + '"'
print(command)
code = subprocess.call(command)
print(str(code))
def GetRequest(url):
response = requests.get(url)
data = response.json()
return data
# channel_response = requests.get('https://live-api.line-apps.com/app/channel/4369341')
def get_hls(liveid, channel_id):
hls_api = 'https://live-api.line-apps.com/app/v2/channel/{channel_id}/broadcast/{live_id}'
hls_api = hls_api.format(channel_id=channel_id, live_id=liveid)
print(hls_api)
hls_data = GetRequest(hls_api)
m3u8 = hls_data['liveHLSURLs']['720']
return m3u8
# data = channel_response.json()
# print(data['liveBroadcasts']['hasNextPage'])
def main(argv):
channel_id = ''
try:
opts, args = getopt.getopt(argv, "c:")
# for item in opts:
# print(item)
channel_id = opts[0][1]
except:
channel_id = G_channel_id
while(1):
channel_api = 'https://live-api.line-apps.com/app/channel/' + channel_id
data = GetRequest(channel_api)
if(len(data['liveBroadcasts']['rows']) > 0):
m3u8 = get_hls(data['liveBroadcasts']['rows'][0]['id'], channel_id)
print(m3u8)
rec_hls(data['liveBroadcasts']['rows'][0]['title'],
m3u8, 'ts')
else:
nowtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(nowtime + ' ' + data['title'] + 'has no live now')
for num in range(1, 6):
print('wait ' + str(num) + 's then refresh')
time.sleep(1)
if __name__ == "__main__":
main(sys.argv[1:])
# for item in data['liveBroadcasts']['rows']:
# print(item['autoPlayURL'])