forked from AlotOfBlahaj/Auto_Record_Matsuri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitcasting.py
47 lines (40 loc) · 1.59 KB
/
twitcasting.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
import time
from daemon import VideoDaemon
from tools import get_logger, get_json, while_warp
from video_process import process_video
class Twitcasting(VideoDaemon):
def __init__(self, target_id):
super().__init__(target_id)
self.logger = get_logger('Twitcasting')
self.module = 'Twitcasting'
def live_info(self):
live_js = get_json(
f"https://twitcasting.tv/streamserver.php?target={self.target_id}&mode=client")
is_live = live_js['movie']['live']
vid = str(live_js['movie']['id'])
live_info = {"Is_live": is_live,
"Vid": vid}
return live_info
def get_hsl(self, live_info):
# html = get(f"https://twitcasting.tv/{twitcasting_id}")
# dom = etree.HTML(html)
# title = dom.xpath('/html/body/div[3]/div[2]/div/div[2]/h2/span[3]/a/text()')[0]
title = f"{self.target_id}#{live_info.get('Vid')}"
ref = f"https://twitcasting.tv/{self.target_id}/metastream.m3u8"
target = f"https://twitcasting.tv/{self.target_id}"
date = time.strftime("%Y-%m-%d", time.localtime())
return {'Title': title,
'Ref': ref,
'Target': target,
'Date': date}
@while_warp
def check(self):
live_info = self.live_info()
if live_info.get('Is_live'):
video_dict = self.get_hsl(live_info)
video_dict['Provide'] = self.module
process_video(video_dict)
else:
self.logger.info(f'{self.target_id}: Not found Live')
def run(self) -> None:
self.check()