From 2c364c38c271b57d4516de0dc5d33edbc5903e3d Mon Sep 17 00:00:00 2001 From: Luca Schlecker Date: Tue, 29 Dec 2020 21:00:07 +0100 Subject: [PATCH] fix #72: Find the JSON data inside the line and trim the rest Signed-off-by: Luca Schlecker --- src/search/youtube.cr | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/search/youtube.cr b/src/search/youtube.cr index e043583..d8cc455 100755 --- a/src/search/youtube.cr +++ b/src/search/youtube.cr @@ -200,7 +200,15 @@ module Youtube # timestamp 11/8/2020: # youtube's html page has a line previous to this literally with 'scraper_data_begin' as a comment if line.includes?("var ytInitialData") - yt_initial_data = JSON.parse(line.split(" = ")[1].delete(';')) + # Extract JSON data from line + data = line.split(" = ")[2].delete(';') + dataEnd = (data.index("") || 0) - 1 + + begin + yt_initial_data = JSON.parse(data[0..dataEnd]) + rescue + break + end end end