mirror of
https://github.com/cooperhammond/irs.git
synced 2024-11-08 18:38:33 +00:00
fix #72: Find the JSON data inside the line and trim the rest
Signed-off-by: Luca Schlecker <luca.schlecker@hotmail.com>
This commit is contained in:
parent
c20f4309d8
commit
2c364c38c2
|
@ -200,7 +200,15 @@ module Youtube
|
||||||
# timestamp 11/8/2020:
|
# timestamp 11/8/2020:
|
||||||
# youtube's html page has a line previous to this literally with 'scraper_data_begin' as a comment
|
# youtube's html page has a line previous to this literally with 'scraper_data_begin' as a comment
|
||||||
if line.includes?("var ytInitialData")
|
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("</script>") || 0) - 1
|
||||||
|
|
||||||
|
begin
|
||||||
|
yt_initial_data = JSON.parse(data[0..dataEnd])
|
||||||
|
rescue
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue