Merge branch 'main' into feat/proxy

This commit is contained in:
felinae98
2022-05-23 13:24:35 +08:00
18 changed files with 336 additions and 30 deletions
@@ -1,4 +1,5 @@
import json
import re
from typing import Any, Optional
from ..post import Post
@@ -25,6 +26,7 @@ class Bilibili(NewMessage):
schedule_kw = {"seconds": 10}
name = "B站"
has_target = True
parse_target_promot = "请输入用户主页的链接"
async def get_target_name(self, target: Target) -> Optional[str]:
async with http_client() as client:
@@ -36,6 +38,16 @@ class Bilibili(NewMessage):
return None
return res_data["data"]["name"]
async def parse_target(self, target_text: str) -> Target:
if re.match(r"\d+", target_text):
return Target(target_text)
elif match := re.match(
r"(?:https?://)?space\.bilibili\.com/(\d+)", target_text
):
return Target(match.group(1))
else:
raise self.ParseTargetException()
async def get_sub_list(self, target: Target) -> list[RawPost]:
async with http_client() as client:
params = {"host_uid": target, "offset": 0, "need_top": 0}
@@ -1,3 +1,4 @@
import re
from typing import Any, Optional
from ..post import Post
@@ -17,6 +18,7 @@ class NcmArtist(NewMessage):
schedule_kw = {"minutes": 1}
name = "网易云-歌手"
has_target = True
parse_target_promot = "请输入歌手主页(包含数字ID)的链接"
async def get_target_name(self, target: Target) -> Optional[str]:
async with http_client() as client:
@@ -29,6 +31,16 @@ class NcmArtist(NewMessage):
return
return res_data["artist"]["name"]
async def parse_target(self, target_text: str) -> Target:
if re.match(r"^\d+$", target_text):
return Target(target_text)
elif match := re.match(
r"(?:https?://)?music\.163\.com/#/artist\?id=(\d+)", target_text
):
return Target(match.group(1))
else:
raise self.ParseTargetException()
async def get_sub_list(self, target: Target) -> list[RawPost]:
async with http_client() as client:
res = await client.get(
@@ -1,3 +1,4 @@
import re
from typing import Any, Optional
from ..post import Post
@@ -17,6 +18,7 @@ class NcmRadio(NewMessage):
schedule_kw = {"minutes": 10}
name = "网易云-电台"
has_target = True
parse_target_promot = "请输入主播电台主页(包含数字ID)的链接"
async def get_target_name(self, target: Target) -> Optional[str]:
async with http_client() as client:
@@ -30,6 +32,16 @@ class NcmRadio(NewMessage):
return
return res_data["programs"][0]["radio"]["name"]
async def parse_target(self, target_text: str) -> Target:
if re.match(r"^\d+$", target_text):
return Target(target_text)
elif match := re.match(
r"(?:https?://)?music\.163\.com/#/djradio\?id=(\d+)", target_text
):
return Target(match.group(1))
else:
raise self.ParseTargetException()
async def get_sub_list(self, target: Target) -> list[RawPost]:
async with http_client() as client:
res = await client.post(
@@ -47,6 +47,7 @@ class Platform(metaclass=RegistryABCMeta, base=True):
enable_tag: bool
store: dict[Target, Any]
platform_name: str
parse_target_promot: Optional[str] = None
@abstractmethod
async def get_target_name(self, target: Target) -> Optional[str]:
@@ -73,6 +74,12 @@ class Platform(metaclass=RegistryABCMeta, base=True):
self.reverse_category[val] = key
self.store = dict()
class ParseTargetException(Exception):
pass
async def parse_target(self, target_string: str) -> Target:
return Target(target_string)
@abstractmethod
def get_tags(self, raw_post: RawPost) -> Optional[Collection[Tag]]:
"Return Tag list of given RawPost"
+13 -3
View File
@@ -28,6 +28,7 @@ class Weibo(NewMessage):
schedule_type = "interval"
schedule_kw = {"seconds": 3}
has_target = True
parse_target_promot = "请输入用户主页(包含数字UID)的链接"
async def get_target_name(self, target: Target) -> Optional[str]:
async with http_client() as client:
@@ -41,6 +42,15 @@ class Weibo(NewMessage):
else:
return None
async def parse_target(self, target_text: str) -> Target:
if re.match(r"\d+", target_text):
return Target(target_text)
elif match := re.match(r"(?:https?://)?weibo\.com/u/(\d+)", target_text):
# 都2202年了应该不会有http了吧,不过还是防一手
return Target(match.group(1))
else:
raise self.ParseTargetException()
async def get_sub_list(self, target: Target) -> list[RawPost]:
async with http_client() as client:
params = {"containerid": "107603" + target}
@@ -133,9 +143,9 @@ class Weibo(NewMessage):
"https://m.weibo.cn/detail/{}".format(info["mid"]), headers=header
)
try:
full_json_text = re.search(
r'"status": ([\s\S]+),\s+"call"', res.text
).group(1)
match = re.search(r'"status": ([\s\S]+),\s+"call"', res.text)
assert match
full_json_text = match.group(1)
info = json.loads(full_json_text)
except:
logger.info(