示例#1
0
        public static async ValueTask VideoInfoById(GroupMessageEventArgs eventArgs)
        {
            Regex idRegex    = new(@"(?:BV|bv|AV|av)[a-zA-Z0-9]+");
            var   videoIdStr = idRegex.Match(eventArgs.Message.RawText).Value;
            var   videoInfo  = VideoApis.GetVideoInfo(videoIdStr);

            if (videoInfo.Code != 0)
            {
                await eventArgs.Reply($"API发生错误({videoInfo.Code})\r\nmessage:{videoInfo.Message}");

                return;
            }

            //发送视频信息
            await eventArgs.Reply(GenReplyMessage(videoInfo));
        }
示例#2
0
        public static async ValueTask VideoInfoByMiniApp(GroupMessageEventArgs eventArgs)
        {
            //获取短链
            Regex urlRegex    = new(@"https://b23\.tv/[a-zA-Z0-9]+");
            var   videoUrlStr = urlRegex.Match(eventArgs.Message.RawText).Value;

            if (string.IsNullOrEmpty(videoUrlStr))
            {
                return;
            }
            //网络请求获取跳转地址
            var handler = new HttpClientHandler();

            handler.AllowAutoRedirect = false;
            var client   = new HttpClient(handler);
            var response = await client.GetAsync(videoUrlStr);

            //解析id
            Regex idRegex    = new(@"(?:BV|bv|AV|av)[a-zA-Z0-9]+");
            var   videoIdStr = idRegex.Match(response.Headers.Location?.ToString() ?? string.Empty).Value;

            if (string.IsNullOrEmpty(videoIdStr))
            {
                await eventArgs.Reply("小程序解析发生错误");

                Log.Error("Mini App", "解析ID为空");
                return;
            }

            //获取视频信息
            var videoInfo = VideoApis.GetVideoInfo(videoIdStr);

            if (videoInfo.Code != 0)
            {
                await eventArgs.Reply($"API发生错误({videoInfo.Code})\r\nmessage:{videoInfo.Message}");

                return;
            }

            //发送视频信息
            await eventArgs.Reply("别他妈发小程序了");

            await eventArgs.Reply(GenReplyMessage(videoInfo));
        }