Ejemplo n.º 1
0
        private async void FavVideoGridView_ItemClick(object sender, ItemClickEventArgs e)
        {
            if ((e.ClickedItem as FavVideoViewModel).Bv == "加载更多")
            {
                var vm = FavListView.SelectedItem as FavViewModel;
                await vm.GetMoreVideoAsync();
            }
            else if (!Regex.IsMatch((e.ClickedItem as FavVideoViewModel).Bv, "[B|b][V|v][0-9]*"))
            {
                return;
            }
            else
            {
                try
                {
                    var info   = e.ClickedItem as FavVideoViewModel;
                    var master = await BiliVideoHelper.GetVideoMasterAsync(info.Bv, Settings.SESSDATA);

                    NavigationHelper.NavigateToPage(ContentPage.Search);
                    SearchPage.Current.HandleMaster <BiliVideoMasterResultPage, BiliVideoMaster>(master);
                }
                catch (ParsingVideoException)
                {
                    var dialog = new NoticeDialog("提示", "该视频已失效");
                    await dialog.ShowAsync();
                }
                catch (Exception ex)
                {
                    _logger.Info(ex, ex.Message);
                }
            }
        }
        private async void SearchBtn_Click(object sender, RoutedEventArgs e)
        {
            var searchContent = SearchTextBox.Text;

            if (string.IsNullOrWhiteSpace(searchContent))
            {
                return;
            }

            var result = AnalyzeUrl(searchContent);

            if (string.IsNullOrWhiteSpace(result.Item2))//输入了无效的url
            {
                ShowNoticeFlyout("输入了无效的url");
                return;
            }
            SearchProgress();
            try
            {
                switch (result.Item1)
                {
                case UrlType.Bv:
                    var video1 = await BiliVideoHelper.GetVideoMasterAsync(result.Item2, Settings.SESSDATA);

                    SearchPage.Current.HandleMaster <BiliVideoMasterResultPage, BiliVideoMaster>(video1);
                    Reset();
                    break;

                case UrlType.Av:
                    var video2 = await BiliVideoHelper.GetVideoMasterAsync(long.Parse(result.Item2), Settings.SESSDATA);

                    SearchPage.Current.HandleMaster <BiliVideoMasterResultPage, BiliVideoMaster>(video2);
                    Reset();
                    break;

                case UrlType.Ep:
                    var bangumi1 = await BiliBangumiHelper.GetBangumiMasterAsync(long.Parse(result.Item2), Settings.SESSDATA, null);

                    SearchPage.Current.HandleMaster <BiliBangumiMasterResultPage, BiliBangumiMaster>(bangumi1);
                    Reset();
                    break;

                case UrlType.Ss:
                    var bangumi2 = await BiliBangumiHelper.GetBangumiMasterAsync(long.Parse(result.Item2), Settings.SESSDATA);

                    SearchPage.Current.HandleMaster <BiliBangumiMasterResultPage, BiliBangumiMaster>(bangumi2);
                    Reset();
                    break;

                case UrlType.Mc:
                    var manga = await BiliMangaHelper.GetMangaMasterAsync(long.Parse(result.Item2), Settings.SESSDATA);

                    SearchPage.Current.HandleMaster <BiliMangaMasterResultPage, BiliMangaMaster>(manga);
                    Reset();
                    break;

                case UrlType.Error:
                    Reset();
                    break;

                default:
                    Reset();
                    break;
                }
            }
            catch (Exception ex)
            {
                Reset();
                if (ex is VideoNotFoundException or ArgumentException
                    or UnauthorizedAccessException or ParsingVideoException)
                {
                    ShowNoticeFlyout(ex.Message);
                }