Platform
Resources
Pricing
Sign in
Get started
Martien van Steenbergen
Wise Fool. Visioneer.
Workspace
Fork
Public
By
Martien van Steenbergen
Edited
Sep 6, 2024
Insert cell
Insert cell
Insert cell
Insert cell
// you may need to enable your use on "https://cors-anywhere.herokuapp.com/"
// This demo of CORS Anywhere should only be used for development purposes, see https://github.com/Rob--W/cors-anywhere/issues/301.
// To temporarily unlock access to the demo, click on the following button:
// url = "https://www.youtube.com/watch?v=Afoh23PHVP0"
url
=
"https://youtu.be/3Is8LiajzyI"
// url = "https://www.youtube.com/watch?v=pPI0ZG251tQ"
Insert cell
thumbnail
=
axios
(
{
method
:
"get"
,
url
:
"https://cors-anywhere.herokuapp.com/"
+
video
.
thumbnail
.
thumbnails
[
0
]
.
url
}
)
Insert cell
result
=
await
axios
(
{
method
:
"get"
,
url
:
"https://cors-anywhere.herokuapp.com/"
+
url
+
"&fmt=json3"
}
)
Insert cell
YT_INITIAL_PLAYER_RESPONSE_RE
=
/ytInitialPlayerResponse\s*=\s*({.+?})\s*;\s*(?:var\s+(?:meta|head)|<\/script|\n)/
Insert cell
yt
=
JSON
.
parse
(
result
.
data
.
match
(
YT_INITIAL_PLAYER_RESPONSE_RE
)
[
1
]
)
Insert cell
video
=
yt
.
videoDetails
Insert cell
track
=
yt
.
captions
?.
playerCaptionsTracklistRenderer
.
captionTracks
[
0
]
Insert cell
transcript
=
track
&&
await
axios
(
{
method
:
"get"
,
url
:
track
.
baseUrl
+
'&fmt=json3'
}
)
Insert cell
t
=
transcript
?.
data
.
events
.
map
(
k
=>
k
.
segs
)
// this is where the text is
.
filter
(
k
=>
k
&&
k
[
0
]
.
utf8
!==
"\n"
)
// only pick non-empties and omit newlines
.
map
(
k
=>
k
?.
map
(
t
=>
t
.
utf8
)
// grab just the text
.
join
(
""
)
// and join the words into a single line
)
.
join
(
"\n"
)
// join all lines into a single long string
Insert cell
t
?.
length
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
a
=
fetch
(
"https://cors-anywhere.herokuapp.com/"
+
"https://www.youtube.com/watch?v=Afoh23PHVP0"
)
.
then
(
response
=>
response
)
Insert cell
b
=
a
.
text
(
)
Insert cell
JSON
.
parse
(
b
.
match
(
YT_INITIAL_PLAYER_RESPONSE_RE
)
[
1
]
)
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
url
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
thumbnail
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
result
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
YT_INITIAL_PLAYER_RESPONSE_RE
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
yt
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
video
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
track
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
transcript
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
t
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
axios
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
a
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
b
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML