2022-11-26 Extracting Youtube subtitles in Emacs

A few days ago I read about an amazing package. Like the OP, I very much dislike watching videos with lectures – text is much, much better way to communicate. (In fact, when I was a student, I preferred to skip lectures and learn from my colleagues’ notes instead. It was much more efficient.) I decided that I really need to try out youtube-sub-extractor.el.

It turned out that it’s very easy to do so. I installed the package and immediately tried it out. It turns out that it’s fairly simple to use – just call youtube-sub-extractor-extract-subs, give it a Youtube URL, and you get a buffer with the subtitles. From that buffer you can call two functions – youtube-sub-extractor-copy-ts-link to get a link with a timestamp to that particular moment in the video (kind of like what I did a few weeks ago), bound to RET, and youtube-sub-extractor-browse-ts-link to open the video at the corresponding moment, bound to C-c C-o. What’s especially nice is that the latter function uses browse-url under the hood, so it opens mpv from my Emacs.

Now this is definitely pretty cool, but there is one thing I’d like to add here. As I mentioned before, I sometimes have a YouTube link in my buffer, and killing it only to be able to yank it after I call youtube-sub-extractor-extract-subs is a nuisance. This is Emacs, so fixing this is a matter of seconds:

(require 'thingatpt)
(defun youtube-sub-extractor-extract-subs-at-point ()
  "Extract subtitles from a YouTube link at point."
  (interactive)
  (youtube-sub-extractor-extract-subs (thing-at-point-url-at-point)))

And that’s it for today!

CategoryEnglish, CategoryBlog, CategoryEmacs