Beispiel #1
0
        private void GoToDownloadPage(SubsceneSearchModel subsceneSearchModel = null)
        {
            SubsceneSearchModel item;

            if (subsceneSearchModel != null)
            {
                item = subsceneSearchModel;
            }
            else
            {
                item = SubListView.SelectedItem as SubsceneSearchModel;
            }

            if (item != null)
            {
                Frame.Navigate(typeof(SubsceneDownloadPage), new NavigationParamModel {
                    Key = (int)Server.Subscene + item.Name, Title = item.Name, Link = Helper.Settings.SubsceneServer.Url + item.Link
                }, new DrillInNavigationTransitionInfo());
            }
        }
Beispiel #2
0
        public async void SearchSubtitle(string queryText)
        {
            if (GeneralHelper.IsNetworkAvailable())
            {
                try
                {
                    errorInfo.IsOpen = false;

                    if (!string.IsNullOrEmpty(queryText))
                    {
                        if (Helper.Settings.IsHistoryEnabled)
                        {
                            Helper.AddToHistory(queryText);
                        }
                        progress.IsActive      = true;
                        SubListView.Visibility = Visibility.Collapsed;
                        Subtitles.Clear();
                        if (queryText.StartsWith("tt"))
                        {
                            AutoSuggest.Text = await Helper.GetImdbIdFromTitle(queryText);
                        }

                        var url = string.Format(Constants.SubsceneSearchAPI, Helper.Settings.SubsceneServer.Url, queryText);
                        var web = new HtmlWeb();
                        var doc = await web.LoadFromWebAsync(url);

                        var titleCollection = doc.DocumentNode.SelectSingleNode("//div[@class='search-result']");
                        if (titleCollection == null || titleCollection.InnerText.Contains("No results found"))
                        {
                            ShowError(Constants.NotFoundOrExist);
                        }
                        else
                        {
                            for (int i = 1; i < 4; i++)
                            {
                                errorInfo.IsOpen = false;
                                var node = titleCollection.SelectSingleNode($"ul[{i}]");
                                if (node != null)
                                {
                                    foreach (var item in node.SelectNodes("li"))
                                    {
                                        var subNode = item?.SelectSingleNode("div//a");
                                        var count   = item.SelectSingleNode("span");
                                        if (count == null)
                                        {
                                            count = item.SelectSingleNode("div[@class='subtle count']");
                                        }

                                        var name     = subNode?.InnerText.Trim();
                                        var subtitle = new SubsceneSearchModel
                                        {
                                            Name = name,
                                            Link = subNode?.Attributes["href"]?.Value.Trim(),
                                            Desc = count?.InnerText.Trim(),
                                            Key  = GetSubtitleKey(i)
                                        };
                                        Subtitles.Add(subtitle);
                                    }
                                }
                                else
                                {
                                    ShowError(Constants.NotFoundOrExist);
                                }
                            }
                        }
                    }
                    progress.IsActive      = false;
                    SubListView.Visibility = Visibility.Visible;
                    var groups = from c in Subtitles
                                 group c by c.Key;
                    SubtitleCVS.Source = groups;

                    if (Helper.Settings.IsFirstRun)
                    {
                        tip2.IsOpen = true;
                    }
                }
                catch (ArgumentOutOfRangeException)
                {
                }
                catch (ArgumentNullException)
                {
                }
                catch (NullReferenceException)
                {
                }
                catch (WebException ex)
                {
                    if (!string.IsNullOrEmpty(ex.Message))
                    {
                        ShowError(ex.Message);
                    }
                }
                catch (HttpRequestException hx)
                {
                    if (!string.IsNullOrEmpty(hx.Message))
                    {
                        ShowError(hx.Message);
                    }
                }
                finally
                {
                    progress.IsActive      = false;
                    SubListView.Visibility = Visibility.Visible;
                }
            }
            else
            {
                ShowError(Constants.InternetIsNotAvailable, Constants.InternetIsNotAvailableTitle);
            }
        }