/// <summary> /// レシピ手順インスタンス作成 /// </summary> /// <param name="number">番号</param> /// <param name="photoFilePath">写真ファイルパス</param> /// <param name="text">手順テキスト</param> /// <returns>レシピ手順インスタンス</returns> public override IRecipeStep CreateStepInstance(int number, string photoFilePath, string text) { var step = new RakutenRecipeStep(this.Settings, this.Logger); step.Number.Value = number; step.PhotoFilePath.Value = photoFilePath; step.StepText.Value = text; return(step); }
/// <summary> /// レシピダウンロード /// </summary> /// <returns></returns> public override async Task DownloadRecipeAsync() { try { var htmlString = await this._httpClient.GetStringAsync(this.Url.Value); var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(htmlString); this.Title.Value = htmlDoc.QuerySelector("#topicPath [itemprop=title] strong").InnerText.Trim(); using (var stream = await this._httpClient.GetStreamAsync(new Uri(htmlDoc.QuerySelector("#detailContents .rcpPhotoBox img").Attributes["src"].Value))) using (var ms = new MemoryStream()) { stream.CopyTo(ms); this.Photo.Value = ms.ToArray(); } this.Description.Value = htmlDoc.QuerySelector("#detailContents .ownerCom .summary").InnerText.Trim(); this.Author.Value = new RakutenRecipeAuthor { Name = HttpUtility.HtmlDecode(htmlDoc.QuerySelector("#recipe_owner_mypage_link").InnerText).Trim(), Url = new Uri(this.Url.Value, htmlDoc.QuerySelector("#recipe_owner_mypage_link").Attributes["href"].Value).AbsoluteUri }; this.Yield.Value = htmlDoc.QuerySelector("#detailContents .materialBox [itemprop=recipeYield]")?.InnerText.Trim(); this.Ingredients.Clear(); var ingredients = new List <RakutenRecipeIngredient>(); foreach (var ingredient in htmlDoc.QuerySelectorAll("#detailContents .materialBox li[itemprop=ingredients]")) { var item = new RakutenRecipeIngredient(this); item.Id.Value = ingredients.Count + 1; // 自動採番 item.Name.Value = ingredient.QuerySelector(".name").InnerText.Trim(); item.AmountText.Value = ingredient.QuerySelector(".amount").InnerText; ingredients.Add(item); } this.Ingredients.AddRange(ingredients); this.Steps.Clear(); var steps = htmlDoc .QuerySelectorAll("#detailContents .stepBox") .Select(async(x, index) => { var RakutenRecipeStep = new RakutenRecipeStep(this.Settings, this.Logger); RakutenRecipeStep.Number.Value = index + 1; var photoUrl = x.QuerySelector(".stepPhoto img")?.Attributes["src"].Value; if (photoUrl != null) { using (var stream = await this._httpClient.GetStreamAsync(new Uri(photoUrl))) using (var ms = new MemoryStream()) { stream.CopyTo(ms); RakutenRecipeStep.Photo.Value = ms.ToArray(); } } RakutenRecipeStep.StepText.Value = x.QuerySelector(".stepMemo").InnerText.Trim(); return(RakutenRecipeStep); }); foreach (var step in steps) { this.Steps.Add(await step); } this.History.Value = htmlDoc.QuerySelector("#detailContents .howtoPointBox:first-child p")?.InnerText.Trim(); this.Advice.Value = htmlDoc.QuerySelector("#detailContents .howtoPointBox:last-child p")?.InnerText.Trim(); this.RakutenRecipeId.Value = Regex.Replace(HttpUtility.HtmlDecode(htmlDoc.QuerySelector("#detailContents .rcpId").InnerText.Trim()), "^.+:.", ""); this.PublishedDate.Value = htmlDoc.QuerySelector("#publish_day_itemprop").InnerText.Trim(); } catch (Exception ex) { this._failedNotification.OnNext((this, Behavior.Download, ex)); return; } this._completedNotification.OnNext((this, Behavior.Download)); }