Beispiel #1
0
        public FavItem(string title, string cover, long info, long id, bool isFolder)
        {
            InitializeComponent();

            IsFolder      = isFolder;
            Id            = id;
            Title         = title;
            TitleBox.Text = title;
            if (isFolder)
            {
                InfoBox.Text = string.Format("{0}个视频", info);
            }
            else
            {
                InfoBox.Text = string.Format("收藏于: {0}", info);
            }

            if (cover != null)
            {
                this.Loaded += async delegate(object senderD, RoutedEventArgs eD)
                {
                    System.Drawing.Bitmap bitmap = await BiliApi.GetImageAsync(cover);

                    ImageBox.Source = BiliApi.BitmapToImageSource(bitmap);
                }
            }
            ;
        }
    }
Beispiel #2
0
        private async ValueTask <EventResult <BaseMsgQuickOperation> > Handler(BaseMessageEventArgs args, IOneBotApi api)
        {
            if (args.RawMessage.Equals(_globalService.BiliSetting.HotCos.Command,
                                       StringComparison.CurrentCultureIgnoreCase))
            {
                var result = await BiliApi.GetCosHotAsync();

                if (result.Any())
                {
                    _logger.LogDebug("{Command}数量:{Count}", _globalService.BiliSetting.HotCos.Command, result.Length);
                    var cqCodes = new List <CQCode>();
                    var tasks   = result.Select(url => Task.Run(async() =>
                    {
                        try
                        {
                            cqCodes.Add(await CQHelper.Image(url, CQFileType.Base64));
                        }
                        catch (Exception e)
                        {
                            _logger.LogWarning("[SendImage]下载图片失败:{Url}\r\nError: {Error}", e.ToString(), url);
                        }
                    }));

                    await Task.WhenAll(tasks);

                    return(1, cqCodes.ToArray());
                }
            }

            return(null);
        }
Beispiel #3
0
        public FavItem(string title, string cover, long info, long id, bool isFolder)
        {
            InitializeComponent();

            IsFolder      = isFolder;
            Id            = id;
            Title         = title;
            TitleBox.Text = title;
            if (isFolder)
            {
                InfoBox.Text = string.Format("{0}个视频", info);
            }
            else
            {
                InfoBox.Text = string.Format("收藏于: {0}", TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddSeconds(info).ToString("yyyy-MM-dd"));
            }

            if (cover != null)
            {
                this.Loaded += async delegate(object senderD, RoutedEventArgs eD)
                {
                    System.Drawing.Bitmap bitmap = await BiliApi.GetImageAsync(cover);

                    ImageBox.Source = BiliApi.BitmapToImageSource(bitmap);
                }
            }
            ;
        }
    }
Beispiel #4
0
 private Json.Value GetRoomLotteries(int roomId)
 {
     Json.Value lottery = BiliApi.GetJsonResult("https://api.live.bilibili.com/xlive/lottery-interface/v1/lottery/Check", new Dictionary <string, string> {
         { "roomid", roomId.ToString() }
     }, false);
     return(lottery);
 }
Beispiel #5
0
 /// <summary>
 /// Get infos of a video/season.
 /// </summary>
 /// <param name="id">Aid/Season-id</param>
 /// <param name="isSeason">IsSeason</param>
 /// <returns>Video info</returns>
 public static VideoInfo GetInfo(uint id, bool isSeason)
 {
     if (!isSeason)
     {
         Dictionary <string, string> dic = new Dictionary <string, string>();
         dic.Add("aid", id.ToString());
         try
         {
             IJson json = BiliApi.GetJsonResult("https://api.bilibili.com/x/web-interface/view", dic, false);
             return(new VideoInfo(json.GetValue("data"), isSeason));
         }
         catch (System.Net.WebException)
         {
             return(null);
         }
     }
     else
     {
         Dictionary <string, string> dic = new Dictionary <string, string>();
         dic.Add("season_id", id.ToString());
         try
         {
             IJson json = BiliApi.GetJsonResult("https://bangumi.bilibili.com/view/web_api/season", dic, false);
             if (json.GetValue("code").ToLong() == 0)
             {
                 return(new VideoInfo(json.GetValue("result"), isSeason));
             }
             return(null);
         }
         catch (System.Net.WebException)
         {
             return(null);
         }
     }
 }
Beispiel #6
0
 private void BiliLoginQR_QRImageLoaded(BiliLoginQR sender, Bitmap qrImage)
 {
     Dispatcher.Invoke(new Action(() =>
     {
         QrImageBox.Source = BiliApi.BitmapToImageSource(qrImage);
     }));
 }
Beispiel #7
0
        public ResultVideo(ResultBox.Video video)
        {
            InitializeComponent();

            Aid   = video.Aid;
            Title = video.Title;

            TitleBox.Inlines.Clear();
            MatchCollection mc = Regex.Matches(video.Title, "(\\<em.*?\\>(?<Word>.*?)\\</em\\>|.)");

            foreach (Match m in mc)
            {
                Inline inline = new Run(m.Value);
                if (m.Value.StartsWith("<"))
                {
                    inline            = new Run(m.Groups["Word"].Value);
                    inline.Foreground = new SolidColorBrush(Color.FromRgb(0xf2, 0x5d, 0x8e));
                }
                else
                {
                    inline = new Run(m.Value);
                }
                TitleBox.Inlines.Add(inline);
            }

            PlayBox.Text     = BiliApi.FormatNum(video.Play, 1);
            PostdateBox.Text = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddSeconds(video.Pubdate).ToString("yyyy-MM-dd");
            AuthorBox.Text   = video.Author;

            ImageBox.Source = new BitmapImage(new Uri(video.Pic));
        }
Beispiel #8
0
        public void LoadAsync()
        {
            if (cancellationTokenSource != null)
            {
                cancellationTokenSource.Cancel();
            }
            ContentViewer.ScrollToHome();
            ContentPanel.Children.Clear();
            cancellationTokenSource = new CancellationTokenSource();
            CancellationToken cancellationToken = cancellationTokenSource.Token;

            LoadingPrompt.Visibility = Visibility.Visible;
            PagesBox.Visibility      = Visibility.Hidden;

            Task task = new Task(() =>
            {
                IJson userinfo = BiliApi.GetJsonResult("https://api.bilibili.com/x/web-interface/nav", null, false);
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }
                if (userinfo.GetValue("code").ToLong() == 0)
                {
                    Dictionary <string, string> dic = new Dictionary <string, string>();
                    dic.Add("mid", userinfo.GetValue("data").GetValue("mid").ToLong().ToString());
                    IJson json = BiliApi.GetJsonResult("https://api.bilibili.com/x/space/fav/nav", dic, false);
                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }
                    if (json.GetValue("code").ToLong() == 0)
                    {
                        Dispatcher.Invoke(new Action(() =>
                        {
                            foreach (IJson folder in json.GetValue("data").GetValue("archive"))
                            {
                                FavItem favItem;
                                if (folder.GetValue("Cover").Contains(0))
                                {
                                    favItem = new FavItem(folder.GetValue("name").ToString(), folder.GetValue("cover").GetValue(0).GetValue("pic").ToString(), folder.GetValue("cur_count").ToLong(), folder.GetValue("media_id").ToLong(), true);
                                }
                                else
                                {
                                    favItem = new FavItem(folder.GetValue("name").ToString(), null, folder.GetValue("cur_count").ToLong(), folder.GetValue("media_id").ToLong(), true);
                                }
                                favItem.PreviewMouseLeftButtonDown += FavItem_PreviewMouseLeftButtonDown;
                                ContentPanel.Children.Add(favItem);
                            }
                        }));
                    }
                }
                Dispatcher.Invoke(new Action(() =>
                {
                    LoadingPrompt.Visibility = Visibility.Hidden;
                }));
            });

            task.Start();
        }
Beispiel #9
0
        private bool Analysis()
        {
            StatusUpdate?.Invoke(ProgressPercentage, 0, Status.Analyzing);
            Segments = new List <Segment>();
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("avid", Aid.ToString());
            dic.Add("cid", Cid.ToString());
            dic.Add("qn", Qn.ToString());
            try
            {
                IJson json = BiliApi.GetJsonResult("https://api.bilibili.com/x/player/playurl", dic, false);
                if (json.GetValue("code").ToLong() == 0)
                {
                    if (json.GetValue("data").GetValue("quality").ToLong() == Qn)
                    {
                        foreach (IJson v in json.GetValue("data").GetValue("durl"))
                        {
                            Segment segment = new Segment(Aid, Regex.Unescape(v.GetValue("url").ToString()), SegmentType.Mixed, v.GetValue("size").ToLong(), Threads);
                            segment.Finished += Segment_Finished;
                            Segments.Add(segment);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    json = BiliApi.GetJsonResult("http://api.bilibili.com/pgc/player/web/playurl", dic, false);
                    if (json.GetValue("code").ToLong() == 0)
                    {
                        if (json.GetValue("result").GetValue("quality").ToLong() == Qn)
                        {
                            foreach (IJson v in json.GetValue("result").GetValue("durl"))
                            {
                                Segment segment = new Segment(Aid, Regex.Unescape(v.GetValue("url").ToString()), SegmentType.Mixed, v.GetValue("size").ToLong(), Threads);
                                segment.Finished += Segment_Finished;
                                Segments.Add(segment);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                return(true);
            }
            catch (WebException)
            {
                return(false);
            }
        }
Beispiel #10
0
        private void ShowFolder(int mediaId, int pagenum, bool init)
        {
            if (cancellationTokenSource != null)
            {
                cancellationTokenSource.Cancel();
            }
            ContentViewer.ScrollToHome();
            ContentPanel.Children.Clear();
            MediaId = mediaId;
            cancellationTokenSource = new CancellationTokenSource();
            CancellationToken cancellationToken = cancellationTokenSource.Token;

            LoadingPrompt.Visibility = Visibility.Visible;
            PagesBox.Visibility      = Visibility.Hidden;

            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("media_id", mediaId.ToString());
            dic.Add("pn", pagenum.ToString());
            dic.Add("ps", "20");
            dic.Add("keyword", "");
            dic.Add("order", "mtime");
            dic.Add("type", "0");
            dic.Add("tid", "0");
            dic.Add("jsonp", "jsonp");
            Task task = new Task(() =>
            {
                IJson json = BiliApi.GetJsonResult("https://api.bilibili.com/medialist/gateway/base/spaceDetail", dic, false);
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }
                if (json.GetValue("code").ToLong() == 0)
                {
                    Dispatcher.Invoke(new Action(() =>
                    {
                        foreach (IJson media in json.GetValue("data").GetValue("medias"))
                        {
                            FavItem favItem = new FavItem(media.GetValue("title").ToString(), media.GetValue("cover").ToString(), media.GetValue("fav_time").ToLong(), media.GetValue("id").ToLong(), false);
                            favItem.PreviewMouseLeftButtonDown += FavItem_PreviewMouseLeftButtonDown;
                            ContentPanel.Children.Add(favItem);
                        }
                        if (init)
                        {
                            PagesBox.SetPage((int)Math.Ceiling((double)json.GetValue("data").GetValue("info").GetValue("media_count").ToLong() / 20), 1, true);
                        }
                        PagesBox.Visibility = Visibility.Visible;
                    }));
                }
                Dispatcher.Invoke(new Action(() =>
                {
                    LoadingPrompt.Visibility = Visibility.Hidden;
                }));
            });

            task.Start();
        }
Beispiel #11
0
        private void FavItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            FavItem favItemSender = (FavItem)sender;

            if (favItemSender.IsFolder)
            {
                if (cancellationTokenSource != null)
                {
                    cancellationTokenSource.Cancel();
                }
                ContentViewer.ScrollToHome();
                ContentPanel.Children.Clear();
                cancellationTokenSource = new CancellationTokenSource();
                CancellationToken cancellationToken = cancellationTokenSource.Token;

                LoadingPrompt.Visibility = Visibility.Visible;

                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("media_id", favItemSender.Id.ToString());
                dic.Add("pn", "1");
                dic.Add("ps", "20");
                dic.Add("keyword", "");
                dic.Add("order", "mtime");
                dic.Add("type", "0");
                dic.Add("tid", "0");
                dic.Add("jsonp", "jsonp");
                Task task = new Task(() =>
                {
                    IJson json = BiliApi.GetJsonResult("https://api.bilibili.com/medialist/gateway/base/spaceDetail", dic, false);
                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }
                    if (json.GetValue("code").ToLong() == 0)
                    {
                        Dispatcher.Invoke(new Action(() =>
                        {
                            foreach (IJson media in json.GetValue("data").GetValue("medias"))
                            {
                                FavItem favItem = new FavItem(media.GetValue("title").ToString(), media.GetValue("cover").ToString(), media.GetValue("fav_time").ToLong(), media.GetValue("id").ToLong(), false);
                                favItem.PreviewMouseLeftButtonDown += FavItem_PreviewMouseLeftButtonDown;
                                ContentPanel.Children.Add(favItem);
                            }
                        }));
                    }
                    Dispatcher.Invoke(new Action(() =>
                    {
                        LoadingPrompt.Visibility = Visibility.Hidden;
                    }));
                });
                task.Start();
            }
            else
            {
                VideoSelected?.Invoke(favItemSender.Title, favItemSender.Id);
            }
        }
Beispiel #12
0
        public void LoadAsync()
        {
            if (cancellationTokenSource != null)
            {
                cancellationTokenSource.Cancel();
            }
            ContentViewer.ScrollToHome();
            ContentPanel.Children.Clear();
            cancellationTokenSource = new CancellationTokenSource();
            CancellationToken cancellationToken = cancellationTokenSource.Token;

            LoadingPromptList.Visibility = Visibility.Visible;
            PagesBox.Visibility          = Visibility.Hidden;

            Task task = new Task(() =>
            {
                Json.Value userinfo = BiliApi.GetJsonResult("https://api.bilibili.com/x/web-interface/nav", null, false);
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }
                if (userinfo["code"] == 0)
                {
                    Dictionary <string, string> dic = new Dictionary <string, string>();
                    dic.Add("pn", "1");
                    dic.Add("ps", "100");
                    dic.Add("up_mid", ((uint)userinfo["data"]["mid"]).ToString());
                    dic.Add("is_space", "0");
                    Json.Value json = BiliApi.GetJsonResult("https://api.bilibili.com/medialist/gateway/base/created", dic, false);
                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }
                    if (json["code"] == 0)
                    {
                        Dispatcher.Invoke(new Action(() =>
                        {
                            foreach (Json.Value folder in json["data"]["list"])
                            {
                                AddFavFolder(new FavFolder(folder["title"], folder["media_count"], folder["id"]));
                            }
                            AddFavFolder(new FavFolder(FavFolder.SpecialFolder.ToView));
                        }));
                    }
                }
                Dispatcher.Invoke(new Action(() =>
                {
                    LoadingPromptList.Visibility = Visibility.Hidden;
                }));
            });

            task.Start();
        }
Beispiel #13
0
        public void LoadAsync(int mid, int page, bool init)
        {
            Mid = mid;
            if (cancellationTokenSource != null)
            {
                cancellationTokenSource.Cancel();
            }
            ContentViewer.ScrollToHome();
            ContentPanel.Children.Clear();
            PagesBox.Visibility = Visibility.Hidden;

            cancellationTokenSource = new CancellationTokenSource();
            CancellationToken cancellationToken = cancellationTokenSource.Token;

            LoadingPrompt.Visibility = Visibility.Visible;
            Task task = new Task(() =>
            {
                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("mid", mid.ToString());
                dic.Add("ps", "30");
                dic.Add("pn", page.ToString());
                try
                {
                    Json.Value json = BiliApi.GetJsonResult("https://api.bilibili.com/x/space/arc/search", dic, true);
                    Dispatcher.Invoke(new Action(() =>
                    {
                        foreach (Json.Value v in json["data"]["list"]["vlist"])
                        {
                            ResultBox.Video video   = new ResultBox.Video(v);
                            ResultVideo resultVideo = new ResultVideo(video);
                            resultVideo.PreviewMouseLeftButtonDown += ResultVideo_PreviewMouseLeftButtonDown;
                            ContentPanel.Children.Add(resultVideo);
                        }
                        if (init)
                        {
                            int pages = (int)Math.Ceiling((double)json["data"]["page"]["count"] / json["data"]["page"]["ps"]);
                            PagesBox.SetPage(pages, 1, true);
                        }
                        PagesBox.Visibility      = Visibility.Visible;
                        LoadingPrompt.Visibility = Visibility.Hidden;
                    }));
                }
                catch (Exception)
                {
                }
                Dispatcher.Invoke(new Action(() =>
                {
                    LoadingPrompt.Visibility = Visibility.Hidden;
                }));
            }, cancellationTokenSource.Token);

            task.Start();
        }
Beispiel #14
0
        public ResultUser(ResultBox.User user)
        {
            InitializeComponent();

            Mid            = user.Mid;
            UnameBox.Text  = user.Uname;
            VideosBox.Text = BiliApi.FormatNum(user.Videos, 1);
            FansBox.Text   = BiliApi.FormatNum(user.Fans, 1);
            UsignBox.Text  = user.Usign;

            ImageBox.Source = new BitmapImage(new Uri(user.Upic));
        }
        public void LoadAsync(int mid, int page, bool init)
        {
            Mid = mid;
            if (cancellationTokenSource != null)
            {
                cancellationTokenSource.Cancel();
            }
            ContentViewer.ScrollToHome();
            ContentPanel.Children.Clear();
            PagesBox.Visibility = Visibility.Hidden;

            cancellationTokenSource = new CancellationTokenSource();
            CancellationToken cancellationToken = cancellationTokenSource.Token;

            LoadingPrompt.Visibility = Visibility.Visible;
            Task task = new Task(() =>
            {
                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("mid", mid.ToString());
                dic.Add("pagesize", "30");
                dic.Add("page", page.ToString());
                try
                {
                    IJson json = BiliApi.GetJsonResult("https://space.bilibili.com/ajax/member/getSubmitVideos", dic, true);
                    Dispatcher.Invoke(new Action(() =>
                    {
                        foreach (IJson v in json.GetValue("data").GetValue("vlist"))
                        {
                            ResultBox.Video video   = new ResultBox.Video(v);
                            ResultVideo resultVideo = new ResultVideo(video);
                            resultVideo.PreviewMouseLeftButtonDown += ResultVideo_PreviewMouseLeftButtonDown;
                            ContentPanel.Children.Add(resultVideo);
                        }
                        if (init)
                        {
                            PagesBox.SetPage((int)json.GetValue("data").GetValue("pages").ToLong(), 1, true);
                        }
                        PagesBox.Visibility      = Visibility.Visible;
                        LoadingPrompt.Visibility = Visibility.Hidden;
                    }));
                }
                catch (Exception)
                {
                }
                Dispatcher.Invoke(new Action(() =>
                {
                    LoadingPrompt.Visibility = Visibility.Hidden;
                }));
            }, cancellationTokenSource.Token);

            task.Start();
        }
Beispiel #16
0
        public SuggestItemUser(SearchBox.UserSuggest userSuggest)
        {
            InitializeComponent();

            if (TitleInline.Text != null)
            {
                TitleInline.Text = userSuggest.Title;
            }

            FansInline.Text = string.Format("{0:0}粉丝", BiliApi.FormatNum(userSuggest.Fans, 1)).PadRight(10, ' ');

            ArchivesInline.Text = string.Format("{0:0}个视频", BiliApi.FormatNum(userSuggest.Archives, 1));

            ImageBox.Source = new BitmapImage(new Uri(userSuggest.Cover));
        }
Beispiel #17
0
        public ResultSeason(ResultBox.Season season)
        {
            InitializeComponent();

            SeasonId = season.SeasonId;
            Title    = season.Title;

            TypeBox.Text = season.SeasonTypeName;

            TitleBox.Inlines.Clear();
            MatchCollection mc;

            if (season.Title != null && season.Title != "")
            {
                mc = Regex.Matches(season.Title, "(\\<em.*?\\>(?<Word>.*?)\\</em\\>|.)");
            }
            else
            {
                mc = Regex.Matches(season.OrgTitle, "(\\<em.*?\\>(?<Word>.*?)\\</em\\>|.)");
            }
            foreach (Match m in mc)
            {
                Inline inline = new Run(m.Value);
                if (m.Value.StartsWith("<"))
                {
                    inline            = new Run(m.Groups["Word"].Value);
                    inline.Foreground = new SolidColorBrush(Color.FromRgb(0xf2, 0x5d, 0x8e));
                }
                else
                {
                    inline = new Run(m.Value);
                }
                TitleBox.Inlines.Add(inline);
            }

            StylesBox.Text      = season.Styles;
            AreasBox.Text       = season.Areas;
            PubtimeBox.Text     = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddSeconds(season.Pubtime).ToString("yyyy-MM-dd");
            CvBox.Text          = season.Cv.Replace('\n', ' ');
            DescriptionBox.Text = season.Description.Replace('\n', ' ');

            this.Loaded += async delegate(object senderD, RoutedEventArgs eD)
            {
                System.Drawing.Bitmap bitmap = await season.GetCoverAsync();

                ImageBox.Source = BiliApi.BitmapToImageSource(bitmap);
            };
        }
Beispiel #18
0
        private async void ShowUserInfo(UserInfo userInfo)
        {
            ShowFavoritesBtn.Visibility = Visibility.Visible;

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(userInfo.Uname);
            stringBuilder.Append(string.Format(" [Lv.{0}]", userInfo.CurrentLevel));
            if (userInfo.VipStatus > 0)
            {
                stringBuilder.Append(" [大会员]");
            }
            UserInfoBox.Text = stringBuilder.ToString();

            UserFaceImage.Source = BiliApi.BitmapToImageSource(await userInfo.GetFaceBitmapAsync());
        }
Beispiel #19
0
        public ResultUser(ResultBox.User user)
        {
            InitializeComponent();

            Mid            = user.Mid;
            UnameBox.Text  = user.Uname;
            VideosBox.Text = BiliApi.FormatNum(user.Videos, 1);
            FansBox.Text   = BiliApi.FormatNum(user.Fans, 1);
            UsignBox.Text  = user.Usign;

            this.Loaded += async delegate(object senderD, RoutedEventArgs eD)
            {
                System.Drawing.Bitmap bitmap = await user.GetPicAsync();

                ImageBox.Source = BiliApi.BitmapToImageSource(bitmap);
            };
        }
Beispiel #20
0
        private List <Suggest> GetSuggest(string text)
        {
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("highlight", "1");
            dic.Add("keyword", text);
            try
            {
                IJson json = BiliApi.GetJsonResult("https://app.bilibili.com/x/v2/search/suggest3", dic, true);

                if (json.GetValue("data").Contains("list"))
                {
                    List <Suggest> suggests = new List <Suggest>();
                    foreach (IJson i in json.GetValue("data").GetValue("list"))
                    {
                        if (!i.Contains("sug_type"))
                        {
                            Suggest suggest = new Suggest(i);
                            suggests.Add(suggest);
                        }
                        else if (i.GetValue("sug_type").ToString() == "pgc")
                        {
                            SeasonSuggest seasonSuggest = new SeasonSuggest(i);
                            suggests.Add(seasonSuggest);
                        }
                        else if (i.GetValue("sug_type").ToString() == "user")
                        {
                            UserSuggest userSuggest = new UserSuggest(i);
                            suggests.Add(userSuggest);
                        }
                        else
                        {
                            Suggest suggest = new Suggest(i);
                            suggests.Add(suggest);
                        }
                    }
                    suggests.Sort((x, y) => x.Position.CompareTo(y.Position));
                    return(suggests);
                }
                return(null);
            }
            catch (WebException)
            {
                return(null);
            }
        }
Beispiel #21
0
                public Quality(string title, string index, uint num, string part, uint aid, uint cid, uint qn, string description, bool seasonApiOnly, string pic)
                {
                    SeasonApiOnly = seasonApiOnly;
                    Title         = title;
                    Index         = index;
                    Num           = num;
                    Part          = part;
                    Aid           = aid;
                    Cid           = cid;
                    Qn            = qn;
                    Description   = description;
                    Pic           = pic;
                    MergeRequired = true;

                    Dictionary <string, string> dic = new Dictionary <string, string>
                    {
                        { "avid", Aid.ToString() },
                        { "cid", Cid.ToString() },
                        { "qn", Qn.ToString() }
                    };

                    //dic.Add("fnval", "16");
                    try
                    {
                        if (!seasonApiOnly)
                        {
                            Json.Value json = BiliApi.GetJsonResult("https://api.bilibili.com/x/player/playurl", dic, false);
                            IsAvaliable = json["data"]["quality"] == Qn;

                            if (IsAvaliable && !((string)json["data"]["format"]).Contains("flv"))
                            {
                                IsAvaliable   = json["data"]["durl"].Count == 1;
                                MergeRequired = false;
                            }
                        }
                        else
                        {
                            Json.Value json = BiliApi.GetJsonResult("http://api.bilibili.com/pgc/player/web/playurl", dic, false);
                            IsAvaliable = json["result"]["format"] == Qn;
                        }
                    }
                    catch (System.Net.WebException)
                    {
                        IsAvaliable = false;
                    }
                }
Beispiel #22
0
 private int[] GetAreaIds()
 {
     Json.Value list = BiliApi.GetJsonResult("https://api.live.bilibili.com/room/v1/Area/getList", null, false);
     if (list["code"] == 0)
     {
         List <int> ids = new List <int>();
         foreach (Json.Value area in list["data"])
         {
             ids.Add(area["id"]);
         }
         return(ids.ToArray());
     }
     else
     {
         AppendLog($"error >> {list["message"]}");
         return(new int[] { 0 });
     }
 }
Beispiel #23
0
 private List <GiftBag> GetBagList()
 {
     Json.Value bagList = BiliApi.GetJsonResult("https://api.live.bilibili.com/xlive/web-room/v1/gift/bag_list", null, false);
     if (bagList["code"] == 0)
     {
         List <GiftBag> giftBags = new List <GiftBag>();
         foreach (Json.Value bag in bagList["data"]["list"])
         {
             giftBags.Add(new GiftBag(bag));
         }
         return(giftBags);
     }
     else
     {
         AppendLog($"error >> {bagList["message"]}");
         return(null);
     }
 }
Beispiel #24
0
 public static UserInfo GetUserInfo(CookieCollection cookies)
 {
     try
     {
         Json.Value json = BiliApi.GetJsonResult("https://account.bilibili.com/home/userInfo", null, false);
         if (json["code"] == 0)
         {
             return(new UserInfo(json));
         }
         else
         {
             return(null);
         }
     }
     catch (WebException)
     {
         return(null);
     }
 }
Beispiel #25
0
        private IJson GetResult(string text, string type)
        {
            SearchText = text;
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("jsonp", "jsonp");
            dic.Add("highlight", "1");
            dic.Add("search_type", type);
            dic.Add("keyword", text);
            try
            {
                IJson json = BiliApi.GetJsonResult("https://api.bilibili.com/x/web-interface/search/type", dic, true);
                return(json);
            }
            catch (System.Net.WebException)
            {
                return(null);
            }
        }
Beispiel #26
0
        private Json.Value GetResult(string text, string type, int pagenum)
        {
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("jsonp", "jsonp");
            dic.Add("highlight", "1");
            dic.Add("search_type", type);
            dic.Add("keyword", text);
            dic.Add("page", pagenum.ToString());
            try
            {
                Json.Value json = BiliApi.GetJsonResult("https://api.bilibili.com/x/web-interface/search/type", dic, true);
                return(json);
            }
            catch (System.Net.WebException)
            {
                return(null);
            }
        }
Beispiel #27
0
 /// <summary>
 /// Get infos of a video/season.
 /// </summary>
 /// <param name="id">Aid/Season-id</param>
 /// <param name="isSeason">IsSeason</param>
 /// <returns>Video info</returns>
 public static VideoInfo GetInfo(uint id, bool isSeason)
 {
     if (!isSeason)
     {
         Dictionary <string, string> dic = new Dictionary <string, string>
         {
             { "aid", id.ToString() }
         };
         try
         {
             Json.Value json = BiliApi.GetJsonResult("https://api.bilibili.com/x/web-interface/view", dic, false);
             if (json["code"] == 0)
             {
                 return(new VideoInfo(json["data"], isSeason));
             }
             return(null);
         }
         catch (System.Net.WebException)
         {
             return(null);
         }
     }
     else
     {
         Dictionary <string, string> dic = new Dictionary <string, string>
         {
             { "season_id", id.ToString() }
         };
         try
         {
             Json.Value json = BiliApi.GetJsonResult("https://bangumi.bilibili.com/view/web_api/season", dic, false);
             if (json["code"] == 0)
             {
                 return(new VideoInfo(json["result"], isSeason));
             }
             return(null);
         }
         catch (System.Net.WebException)
         {
             return(null);
         }
     }
 }
Beispiel #28
0
        public SuggestItemUser(SearchBox.UserSuggest userSuggest)
        {
            InitializeComponent();

            if (TitleInline.Text != null)
            {
                TitleInline.Text = userSuggest.Title;
            }

            FansInline.Text = string.Format("{0:0}粉丝", BiliApi.FormatNum(userSuggest.Fans, 1)).PadRight(10, ' ');

            ArchivesInline.Text = string.Format("{0:0}个视频", BiliApi.FormatNum(userSuggest.Archives, 1));

            this.Loaded += async delegate(object senderD, RoutedEventArgs eD)
            {
                System.Drawing.Bitmap bitmap = await userSuggest.GetCoverAsync();

                ImageBox.Source = BiliApi.BitmapToImageSource(bitmap);
            };
        }
Beispiel #29
0
        public async static Task <UserInfo> GetUserInfoAsync(CookieCollection cookies)
        {
            try
            {
                IJson json = await BiliApi.GetJsonResultAsync("https://account.bilibili.com/home/userInfo", null, false);

                if (json.GetValue("code").ToLong() == 0)
                {
                    return(new UserInfo(json));
                }
                else
                {
                    return(null);
                }
            }
            catch (WebException)
            {
                return(null);
            }
        }
Beispiel #30
0
        public async static Task <UserInfo> GetUserInfoAsync(CookieCollection cookies)
        {
            try
            {
                Json.Value json = await BiliApi.GetJsonResultAsync("http://api.bilibili.com/nav", null, false);

                if (json["code"] == 0)
                {
                    return(new UserInfo(json));
                }
                else
                {
                    return(null);
                }
            }
            catch (WebException)
            {
                return(null);
            }
        }