public static async Task <string> GetMovieSearchPageAsync(string title) { List <string> parseResult; var searchResultPage = await WebPageParser.GetPageAsync(KinopoiskUri, searchRequestPrefix + title); if (WebPageParser.TryParsePage(searchResultPage, movieNotFoundExpr, out parseResult)) { throw new ArgumentException("Movie not found"); } return(searchResultPage); }
private static string GetPageBlock(string request, Regex pageBlockExpr, string error = "Error while parsing page block") { List <string> parseResult; var page = WebPageParser.GetPageAsync(KinopoiskUri, request).Result; if (!WebPageParser.TryParsePage(page, pageBlockExpr, out parseResult)) { throw new ArgumentException(error); } return(parseResult[0]); }
public async Task <MovieInfo> GetMovieInfoAsync(int movieId) { using (var cancellationTokenSource = new CancellationTokenSource()) { var pageTask = WebPageParser.GetPageAsync(KinopoiskApiUri, $"/api/kinopoisk.json?id={movieId}&token={token}"); var completedTask = await Task.WhenAny(pageTask, Task.Delay(millisecondsDelay, cancellationTokenSource.Token)); if (pageTask != completedTask) { return(new MovieInfo()); } cancellationTokenSource.Cancel(); var page = Regex.Unescape(pageTask.Result); return(movieInfoParser.Parse(page)); } }