Skip to content

Commit e728132

Browse files
committed
feat: add migu live record support
1 parent e6dd999 commit e728132

File tree

3 files changed

+52
-24
lines changed

3 files changed

+52
-24
lines changed

app/core/platform_handlers/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
LivemeHandler,
2727
LookHandler,
2828
MaoerFMHandler,
29+
MiguHandler,
2930
NeteaseHandler,
3031
PamdaTVHandler,
3132
PiaopiaoHandler,
@@ -122,6 +123,7 @@ def get_platform_info(record_url: str) -> tuple:
122123
"3.cn": ("京东直播", "jd"),
123124
"faceit.com": ("faceit", "faceit"),
124125
"lailianjie.com": ("连接直播", "lianjie"),
126+
"miguvideo.com": ("咪咕直播", "migu"),
125127
".m3u8": ("自定义录制直播", "custom"),
126128
".flv": ("自定义录制直播", "custom"),
127129
}
@@ -159,6 +161,7 @@ def get_platform_info(record_url: str) -> tuple:
159161
"LivemeHandler",
160162
"LookHandler",
161163
"MaoerFMHandler",
164+
"MiguHandler",
162165
"NeteaseHandler",
163166
"PamdaTVHandler",
164167
"PiaopiaoHandler",

app/core/platform_handlers/handlers.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,27 @@ async def get_stream_info(self, live_url: str) -> StreamData:
10141014
return await self.live_stream.fetch_stream_url(json_data, self.record_quality)
10151015

10161016

1017+
class MiguHandler(PlatformHandler):
1018+
platform = "migu"
1019+
1020+
def __init__(
1021+
self,
1022+
proxy: str | None = None,
1023+
cookies: str | None = None,
1024+
record_quality: str | None = None,
1025+
platform: str | None = None,
1026+
) -> None:
1027+
super().__init__(proxy, cookies, record_quality, platform)
1028+
self.live_stream: streamget.MiguLiveStream | None = None
1029+
1030+
@trace_error_decorator
1031+
async def get_stream_info(self, live_url: str) -> StreamData:
1032+
if not self.live_stream:
1033+
self.live_stream = streamget.MiguLiveStream(proxy_addr=self.proxy, cookies=self.cookies)
1034+
json_data = await self.live_stream.fetch_web_stream_data(url=live_url)
1035+
return await self.live_stream.fetch_stream_url(json_data, self.record_quality)
1036+
1037+
10171038
DouyinHandler.register(r"https://.*\.douyin\.com/")
10181039
TikTokHandler.register(r"https://.*\.tiktok\.com/")
10191040
KuaishouHandler.register(r"https://live\.kuaishou\.com/")
@@ -1061,3 +1082,4 @@ async def get_stream_info(self, live_url: str) -> StreamData:
10611082
JDHandler.register(r"3\.cn/")
10621083
FaceitHandler.register(r"https://.*\.faceit\.com/")
10631084
LianJieHandler.register(r"https://.*\.lailianjie\.com/")
1085+
MiguHandler.register(r"https://.*\.miguvideo\.com/")

app/core/stream_manager.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,27 @@ def _get_filename(self, stream_info: StreamData) -> str:
7474
stream_info.anchor_name = utils.clean_name(stream_info.anchor_name, self._["live_room"])
7575

7676
now = time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime())
77-
77+
7878
custom_template = self.user_config.get("custom_filename_template")
7979
if custom_template:
8080
filename = custom_template
8181
filename = filename.replace("{anchor_name}", stream_info.anchor_name or "")
8282
filename = filename.replace("{title}", live_title or "")
8383
filename = filename.replace("{time}", now)
8484
filename = filename.replace("{platform}", stream_info.platform or "")
85-
85+
8686
while "__" in filename:
8787
filename = filename.replace("__", "_")
88-
88+
8989
filename = filename.strip("_")
90-
90+
9191
if not filename:
9292
full_filename = "_".join([i for i in (stream_info.anchor_name, live_title, now) if i])
9393
else:
9494
full_filename = filename
9595
else:
9696
full_filename = "_".join([i for i in (stream_info.anchor_name, live_title, now) if i])
97-
97+
9898
return full_filename
9999

100100
def _get_output_dir(self, stream_info: StreamData) -> str:
@@ -139,11 +139,13 @@ def _clean_and_truncate_title(title: str) -> str | None:
139139
return cleaned_title
140140

141141
def _get_record_url(self, url: str):
142-
http_record_list = ["shopee"]
143-
if self.platform_key in http_record_list:
144-
url = url.replace("https://", "http://")
142+
http_record_list = ["shopee", "migu"]
143+
145144
if self.user_config.get("force_https_recording") and url.startswith("http://"):
146145
url = url.replace("http://", "https://")
146+
147+
if self.platform_key in http_record_list:
148+
url = url.replace("https://", "http://")
147149
return url
148150

149151
async def fetch_stream(self) -> StreamData:
@@ -198,13 +200,13 @@ async def start_recording(self, stream_info: StreamData):
198200
)
199201

200202
async def start_ffmpeg(
201-
self,
202-
record_name: str,
203-
live_url: str,
204-
record_url: str,
205-
ffmpeg_command: list,
206-
save_type: str,
207-
script_command: str | None = None
203+
self,
204+
record_name: str,
205+
live_url: str,
206+
record_url: str,
207+
ffmpeg_command: list,
208+
save_type: str,
209+
script_command: str | None = None
208210
) -> bool:
209211
"""
210212
The child process executes ffmpeg for recording
@@ -286,11 +288,11 @@ async def start_ffmpeg(
286288
if not self.recording.is_recording:
287289
logger.success(f"Live recording has stopped: {record_name}")
288290
else:
289-
291+
290292
logger.success(f"Live recording completed: {record_name}")
291293
msg_manager = MessagePusher(self.settings)
292294
user_config = self.settings.user_config
293-
295+
294296
if (self.app.recording_enabled and MessagePusher.should_push_message(
295297
self.settings, self.recording, check_manually_stopped=True, message_type='end') and
296298
not self.recording.notified_live_end):
@@ -453,13 +455,13 @@ async def _do_converts_mp4(self, converts_file_path: str, is_original_delete: bo
453455
logger.error(f"An unknown error occurred: {e}")
454456

455457
async def custom_script_execute(
456-
self,
457-
script_command: str,
458-
record_name: str,
459-
save_file_path: str,
460-
save_type: str,
461-
split_video_by_time: bool,
462-
converts_to_mp4: bool
458+
self,
459+
script_command: str,
460+
record_name: str,
461+
save_file_path: str,
462+
save_type: str,
463+
split_video_by_time: bool,
464+
converts_to_mp4: bool
463465
):
464466
from ..process_manager import BackgroundService
465467

@@ -542,3 +544,4 @@ def get_headers_params(live_url, platform_key):
542544
"blued": "referer:https://app.blued.cn",
543545
}
544546
return record_headers.get(platform_key)
547+

0 commit comments

Comments
 (0)