public async Task <DplayerWebResult> Get([FromQuery] BiliBiliQuery query) { HttpContext.Request.Headers["Accept"] = "application/json"; var result = await Bilibili.GetDanmuAsync(query); return(new DplayerWebResult(result.ToDanmuDataBases().ToArray())); }
public async Task <dynamic> Get(int cid, int aid, int p, string format) { string[] date = Request.Query["date"]; if (date.Length == 0 && !(!string.IsNullOrEmpty(format) && format.Equals("json"))) { if (cid == 0 && aid != 0) { p = p == 0 ? 1 : p; cid = await Bilibili.GetCidAsync(aid, p); } HttpContext.Response.ContentType = "application/xml; charset=utf-8"; return(await Bilibili.GetDanmuRawByCidTask(cid)); } var danmu = await Bilibili.GetDanmuAsync(cid, aid, p, date); if (!string.IsNullOrEmpty(format) && format.Equals("json")) { return(new WebResult <IEnumerable <BaseDanmuData> >(danmu.ToDanmuDataBases())); } if (string.IsNullOrEmpty(format)) { HttpContext.Request.Headers["Accept"] = "application/xml"; } return(danmu); }
public void BilibiliTest() { Channel channle = new Bilibili(videoPath, coverPath, new string[] { "123", "321" }, title, introduction, null, null); channle.Operate(); Console.ReadLine(); }
public async Task <DplayerWebResult> Get(int cid, int aid, int p) { string[] date = Request.Query["date"]; HttpContext.Request.Headers["Accept"] = "application/json"; var result = await Bilibili.GetDanmuAsync(cid, aid, p, date); return(new DplayerWebResult(result.ToDanmuDataBases().ToArray())); }
public static async Task <bool> ShamWatchVideo(long av, string cookie) { var jct = Bilibili.GetJCT(cookie); var cookies = CookieParse.Matches(cookie.Replace(" ", string.Empty)); var uid = cookies.Where(x => x.Groups["key"].Value == "DedeUserID").FirstOrDefault()?.Groups["value"].Value; var sid = cookies.Where(x => x.Groups["key"].Value == "DedeUserID__ckMd5").FirstOrDefault()?.Groups["value"].Value; var video = Video.Get(av); var referer = "https://www.bilibili.com/video/av" + av; var time = Utils.GetTimeStamp(); var param = new Dictionary <string, object>() { { "aid", video.AV }, { "cid", video.CID }, { "part", 1 }, { "did", sid }, { "mid", uid }, { "csrf", jct }, { "jsonp", "jsonp" }, { "ftime", time }, { "stime", time } }; var result = JObject.Parse(Utils.HttpPOST("https://api.bilibili.com/x/report/click/h5", Utils.ToUrlParameter(param), 5000, cookie, referer)); if ((int)result["code"] == 0) { param = new Dictionary <string, object>() { { "aid", video.AV }, { "cid", video.CID }, { "did", sid }, { "mid", uid }, { "csrf", jct }, { "played_time", 0 }, { "realtime", video.Duration.TotalSeconds }, { "pause", "false" }, { "dt", 7 }, { "play_type", 1 }, { "jsonp", "jsonp" }, { "start_ts", Utils.GetTimeStamp() } }; result = JObject.Parse(Utils.HttpPOST("https://api.bilibili.com/x/report/web/heartbeat", Utils.ToUrlParameter(param), 5000, cookie, referer)); if ((int)result["code"] == 0) { await Task.Delay(5000); param["played_time"] = video.Duration.TotalSeconds - 1; param["play_type"] = 0; param["start_ts"] = Utils.GetTimeStamp(); result = JObject.Parse(Utils.HttpPOST("https://api.bilibili.com/x/report/web/heartbeat", Utils.ToUrlParameter(param), 5000, cookie, referer)); return((int)result["code"] == 0); } } return(false); }
public async Task <dynamic> Get([FromQuery] BiliBiliQuery query, string format) { var danmu = await Bilibili.GetDanmuAsync(query); if (!string.IsNullOrEmpty(format) && format.Equals("json")) { return(new WebResult <IEnumerable <ArtPlayerDanmuData> >(danmu .Select(s => (ArtPlayerDanmuData)s))); } if (string.IsNullOrEmpty(format)) { HttpContext.Request.Headers["Accept"] = "application/xml"; } return(danmu); }
public async Task <WebResult> QueryAid(string bvid, int?aid) { var a = await Bilibili.GetBvidInfoAsync(bvid, aid ?? 0); return(a?.Code == 0 ? new WebResult(0) { Data = new { a.Data.Aid, a.Data.Bvid, PageList = (await Bilibili.GetBiliBiliPageAsync(a.Data.Bvid)).Data } } : new WebResult(1)); }
public async Task <bool> ExecuteAsync(TelegramBotClient botClient, Update update) { ChatId chatId = update.Message.From.Id; var vlist = await Bilibili.GetSpacePage(1, 1); foreach (var v in vlist) { //Console.WriteLine(t.ToString()); await botClient.SendTextMessageAsync( chatId, $"{v["author"]}的最新视频:\n" + $"{v["title"]}\n" + $"https://www.bilibili.com/video/{v["bvid"]}" ); } return(true); }
public async Task <dynamic> Get([FromQuery] BiliBiliQuery query, string format) { if (query.Date.Length == 0 && !(!string.IsNullOrEmpty(format) && format.Equals("json"))) { HttpContext.Response.ContentType = "application/xml; charset=utf-8"; return(await Bilibili.GetDanmuRawByQueryAsync(query)); } var danmu = await Bilibili.GetDanmuAsync(query); if (!string.IsNullOrEmpty(format) && format.Equals("json")) { return(new WebResult <IEnumerable <BaseDanmuData> >(danmu.ToDanmuDataBases())); } if (string.IsNullOrEmpty(format)) { HttpContext.Request.Headers["Accept"] = "application/xml"; } return(danmu); }
public static string PutCoin(long av, string cookie) { string jct = Bilibili.GetJCT(cookie); string param = string.Join("&", "aid=" + av, "multiply=1", "select_like=1", "cross_domain=true", "csrf=" + jct); var data = JObject.Parse(Utils.HttpPOST("https://api.bilibili.com/x/web-interface/coin/add", param, 5000, cookie, "https://www.bilibili.com/video/av" + av)); if ((int)data["code"] == 0) { return("投币成功"); } else { throw new Exception((string)data["message"]); } }
public static string Like(ulong id, bool like, string cookie) { string jct = Bilibili.GetJCT(cookie); if (int.TryParse(cookie.Split(";").Where(x => x.StartsWith("DedeUserID=")).First().Substring(11), out var uid)) { string param = string.Join("&", "uid=" + uid, "dynamic_id=" + id, "up=" + (like ? 1 : 2), "csrf_token=" + jct); var data = JObject.Parse(Utils.HttpPOST("https://api.vc.bilibili.com/dynamic_like/v1/dynamic_like/thumb", param, 5000, cookie)); if ((int)data["code"] == 0) { return("操作执行成功"); } else { throw new Exception((string)data["message"]); } } throw new Exception("异常的账户数据记录,请重新登录"); }
public async Task <bool> ExecuteAsync(TelegramBotClient botClient, Update update) { ChatId chatId = update.Message.From.Id; string uid = "490751924"; try { string rawFollower = await Networking.MakeHttpRequestAsync($"http://api.bilibili.com/x/relation/stat?vmid={uid}"); JObject jsonFollowerObj = JObject.Parse(rawFollower); string strFollower = jsonFollowerObj["data"]["follower"].ToString(); string rawUpStat = await Networking.MakeHttpRequestAsync( $"https://api.bilibili.com/x/space/upstat?mid={uid}&jsonp=jsonp"); JObject rawUpStatObj = JObject.Parse(rawUpStat); // string strView = jsonSpaceObj["data"]["archive"]["view"].ToString(); // string strLikes = rawUpStatObj["data"]?["likes"]?.ToString(); // TODO : Refactor viewer counter. //////////////////////////////// Viewer counter. To be refactored. //////////////////////////// var playCount = 0; var coinCount = 0; var likeCount = 0; var favCount = 0; var shareCount = 0; var pageSize = 20; var pageNo = 1; Console.WriteLine($"Init: {Vars.Stopwatch.Elapsed.ToString()}"); for (;; pageNo++) { var vlist = await Bilibili.GetSpacePage(100, pageNo); if (vlist.Count == 0) { break; } foreach (var t in vlist) { try { playCount += int.Parse(t["play"].ToString()); // play counter string bvid = t["bvid"].ToString(); try { string rawVideo = await Networking.MakeHttpRequestAsync( $"https://api.bilibili.com/x/web-interface/view?bvid={bvid}"); JObject jsonVideoObj = JObject.Parse(rawVideo); // Console.WriteLine(jsonVideoObj["data"]["stat"]["coin"].ToString()); coinCount += int.Parse(jsonVideoObj["data"]["stat"]["coin"].ToString()); // coin counter likeCount += int.Parse(jsonVideoObj["data"]["stat"]["like"].ToString()); // coin counter favCount += int.Parse(jsonVideoObj["data"]["stat"]["favorite"] .ToString()); // favourite counter. shareCount += int.Parse(jsonVideoObj["data"]["stat"]["share"].ToString()); // share counter. } catch (HttpRequestException e) { Console.WriteLine(e); throw; } } catch (Exception e) { Console.WriteLine(e); throw; } } } //Console.WriteLine(videoArray.ToString()); Console.WriteLine($"pageNo: {pageNo}"); Console.WriteLine($"playCount: {playCount}"); Console.WriteLine($"likeCount: {likeCount}"); Console.WriteLine($"coinCount: {coinCount}"); Console.WriteLine($"favCount: {favCount}"); Console.WriteLine($"shareCount: {shareCount}"); Console.WriteLine(); Console.WriteLine($"After crawling: {Vars.Stopwatch.Elapsed.ToString()}"); Console.WriteLine(); ///////////////////////////////////////// End of viewer counter ///////////////////////////////////// //Console.WriteLine(videoArray.ToString()); // Console.WriteLine(playCount); await botClient.SendTextMessageAsync(chatId, $"👀 关注: {strFollower}\n" + $"▶️ 播放: {playCount}\n" + $"👍 点赞: {likeCount}\n" + $"💰 投币: {coinCount}\n" + $"🌟 收藏: {favCount}\n" + $"↪️ 转发: {shareCount}\n"); } catch (Exception exception) { Console.WriteLine(exception); throw; } return(true); }
public async Task <TrackResult> QueueSong(string n, CommandContext ctx, int pos = -1) { var queue = await Database.GetQueue(ctx.Guild); var inter = ctx.Client.GetInteractivity(); if (n.ToLower().StartsWith("http://nicovideo.jp") || n.ToLower().StartsWith("http://sp.nicovideo.jp") || n.ToLower().StartsWith("https://nicovideo.jp") || n.ToLower().StartsWith("https://sp.nicovideo.jp") || n.ToLower().StartsWith("http://www.nicovideo.jp") || n.ToLower().StartsWith("https://www.nicovideo.jp")) { var msg = await ctx.RespondAsync("Processing NND Video..."); var split = n.Split("/".ToCharArray()); var nndID = split.First(x => x.StartsWith("sm") || x.StartsWith("nm")).Split("?")[0]; FtpClient client = new(Bot.cfg.NndConfig.FtpConfig.Hostname, new NetworkCredential(Bot.cfg.NndConfig.FtpConfig.User, Bot.cfg.NndConfig.FtpConfig.Password)); await client.ConnectAsync(); if (!await client.FileExistsAsync($"{nndID}.mp3")) { await msg.ModifyAsync("Preparing download..."); var ex = await Utilities.NND.GetNND(nndID, msg); if (ex == null) { await msg.ModifyAsync("Please try again or verify the link"); return(null); } await msg.ModifyAsync("Uploading"); await client.UploadAsync(ex, $"{nndID}.mp3", FtpRemoteExists.Skip, true); } var Track = await nodeConnection.Rest.GetTracksAsync(new Uri($"https://nnd.meek.moe/new/{nndID}.mp3")); if (pos == -1) { await Database.AddToQueue(ctx.Guild, ctx.Member.Id, Track.Tracks.First().TrackString); } else { await Database.InsertToQueue(ctx.Guild, ctx.Member.Id, Track.Tracks.First().TrackString, pos); } if (guildConnection.IsConnected && (playstate == Playstate.NotPlaying || playstate == Playstate.Stopped)) { await PlaySong(); } return(new TrackResult(Track.PlaylistInfo, Track.Tracks.First())); } else if (n.ToLower().StartsWith("https://www.bilibili.com") || n.ToLower().StartsWith("http://www.bilibili.com")) { var msg = await ctx.RespondAsync("Processing Bilibili Video..."); var split = n.Split("/".ToCharArray()); var nndID = split.First(x => x.StartsWith("anime") || x.StartsWith("av")).Split("?")[0]; FtpClient client = new(Bot.cfg.NndConfig.FtpConfig.Hostname, new NetworkCredential(Bot.cfg.NndConfig.FtpConfig.User, Bot.cfg.NndConfig.FtpConfig.Password)); await client.ConnectAsync(); if (!await client.FileExistsAsync($"{nndID}.mp3")) { await msg.ModifyAsync("Preparing download..."); var ex = await Bilibili.GetBilibili(nndID, msg); if (ex == null) { await msg.ModifyAsync("Please try again or verify the link"); return(null); } await msg.ModifyAsync("Uploading"); await client.UploadAsync(ex, $"{nndID}.mp3", FtpRemoteExists.Skip, true); } var Track = await nodeConnection.Rest.GetTracksAsync(new Uri($"https://nnd.meek.moe/new/{nndID}.mp3")); if (pos == -1) { await Database.AddToQueue(ctx.Guild, ctx.Member.Id, Track.Tracks.First().TrackString); } else { await Database.InsertToQueue(ctx.Guild, ctx.Member.Id, Track.Tracks.First().TrackString, pos); } if (guildConnection.IsConnected && (playstate == Playstate.NotPlaying || playstate == Playstate.Stopped)) { await PlaySong(); } return(new TrackResult(Track.PlaylistInfo, Track.Tracks.First())); } else if (n.StartsWith("http://") | n.StartsWith("https://")) { var s = await nodeConnection.Rest.GetTracksAsync(new Uri(n)); switch (s.LoadResultType) { case LavalinkLoadResultType.LoadFailed: { await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Failed to load").WithDescription("Loading this song/playlist failed, please try again, reasons could be:\n" + "> Playlist is set to private or unlisted\n" + "> The song is unavailable/deleted").Build()); return(null); }; case LavalinkLoadResultType.NoMatches: { await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Failed to load").WithDescription("No song/playlist was found with this URL, please try again/a different one").Build()); return(null); }; case LavalinkLoadResultType.PlaylistLoaded: { if (s.PlaylistInfo.SelectedTrack == -1) { var msg = await ctx.RespondAsync(embed : new DiscordEmbedBuilder() .WithTitle("Playlist link detected!") .WithDescription("Please respond with either:\n" + "``yes``, ``y`` or ``1`` to add the **entire** playlist or\n" + "``no``, ``n``, ``0`` or let this time out to cancel") .WithAuthor($"Requested by {ctx.Member.Username}#{ctx.Member.Discriminator} || Timeout 25 seconds", iconUrl : ctx.Member.AvatarUrl) .Build()); var resp = await inter.WaitForMessageAsync(x => x.Author.Id == ctx.User.Id, TimeSpan.FromSeconds(25)); await msg.DeleteAsync(); if (resp.TimedOut) { return(null); } if (resp.Result.Content == "y" || resp.Result.Content == "yes" || resp.Result.Content == "1") { await Database.AddToQueue(ctx.Guild, ctx.Member.Id, s.Tracks.ToList()); if (guildConnection.IsConnected && (playstate == Playstate.NotPlaying || playstate == Playstate.Stopped)) { await PlaySong(); } return(new TrackResult(s.PlaylistInfo, s.Tracks)); } else { return(null); } } else { var msg = await ctx.RespondAsync(embed : new DiscordEmbedBuilder() .WithTitle("Link with Playlist detected!") .WithDescription("Please respond with either:\n" + "``yes``, ``y`` or ``1`` to add only the referred song in the link or\n" + "``all`` or ``a`` to add the entire playlistor\n" + "``no``, ``n``, ``0`` or let this time out to cancel") .WithAuthor($"Requested by {ctx.Member.Username}#{ctx.Member.Discriminator} || Timeout 25 seconds", iconUrl : ctx.Member.AvatarUrl) .Build()); var resp = await inter.WaitForMessageAsync(x => x.Author.Id == ctx.User.Id, TimeSpan.FromSeconds(25)); await msg.DeleteAsync(); if (resp.TimedOut) { return(null); } if (resp.Result.Content == "y" || resp.Result.Content == "yes" || resp.Result.Content == "1") { if (pos == -1) { await Database.AddToQueue(ctx.Guild, ctx.Member.Id, s.Tracks.ElementAt(s.PlaylistInfo.SelectedTrack).TrackString); } else { await Database.InsertToQueue(ctx.Guild, ctx.Member.Id, s.Tracks.ElementAt(s.PlaylistInfo.SelectedTrack).TrackString, pos); } if (guildConnection.IsConnected && (playstate == Playstate.NotPlaying || playstate == Playstate.Stopped)) { await PlaySong(); } return(new TrackResult(s.PlaylistInfo, s.Tracks.ElementAt(s.PlaylistInfo.SelectedTrack))); } if (resp.Result.Content == "a" || resp.Result.Content == "all") { if (pos == -1) { await Database.AddToQueue(ctx.Guild, ctx.Member.Id, s.Tracks.ToList()); } else { await Database.InsertToQueue(ctx.Guild, ctx.Member.Id, s.Tracks.Reverse().ToList(), pos); } if (guildConnection.IsConnected && (playstate == Playstate.NotPlaying || playstate == Playstate.Stopped)) { await PlaySong(); } return(new TrackResult(s.PlaylistInfo, s.Tracks)); } else { return(null); } } }; default: { if (pos == -1) { await Database.AddToQueue(ctx.Guild, ctx.Member.Id, s.Tracks.First().TrackString); } else { await Database.InsertToQueue(ctx.Guild, ctx.Member.Id, s.Tracks.First().TrackString, pos); } if (guildConnection.IsConnected && (playstate == Playstate.NotPlaying || playstate == Playstate.Stopped)) { await PlaySong(); } return(new TrackResult(s.PlaylistInfo, s.Tracks.First())); }; } } else { var s = await nodeConnection.Rest.GetTracksAsync(n); switch (s.LoadResultType) { case LavalinkLoadResultType.LoadFailed: { await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Failed to load").WithDescription("Loading this song/playlist failed, please try again, reason could be:\n" + "> The song is unavailable/deleted").Build()); return(null); }; case LavalinkLoadResultType.NoMatches: { await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithTitle("Failed to load").WithDescription("No song was found, please try again").Build()); return(null); }; default: { var em = new DiscordEmbedBuilder() .WithTitle("Results!") .WithDescription("Please select a track by responding to this with:\n") .WithAuthor($"Requested by {ctx.Member.Username}#{ctx.Member.Discriminator} || Timeout 25 seconds", iconUrl: ctx.Member.AvatarUrl); int leng = s.Tracks.Count(); if (leng > 5) { leng = 5; } for (int i = 0; i < leng; i++) { em.AddField($"{i + 1}.{s.Tracks.ElementAt(i).Title} [{s.Tracks.ElementAt(i).Length}]", $"by {s.Tracks.ElementAt(i).Author} [Link]({s.Tracks.ElementAt(i).Uri})"); } var msg = await ctx.RespondAsync(embed : em.Build()); var resp = await inter.WaitForMessageAsync(x => x.Author.Id == ctx.User.Id, TimeSpan.FromSeconds(25)); await msg.DeleteAsync(); if (resp.TimedOut) { return(null); } if (resp.Result.Content == "1") { if (pos == -1) { await Database.AddToQueue(ctx.Guild, ctx.Member.Id, s.Tracks.ElementAt(0).TrackString); } else { await Database.InsertToQueue(ctx.Guild, ctx.Member.Id, s.Tracks.ElementAt(0).TrackString, pos); } if (guildConnection.IsConnected && (playstate == Playstate.NotPlaying || playstate == Playstate.Stopped)) { await PlaySong(); } return(new TrackResult(s.PlaylistInfo, s.Tracks.ElementAt(0))); } if (resp.Result.Content == "2") { if (pos == -1) { await Database.AddToQueue(ctx.Guild, ctx.Member.Id, s.Tracks.ElementAt(1).TrackString); } else { await Database.InsertToQueue(ctx.Guild, ctx.Member.Id, s.Tracks.ElementAt(1).TrackString, pos); } if (guildConnection.IsConnected && (playstate == Playstate.NotPlaying || playstate == Playstate.Stopped)) { await PlaySong(); } return(new TrackResult(s.PlaylistInfo, s.Tracks.ElementAt(1))); } if (resp.Result.Content == "3") { if (pos == -1) { await Database.AddToQueue(ctx.Guild, ctx.Member.Id, s.Tracks.ElementAt(2).TrackString); } else { await Database.InsertToQueue(ctx.Guild, ctx.Member.Id, s.Tracks.ElementAt(2).TrackString, pos); } if (guildConnection.IsConnected && (playstate == Playstate.NotPlaying || playstate == Playstate.Stopped)) { await PlaySong(); } return(new TrackResult(s.PlaylistInfo, s.Tracks.ElementAt(2)));; } if (resp.Result.Content == "4") { if (pos == -1) { await Database.AddToQueue(ctx.Guild, ctx.Member.Id, s.Tracks.ElementAt(3).TrackString); } else { await Database.InsertToQueue(ctx.Guild, ctx.Member.Id, s.Tracks.ElementAt(3).TrackString, pos); } if (guildConnection.IsConnected && (playstate == Playstate.NotPlaying || playstate == Playstate.Stopped)) { await PlaySong(); } return(new TrackResult(s.PlaylistInfo, s.Tracks.ElementAt(3))); } if (resp.Result.Content == "5") { if (pos == -1) { await Database.AddToQueue(ctx.Guild, ctx.Member.Id, s.Tracks.ElementAt(4).TrackString); } else { await Database.InsertToQueue(ctx.Guild, ctx.Member.Id, s.Tracks.ElementAt(4).TrackString, pos); } if (guildConnection.IsConnected && (playstate == Playstate.NotPlaying || playstate == Playstate.Stopped)) { await PlaySong(); } return(new TrackResult(s.PlaylistInfo, s.Tracks.ElementAt(4))); } else { return(null); } }; } } }