Пример #1
0
        /// <summary>
        /// 清空观看历史记录
        /// </summary>
        /// <returns></returns>
        public async Task <bool> ClearHistoryAsync()
        {
            string url     = BiliFactory.UrlContact(Api.ACCOUNT_HISTORY_CLEAR, null, true);
            string content = await BiliClient.PostContentToWebAsync(url, "");

            return(content != null);
        }
Пример #2
0
        /// <summary>
        /// 清空稍后观看列表
        /// </summary>
        /// <returns></returns>
        public async Task <bool> ClearViewLaterAsync()
        {
            string url     = BiliFactory.UrlContact(Api.ACCOUNT_VIEWLATER_CLEAR, null, true);
            string content = await BiliClient.PostContentToWebAsync(url, "");

            return(content != null);
        }
Пример #3
0
        /// <summary>
        /// 刷新令牌
        /// </summary>
        /// <returns></returns>
        public async Task <bool> RefreshTokenAsync()
        {
            try
            {
                var param = $"access_token={_accessToken}&refresh_token={_refreshToken}&appkey={BiliFactory.AndroidKey.Appkey}&ts={BiliFactory.GetNowSeconds()}";
                param += "&sign=" + BiliFactory.GetSign(param);
                var content = await BiliClient.PostContentToWebAsync(Api.PASSPORT_REFRESH_TOKEN, param);

                var obj = JObject.Parse(content);
                if (Convert.ToInt32(obj["code"]) == 0)
                {
                    var data    = JsonConvert.DeserializeObject <TokenInfo>(obj["data"].ToString());
                    var package = new TokenPackage(data.access_token, data.refresh_token, BiliFactory.GetTimeStampFuture(data.expires_in));
                    InitToken(package);
                    TokenChanged?.Invoke(this, package);
                    await SSO();

                    return(true);
                }
                return(false);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #4
0
        /// <summary>
        /// 转发动态
        /// </summary>
        /// <param name="content">附加内容</param>
        /// <param name="dynamicId">被转发动态ID</param>
        /// <param name="rid">被转发动态评论ID</param>
        /// <param name="type">被转发动态类型</param>
        /// <param name="atIds">at的人</param>
        /// <returns></returns>
        public async Task <bool> RepostDynamicAsync(string content, string dynamicId, string rid, int type, List <RepostLocation> atIds)
        {
            if (atIds == null)
            {
                atIds = new List <RepostLocation>();
            }
            var param = new Dictionary <string, string>();

            param.Add("content", Uri.EscapeDataString(content));
            param.Add("at_uids", string.Join(',', atIds.Select(p => p.data)));
            param.Add("ctrl", Uri.EscapeDataString(JsonConvert.SerializeObject(atIds)));
            param.Add("dynamic_id", dynamicId);
            param.Add("rid", rid);
            param.Add("repost_code", "10000");
            param.Add("sync_comment", "0");
            param.Add("spec_type", "0");
            param.Add("type", type.ToString());
            param.Add("uid", BiliClient.Mid.ToString());
            param.Add("extension", Uri.EscapeDataString("{\"emoji_type\":1}"));
            param.Add("statistics", Uri.EscapeDataString("{\"appId\":1,\"version\":\"5.56.1\",\"abtest\":\"\",\"platform\":1}"));
            var req      = BiliFactory.UrlContact("", param, true);
            var response = await BiliClient.PostContentToWebAsync(Api.DYNAMIC_REPOST, req);

            if (!string.IsNullOrEmpty(response))
            {
                var jobj = JObject.Parse(response);
                return(jobj["code"].ToString() == "0");
            }
            return(false);
        }
Пример #5
0
        public static async Task <string> EncryptAsPasswordAsync(string password)
        {
            string base64String;

            string param   = UrlContact("").TrimStart('?');
            string content = await BiliClient.PostContentToWebAsync(Api.PASSPORT_KEY_ENCRYPT, param);

            JObject jobj = JObject.Parse(content);
            string  str  = jobj["data"]["hash"].ToString();
            string  str1 = jobj["data"]["key"].ToString();
            string  str2 = string.Concat(str, password);
            string  str3 = Regex.Match(str1, "BEGIN PUBLIC KEY-----(?<key>[\\s\\S]+)-----END PUBLIC KEY").Groups["key"].Value.Trim();

            byte[] numArray = Convert.FromBase64String(str3);
            AsymmetricKeyAlgorithmProvider asymmetricKeyAlgorithmProvider = AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithmNames.RsaPkcs1);
            CryptographicKey cryptographicKey = asymmetricKeyAlgorithmProvider.ImportPublicKey(WindowsRuntimeBufferExtensions.AsBuffer(numArray), 0);
            var buffer = CryptographicEngine.Encrypt(cryptographicKey, WindowsRuntimeBufferExtensions.AsBuffer(Encoding.UTF8.GetBytes(str2)), null);

            base64String = Convert.ToBase64String(WindowsRuntimeBufferExtensions.ToArray(buffer));

            /**
             * try
             * {
             *
             * }
             * catch (Exception ex)
             * {
             *  System.Diagnostics.Debug.WriteLine(ex);
             *  base64String = password;
             * }
             */
            return(base64String);
        }
Пример #6
0
        /// <summary>
        /// 操作收藏夹
        /// </summary>
        /// <param name="aid">视频ID</param>
        /// <param name="addIds">添加的收藏夹ID列表</param>
        /// <param name="delIds">移出的收藏夹ID列表</param>
        /// <returns></returns>
        public async Task <bool> AddVideoToFavoriteAsync(int aid, List <string> addIds, List <string> delIds)
        {
            if (addIds.Count == 0 && delIds.Count == 0)
            {
                return(false);
            }
            var param = new Dictionary <string, string>();

            param.Add("rid", aid.ToString());
            param.Add("type", "2");
            if (addIds.Count > 0)
            {
                param.Add("add_media_ids", string.Join(',', addIds));
            }
            else if (delIds.Count > 0)
            {
                param.Add("del_media_ids", string.Join(',', delIds));
            }
            var result = await BiliClient.PostContentToWebAsync(Api.VIDEO_FAVORITE, BiliFactory.UrlContact("", param, true));

            if (!string.IsNullOrEmpty(result))
            {
                var jobj = JObject.Parse(result);
                return(jobj["code"].ToString() == "0");
            }
            return(false);
        }
Пример #7
0
        /// <summary>
        /// 设置动态点赞状态
        /// </summary>
        /// <param name="isLike">是否点赞</param>
        /// <param name="dynamicId">动态ID</param>
        /// <param name="rid">动态里的参数</param>
        /// <param name="uid">用户ID</param>
        /// <returns></returns>
        public async Task <bool> SetDynamicLikeStatus(bool isLike, string dynamicId, string rid, string uid)
        {
            if (string.IsNullOrEmpty(uid) || string.IsNullOrEmpty(dynamicId) || string.IsNullOrEmpty(rid))
            {
                return(false);
            }
            var param = new Dictionary <string, string>();

            param.Add("dynamic_id", dynamicId);
            param.Add("rid", rid);
            param.Add("uid", uid);
            param.Add("up", isLike ? "1" : "2");
            var data     = BiliFactory.UrlContact("", param, true);
            var response = await BiliClient.PostContentToWebAsync(Api.DYNAMIC_LIKE, data);

            if (!string.IsNullOrEmpty(response))
            {
                var jobj = JObject.Parse(response);
                if (jobj["code"].ToString() == "0")
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #8
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="captcha">验证码</param>
        /// <returns></returns>
        public async Task <LoginCallback> LoginAsync(string userName, string password, string captcha = "")
        {
            string param = $"appkey={BiliFactory.AndroidKey.Appkey}&build={BiliFactory.BuildNumber}&mobi_app=android&password={Uri.EscapeDataString(await BiliFactory.EncryptAsPasswordAsync(password))}&platform=android&ts={BiliFactory.GetNowSeconds()}&username={Uri.EscapeDataString(userName)}";

            if (!string.IsNullOrEmpty(captcha))
            {
                param += "&captcha=" + captcha;
            }
            param += "&sign=" + BiliFactory.GetSign(param);
            string response = await BiliClient.PostContentToWebAsync(Api.PASSPORT_LOGIN, param);

            var result = new LoginCallback();

            result.Status = LoginResultType.Error;
            if (!string.IsNullOrEmpty(response))
            {
                try
                {
                    var jobj = JObject.Parse(response);
                    int code = Convert.ToInt32(jobj["code"]);
                    if (code == 0)
                    {
                        var data    = JsonConvert.DeserializeObject <LoginResult>(jobj["data"].ToString());
                        var package = new TokenPackage(data.token_info.access_token, data.token_info.refresh_token, BiliFactory.GetTimeStampFuture(data.token_info.expires_in));
                        InitToken(package);
                        TokenChanged?.Invoke(this, package);
                        result.Status = LoginResultType.Success;
                        await SSO();

                        await GetUserSpaceAsync(286725648);
                    }
                    else if (code == -2100)
                    {
                        result.Status = LoginResultType.NeedValidate;
                        result.Url    = jobj["url"].ToString();
                    }
                    else if (code == -105)
                    {
                        result.Status = LoginResultType.NeedCaptcha;
                    }
                    else if (code == -449)
                    {
                        result.Status = LoginResultType.Busy;
                    }
                    else
                    {
                        result.Status = LoginResultType.Fail;
                    }
                }
                catch (Exception)
                {
                    return(new LoginCallback {
                        Status = LoginResultType.Fail, Url = ""
                    });
                }
            }
            return(result);
        }
Пример #9
0
        /// <summary>
        /// 转发动漫/电影/电视剧等
        /// </summary>
        /// <param name="content">转发内容</param>
        /// <param name="videoId">视频ID</param>
        /// <param name="atIds">At的人</param>
        /// <param name="typeName">番剧:4097,影视:4098,电视剧:4099,国创:4100</param>
        /// <returns></returns>
        public async Task <bool> RepostBangumiAsync(string content, int epId, string typeName, List <RepostLocation> atIds)
        {
            var    param = new Dictionary <string, string>();
            string type  = "";

            switch (typeName)
            {
            case "番剧":
                type = "4097";
                break;

            case "影视":
                type = "4098";
                break;

            case "电视剧":
            case "综艺":
                type = "4099";
                break;

            case "国创":
                type = "4100";
                break;

            case "纪录片":
                type = "4101";
                break;

            default:
                type = "4097";
                break;
            }
            param.Add("content", Uri.EscapeDataString(content));
            param.Add("at_uids", string.Join(',', atIds.Select(p => p.data)));
            param.Add("ctrl", Uri.EscapeDataString(JsonConvert.SerializeObject(atIds)));
            param.Add("share_uid", BiliClient.Mid.ToString());
            param.Add("rid", epId.ToString());
            param.Add("type", type);
            param.Add("repost_code", "20000");
            param.Add("sync_comment", "0");
            param.Add("sketch", "");
            param.Add("uid", "0");
            param.Add("share_info", "");
            param.Add("extension", Uri.EscapeDataString("{\"emoji_type\":1}"));
            param.Add("statistics", Uri.EscapeDataString("{\"appId\":1,\"version\":\"5.56.1\",\"abtest\":\"\",\"platform\":1}"));
            var req      = BiliFactory.UrlContact("", param, true);
            var response = await BiliClient.PostContentToWebAsync(Api.VIDEO_REPOST, req);

            if (!string.IsNullOrEmpty(response))
            {
                var jobj = JObject.Parse(response);
                return(jobj["code"].ToString() == "0");
            }
            return(false);
        }
Пример #10
0
        /// <summary>
        /// 添加观看视频的历史记录
        /// </summary>
        /// <param name="aid">视频ID</param>
        /// <returns></returns>
        public async Task AddVideoHistoryAsync(int aid, int cid, int seconds = 0)
        {
            var param = new Dictionary <string, string>();

            param.Add("aid", aid.ToString());
            param.Add("cid", cid.ToString());
            param.Add("progress", seconds.ToString());
            param.Add("type", "3");
            var data = BiliFactory.UrlContact("", param, true);
            await BiliClient.PostContentToWebAsync(Api.VIDEO_ADD_WATCH, data);
        }
Пример #11
0
        /// <summary>
        /// 一键三连
        /// </summary>
        /// <param name="aid">视频ID</param>
        /// <returns></returns>
        public async Task <bool> TripleVideoAsync(int aid)
        {
            var param = new Dictionary <string, string>();

            param.Add("aid", aid.ToString());
            var result = await BiliClient.PostContentToWebAsync(Api.VIDEO_TRIPLE, BiliFactory.UrlContact("", param, true));

            if (!string.IsNullOrEmpty(result))
            {
                var jobj = JObject.Parse(result);
                return(jobj["code"].ToString() == "0");
            }
            return(false);
        }
Пример #12
0
        /// <summary>
        /// 移出稍后再看
        /// </summary>
        /// <param name="aids">视频ID组</param>
        /// <returns></returns>
        public async Task <bool> DeleteViewLaterAsync(params int[] aids)
        {
            var param = new Dictionary <string, string>();

            param.Add("aid", string.Join(',', aids));
            var    data    = BiliFactory.UrlContact("", param, true);
            string content = await BiliClient.PostContentToWebAsync(Api.ACCOUNT_VIEWLATER_DEL, data);

            if (!string.IsNullOrEmpty(content))
            {
                var jobj = JObject.Parse(content);
                return(jobj["code"].ToString() == "0");
            }
            return(false);
        }
Пример #13
0
        /// <summary>
        /// 取消追番/追剧
        /// </summary>
        /// <param name="epid">标识ID</param>
        /// <returns></returns>
        public async Task <bool> UnfollowBangumiAsync(int epid)
        {
            var param = new Dictionary <string, string>();

            param.Add("season_id", epid.ToString());
            string data    = BiliFactory.UrlContact("", param, true);
            string content = await BiliClient.PostContentToWebAsync(Api.ANIME_UNFOLLOW, data);

            if (!string.IsNullOrEmpty(content))
            {
                var jobj = JObject.Parse(content);
                return(jobj["message"].ToString() == "success");
            }
            return(false);
        }
Пример #14
0
        /// <summary>
        /// 取消关注用户
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <returns></returns>
        public async Task <bool> UnfollowUser(int uid)
        {
            var param = new Dictionary <string, string>();

            param.Add("uid", Me.mid.ToString());
            param.Add("follow", uid.ToString());
            var    data     = BiliFactory.UrlContact("", param, true);
            string response = await BiliClient.PostContentToWebAsync(Api.ACCOUNT_UNFOLLOW_USER, data);

            if (!string.IsNullOrEmpty(response))
            {
                var jobj = JObject.Parse(response);
                return(jobj["code"].ToString() == "0");
            }
            return(false);
        }
Пример #15
0
        /// <summary>
        /// 删除收藏夹内视频
        /// </summary>
        /// <param name="aid">视频ID</param>
        /// <param name="videoType">视频类型</param>
        /// <param name="listId">收藏夹ID</param>
        /// <returns></returns>
        public async Task <bool> RemoveFavoriteVideoAsync(int aid, int videoType, int listId)
        {
            var param = new Dictionary <string, string>();

            param.Add("media_id", listId.ToString());
            param.Add("resources", $"{aid}:{videoType}");
            var req  = BiliFactory.UrlContact("", param, true);
            var data = await BiliClient.PostContentToWebAsync(Api.ACCOUNT_FAVORITE_VIDEO_DELETE, req);

            if (!string.IsNullOrEmpty(data))
            {
                var jobj = JObject.Parse(data);
                return(jobj["code"].ToString() == "0");
            }
            return(false);
        }
Пример #16
0
        /// <summary>
        /// 视频投币
        /// </summary>
        /// <param name="aid">视频ID</param>
        /// <param name="coin">投币数量</param>
        /// <param name="isLike">是否同时点赞</param>
        /// <returns></returns>
        public async Task <bool> GiveCoinToVideoAsync(int aid, int coin, bool isLike)
        {
            string is_like = isLike ? "1" : "0";
            var    param   = new Dictionary <string, string>();

            param.Add("aid", aid.ToString());
            param.Add("select_like", is_like);
            param.Add("multiply", coin.ToString());
            var result = await BiliClient.PostContentToWebAsync(Api.VIDEO_COIN, BiliFactory.UrlContact("", param, true));

            if (!string.IsNullOrEmpty(result))
            {
                var jobj = JObject.Parse(result);
                return(jobj["code"].ToString() == "0");
            }
            return(false);
        }
Пример #17
0
        /// <summary>
        /// 订阅频道
        /// </summary>
        /// <param name="channelId">频道ID</param>
        /// <returns></returns>
        public async Task <bool> SubscribeChannelAsync(int channelId)
        {
            var param = new Dictionary <string, string>();

            param.Add("channel_id", channelId.ToString());
            var data     = BiliFactory.UrlContact("", param, true);
            var response = await BiliClient.PostContentToWebAsync(Api.CHANNEL_SUBSCRIBE, data);

            if (!string.IsNullOrEmpty(response))
            {
                var jobj = JObject.Parse(response);
                if (jobj["code"].ToString() == "0")
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #18
0
        /// <summary>
        /// 发送弹幕
        /// </summary>
        /// <param name="message">弹幕信息</param>
        /// <param name="aid">视频ID</param>
        /// <param name="cid">弹幕块ID</param>
        /// <param name="progress">进度</param>
        /// <param name="color">颜色(已处理)</param>
        /// <param name="fontSize">文本大小</param>
        /// <param name="mode">模式</param>
        /// <returns></returns>
        public async Task <bool> SendDanmakuAsync(string message, int aid, int cid, double progress, string color, string fontSize, string mode)
        {
            var param = new Dictionary <string, string>();

            param.Add("aid", aid.ToString());
            param.Add("msg", Uri.EscapeDataString(message));
            param.Add("oid", cid.ToString());
            param.Add("color", color);
            param.Add("fontSize", fontSize);
            param.Add("mode", mode);
            param.Add("pool", "0");
            param.Add("plat", "3");
            param.Add("type", "1");
            param.Add("progress", Math.Round(progress).ToString());
            var data     = BiliFactory.UrlContact("", param, true);
            var response = await BiliClient.PostContentToWebAsync(Api.VIDEO_SEND_DANMAKU, data);

            if (!string.IsNullOrEmpty(response))
            {
                var jobj = JObject.Parse(response);
                return(jobj["code"].ToString() == "0");
            }
            return(false);
        }