<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/r%e2%81%b6-capturing-youtube-captions/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://rud.is/b/2018/03/29/r%E2%81%B6-capturing-youtube-captions/"> R – rud.is</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>(R⁶ == brief, low-expository posts)</p>
<p><a rel="nofollow" href="http://twitter.com/yoniceedee" target="_blank">@yoniceedee</a> suggested I look at the Cambridge Analytics “whistleblower” testimony proceedings:</p>
<blockquote class="twitter-tweet" data-lang="en">
<p lang="en" dir="ltr"><a rel="nofollow" href="https://twitter.com/hrbrmstr?ref_src=twsrc%5Etfw" target="_blank"><a rel="nofollow" href="http://twitter.com/hrbrmstr" target="_blank">@hrbrmstr</a></a> giving the term &quot;improving r&amp;d&quot; a whole new meaning … <a rel="nofollow" href="https://t.co/f1KA8U3htT" target="_blank">https://t.co/f1KA8U3htT</a></p>
<p>— yoni sidi (<a rel="nofollow" href="http://twitter.com/yoniceedee" target="_blank">@yoniceedee</a>) <a rel="nofollow" href="https://twitter.com/yoniceedee/status/979178126608658438?ref_src=twsrc%5Etfw" target="_blank">March 29, 2018</a></p>
</blockquote>
<p></p>
<p>I value the resources <a rel="nofollow" href="http://twitter.com/yoniceedee" target="_blank">@yoniceedee</a> tosses my way (they often end me down twisted paths like this one, though <img alt="🙂" src="https://s.w.org/images/core/emoji/2.3/72x72/1f642.png" class="wp-smiley"> but I really dislike spending any amount of time on youtube and can consume text context much faster than even accelerated video playback.</p>
<p>Google auto-generated captions for that video and you can display them by clicking below the video on the right and enabling the transcript which <em>slowly</em> (well, in my frame of reference) loads into the upper-right. That’s still sub-optimal since we need to be on the youtube page to read/scroll. There’s no “export” option and my initial instinct was to go to Developer Tools and look for the <code>https://www.youtube.com/service_ajax?name=getTranscriptEndpoint</code> URL and “Copy the Response” to the clipboard and save it to a file then do some JSON/list wrangling (the transcript JSON URL is in the snippet below):</p>
<pre><code>library(tidyverse)

trscrpt &lt;- jsonlite::fromJSON(&quot;https://rud.is/dl/ca-transcript.json&quot;)

runs &lt;- trscrpt$data$actions$openTranscriptAction$transcriptRenderer$transcriptRenderer$body$transcriptBodyRenderer$cueGroups[[1]]$transcriptCueGroupRenderer$formattedStartOffset$runs
cues &lt;- trscrpt$data$actions$openTranscriptAction$transcriptRenderer$transcriptRenderer$body$transcriptBodyRenderer$cueGroups[[1]]$transcriptCueGroupRenderer$cues

data_frame(
  mark = map_chr(runs, ~.x$text),
  text = map_chr(cues, ~.x$transcriptCueRenderer$cue$runs[[1]]$text)  
) %>% 
  separate(mark, c(&quot;minute&quot;, &quot;second&quot;), sep=&quot;:&quot;, remove = FALSE, convert = TRUE) 
## # A tibble: 3,247 x 4
##    mark  minute second text                                    
##    </code></pre>