From fb3e615b3bdbdce1cf3689126e553cffd1e089ac Mon Sep 17 00:00:00 2001 From: James Jing Date: Tue, 2 Mar 2021 16:44:23 +0800 Subject: [PATCH] create cc.py for cc.163.com --- engine/plugins/cc.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 engine/plugins/cc.py diff --git a/engine/plugins/cc.py b/engine/plugins/cc.py new file mode 100644 index 0000000..a6ab94a --- /dev/null +++ b/engine/plugins/cc.py @@ -0,0 +1,38 @@ +import base64 +import html +import json +import re + +import requests + +from common.decorators import Plugin +from engine.plugins import match1, logger +from engine.plugins.base_adapter import fake_headers, FFmpegdl + + +@Plugin.download(regexp=r'(?:https?://)?cc\.163\.com') +class CC(FFmpegdl): + def __init__(self, fname, url, suffix='flv'): + super().__init__(fname, url, suffix) + + def check_stream(self): + logger.debug(self.fname) + rid = re.search(r"[0-9]{4,}", self.url).group(0) + res = requests.get( + f"https://api.cc.163.com/v1/activitylives/anchor/lives?anchor_ccid={rid}", + timeout=5, + headers=fake_headers + ) + res.close() + jsons = json.loads(res.text) + if jsons["data"]: + channel_id = jsons["data"][rid]["channel_id"] + res = requests.get( + f"https://cc.163.com/live/channel/?channelids={channel_id}", + timeout=5, + headers=fake_headers + ) + res.close() + jsons = json.loads(res.text) + self.raw_stream_url = jsons["data"][0]["sharefile"] + return True