private async void Subf2mCore() { try { var web = new HtmlWeb(); var doc = await web.LoadFromWebAsync(subtitleUrl); var repeater = doc.DocumentNode.SelectNodes("//ul[@class='scrolllist']"); if (repeater == null) { ShowStatus(Constants.NotFoundOrExist, null, InfoBarSeverity.Error); } else { Subtitles?.Clear(); foreach (var node in repeater.GetEnumeratorWithIndex()) { var language = node.Value.SelectNodes("//div[@class='topright']//span[1]")[node.Index].InnerText; var translator = node.Value.SelectNodes("//div[@class='comment-col']")[node.Index].InnerText; var download_Link = node.Value.SelectNodes("//a[@class='download icon-download']")[node.Index].GetAttributeValue("href", ""); //remove empty lines var singleLineTranslator = Regex.Replace(translator, @"\s+", " ").Replace(" ", ""); if (singleLineTranslator.Contains(" ")) { singleLineTranslator = singleLineTranslator.Replace(" ", ""); } string _name = node.Value.InnerText.Trim(); int MaxLength = 100; _name = _name.Length > MaxLength?_name.Substring(0, MaxLength) : _name; var item = new SubsceneDownloadModel { Name = node.Value.InnerText.Trim(), Title = _name, Translator = singleLineTranslator.Trim(), Link = download_Link.Trim(), Language = language }; Subtitles.Add(item); } SetPosterAndIMDB(doc); } progress.IsActive = false; listView.Visibility = Visibility.Visible; } catch (ArgumentNullException) { } catch (ArgumentOutOfRangeException) { } catch (WebException ex) { if (!string.IsNullOrEmpty(ex.Message)) { ShowStatus(null, ex.Message, InfoBarSeverity.Error); } } catch (HttpRequestException hx) { if (!string.IsNullOrEmpty(hx.Message)) { ShowStatus(null, hx.Message, InfoBarSeverity.Error); } } finally { progress.IsActive = false; listView.Visibility = Visibility.Visible; } }
private async void SubsceneCore() { try { var web = new HtmlWeb(); var doc = await web.LoadFromWebAsync(subtitleUrl); var table = doc.DocumentNode.SelectSingleNode("//table[1]//tbody"); if (table != null) { Subtitles?.Clear(); foreach (var cell in table.SelectNodes(".//tr")) { if (cell.InnerText.Contains("There are no subtitles")) { break; } var Language = cell.SelectSingleNode(".//td[@class='a1']//a//span[1]")?.InnerText.Trim(); var Name = cell.SelectSingleNode(".//td[@class='a1']//a//span[2]")?.InnerText.Trim(); var Translator = cell.SelectSingleNode(".//td[@class='a5']//a")?.InnerText.Trim(); var Comment = cell.SelectSingleNode(".//td[@class='a6']//div")?.InnerText.Trim(); if (Comment != null && Comment.Contains(" ")) { Comment = Comment.Replace(" ", ""); } var Link = cell.SelectSingleNode(".//td[@class='a1']//a")?.Attributes["href"]?.Value.Trim(); if (Name != null) { var item = new SubsceneDownloadModel { Name = Name, Title = Name, Translator = Translator, Comment = Comment, Link = Link, Language = Language }; Subtitles.Add(item); } } SetPosterAndIMDB(doc); } else { ShowStatus(Constants.NotFoundOrExist, null, InfoBarSeverity.Error); } progress.IsActive = false; listView.Visibility = Visibility.Visible; } catch (ArgumentNullException) { } catch (ArgumentOutOfRangeException) { } catch (WebException ex) { if (!string.IsNullOrEmpty(ex.Message)) { ShowStatus(null, ex.Message, InfoBarSeverity.Error); } } catch (HttpRequestException hx) { if (!string.IsNullOrEmpty(hx.Message)) { ShowStatus(null, hx.Message, InfoBarSeverity.Error); } } finally { progress.IsActive = false; listView.Visibility = Visibility.Visible; } }
private async void GetSubtitle() { progress.IsActive = true; listView.Visibility = Visibility.Collapsed; CloseStatus(); if (GeneralHelper.IsNetworkAvailable()) { try { var web = new HtmlWeb(); var doc = await web.LoadFromWebAsync(subtitleUrl); var items = doc.DocumentNode.SelectSingleNode("//table"); if (items == null) { ShowStatus(Constants.NotFoundOrExist, null, InfoBarSeverity.Error); } else { Subtitles?.Clear(); var movieData = items.SelectNodes("//td[@data-title='Release / Movie']"); var commentData = items.SelectNodes("//td[@data-title='Comment']"); var language = items.SelectNodes("//td[@data-title='Language']"); if (movieData != null) { string title = string.Empty; string href = string.Empty; string comment = string.Empty; foreach (var row in movieData.GetEnumeratorWithIndex()) { var currentRow = row.Value?.SelectNodes("a"); foreach (var cell in currentRow) { title = cell?.InnerText?.Trim(); href = $"{Constants.ISubtitleBaseUrl}{cell?.Attributes["href"]?.Value?.Trim()}"; } comment = commentData[row.Index]?.InnerText?.Trim(); if (comment != null && comment.Contains(" ")) { comment = comment.Replace(" ", ""); } if (!string.IsNullOrEmpty(title)) { var item = new SubsceneDownloadModel { Name = Helper.GetDecodedStringFromHtml(title), Translator = Helper.GetDecodedStringFromHtml(comment), Link = href, Language = language[row.Index]?.InnerText.Trim() }; Subtitles.Add(item); } } } } progress.IsActive = false; listView.Visibility = Visibility.Visible; } catch (ArgumentNullException) { } catch (ArgumentOutOfRangeException) { } catch (WebException ex) { if (!string.IsNullOrEmpty(ex.Message)) { ShowStatus(null, ex.Message, InfoBarSeverity.Error); } } catch (HttpRequestException hx) { if (!string.IsNullOrEmpty(hx.Message)) { ShowStatus(null, hx.Message, InfoBarSeverity.Error); } } finally { progress.IsActive = false; listView.Visibility = Visibility.Visible; } } else { ShowStatus(Constants.InternetIsNotAvailableTitle, Constants.InternetIsNotAvailable, InfoBarSeverity.Error); } }