瀏覽代碼

Scrape video link for all sources

Tatiana Inama 6 年之前
父節點
當前提交
49573da708

+ 6 - 2
ktchn/src/recipes/scrape/sources/joy-of-baking.ts

@@ -9,7 +9,8 @@ const JOB_AUTHOR_DATA: Author = {
 
 const SELECTORS = {
   TITLE: 'h1 > span.Heading',
-  IMAGE: 'p[align="left"] img'
+  IMAGE: 'p[align="left"] img',
+  VIDEO: 'iframe[allowfullscreen]'
 }
 
 function getRecipeName($: CheerioSelector): string {
@@ -52,7 +53,10 @@ const JOB_CONFIG = {
     return {
       name: getRecipeName($),
       author: JOB_AUTHOR_DATA,
-      details: new RecipeDetails(), // There is no way to scrape this data from JOB
+      details: {
+        ...new RecipeDetails(),
+        video: $(SELECTORS.VIDEO).attr('src')
+      }, // There is no way to scrape this data from JOB
       ingredients: getIngredients($),
       instructions: getInstructions($),
       image: `${JOB_AUTHOR_DATA.website}/${$(SELECTORS.IMAGE).attr('src')}`

+ 3 - 1
ktchn/src/recipes/scrape/sources/just-one-cookbook.ts

@@ -22,7 +22,8 @@ const SELECTORS = {
   TAGS: 'span.wprm-recipe-keyword',
   SUMMARY: 'div.wprm-recipe-summary',
   COURSE: 'span.wprm-recipe-course',
-  IMAGE: 'div.wprm-recipe-image img'
+  IMAGE: 'div.wprm-recipe-image img',
+  VIDEO: 'div.video-container'
 }
 
 const getRecipeName = ($: CheerioSelector): string => {
@@ -34,6 +35,7 @@ const getRecipeDetails = ($: CheerioSelector): RecipeDetails => {
     preparationTime: $(SELECTORS.PREP_TIME).text(),
     cookingTime: $(SELECTORS.COOK_TIME).text(),
     servings: Number($(SELECTORS.SERVINGS).text()),
+    video: $(SELECTORS.VIDEO).children()[0].attribs['data-l-src'] || ''
   }
 };
 

+ 10 - 6
ktchn/src/recipes/scrape/sources/laura-in-the-kitchen.ts

@@ -12,18 +12,22 @@ const SELECTORS = {
   DETAILS: 'script[type="application/ld+json"]',
   INGREDIENTS: '.cs-ingredients-check-list > ul',
   INSTRUCTIONS: '#recipe-process > ul',
-  IMAGE: 'div.ytp-cued-thumbnail-overlay-image'
+  IMAGE: 'div.ytp-cued-thumbnail-overlay-image',
+  VIDEO: 'div#video-div iframe'
 }
 
 function getRecipeDetails($: CheerioSelector): RecipeDetails {
   const x = $(SELECTORS.DETAILS);
   let parsedScript = JSON.parse(($(x).html()||'').replace(/(\n|\t|\s{2,})/g, ' ').trim())
 
-  return new RecipeDetails(
-    parsedScript.prepTime,
-    parsedScript.cookTime,
-    parsedScript.recipeYield.match(/\d/)[0],
-  );
+  return {
+    ...new RecipeDetails(
+      parsedScript.prepTime,
+      parsedScript.cookTime,
+      parsedScript.recipeYield.match(/\d/)[0],
+    ),
+    video: $(SELECTORS.VIDEO).attr('src')
+  };
 }
 
 function getIngredients($: CheerioSelector): ISubRecipe[] {