Chapa 1)



In march 2022 Andrea Giugliano wrote these two posts in his blog:

2022-03-27: An Elisp snippet to download YouTube video transcripts
2022-03-28: Something I missed: point free composition in Elisp!

I immediately thought that: WOW, I need something like that in eev - but I would like to rewrite it in a style in which all the steps can be executed one by one, and I would like to integrate it with find-youtubedl-links...

At that point I was still totally incompetent with Python - I didn't have this yet - so I had to ask for help on the #emacs IRC channel. After a lot of help I was able to write the functions find-yttranscript-links and find-pip3-links, that produce temporary buffers like the ones shown in the first two screenshots below,

...and I posted this in the eev mailing list:

2022-03-30: M-x find-yttranscript-links

It has a detailed explanation of how everything works, but in a format that is somewhat hard to read. Section 1 below is a de-uglified version of that e-mail to the mailing list; section 2 is about two functions similar to find-pip3-links that were added later, and section 3 is about a video that explains everything. You can watch it by clicking on the third screenshot above.

You can read the subtitles in a nice format here.

1. The e-mail to the mailing list

(The original is here.)

Hi all,

I added a small feature to eev that has some nice ideas in it. I think that it deserves a video, but I can't record the video now, so let me explain it by text. The new feature consists on just two functions: `find-yttranscript-links' and `find-pip3-links'. This blog post by ag91, called "An Elisp snippet to dowload YouTube videos transcripts", implements a function that downloads the transcript of a video from youtube using a Python package that can be installed using pip3, and in the day after writing that blog post the author wrote this other one, in which he translates his script to another style.

So: I thought that I wanted to add that to eev, but I wanted to translate it to a third style, in which each line of the Python code could be executed individually, and all the intermediate results could be inspected and tinkered with.

Remember that most functions of eev that operate on youtube URL work on the id, or the "hash", of the URL. If we put the point on the hash of the URL below and type `M-x find-yttranscript-links', or if we execute the "eek" sexp,

(eek "<up> M-x find-yttranscript-links")

then we get a temporary buffer whose body is this:

* (python-mode)
* (eepitch-python)
* (eepitch-kill)
* (eepitch-python)
import youtube_transcript_downloader
url    = "[11]http://www.youtube.com/watch?v=koud7hgGyQ8";
tr     = youtube_transcript_downloader.get_transcript(url)
trits0 = tr.items()
trits1 = '\n'.join(('% (find-{c}video "' + key + '" "' + text + '")'
for key, text in trits0))

Most of the functions in eev that generate temporary buffers use either `find-elinks' or `find-elinks-elisp'. I _could_ have implemented a `find-elinks-python' that would put the temporary buffer in python-mode, but I decided to be lazy and use the trick above, and I was quite pleased with the result... just to be clear: when we type <f8> on the line with the sexp `(python-mode)' the buffer changes to python-mode. That trick can be used for all other language modes, too.

If you type <f8> on the line with the

import youtube_transcript_downloader

you will probably get an error, because youtube_transcript_downloader is not installed... but a bit above the header we have this sexp,

# (find-pip3-links "youtube-transcript-downloader")

that we can use to install youtube-transcript-downloader.

If we run the Python script above - with all dependencies installed - the line


will print many lines like this one

% (find-{c}video "00:00" "welcome this is a quick tour of acne and")

in the target buffer of eepitch, that is running a Python REPL. The function `find-{c}video' is probably undefined, so that sexp doesn't play a video. One way to solve this - in two steps - is to change the line at the top of the *find-yttranscript-links* buffer from

# (find-yttranscript-links "{c}" "dP1xVpMPn8M")


# (find-yttranscript-links "acmetour" "dP1xVpMPn8M")

and then regenerate the buffer and rerun its Python script, then the last "print" will generate lots of lines like this one:

% (find-acmetourvideo "00:00" "welcome this is a quick tour of acne and")

which is a bit better. If the function `find-acmetourvideo' is not defined we can execute this sexp, that is in one of the first lines of the *find-yttranscript-links* buffer,

# (find-youtubedl-links nil nil "dP1xVpMPn8M" nil "acmetour")

to either download a local copy of that video and define `find-acmetourvideo' as a function that plays it, or to define `find-acmetourvideo' as function that plays that video on youtube. The last two lines of the *find-youtubedl-links* will be these ones (because I changed this yesterday),

# Transcript:
# (find-yttranscript-links "acmetour" "dP1xVpMPn8M")

and we can use the `find-yttranscript-links' sexp to go back to the buffer that generates the transcript.

2. `find-importlib-links' and `find-pypi-links'

In 2022-10-19 I asked on #python how I could enhance find-pip3-links. I showed a screenshot of my find-cabal-links, explained how I use it to get information about a Haskell package and to download a copy of its upstream repository, and asked how I could do something like that for Python packages. I got a lot of help - thanks SpookJ, grym, Tritium, and BrenBarn! - and I was able to write the functions find-importlib-links and find-pypi-links, that create temporary buffers like the ones below:

3. The video

I recorded it in 2022oct20, and then I ran this on it,

(find-yttranscript-links "2022yttranscript" "SW3Tx-lHX3o")

and edited the output to prepare this preliminary index for the video. In 2022dec30 I added "real subtitles" to the video, and now you can watch it with subtitles - even in high speed! - with:

# See:  http://anggtwu.net/eev-videos.html
#       http://anggtwu.net/eev-videos.html#mpv-keys
# Play: (find-2022yttranscriptvideo "0:00")
# Info: (find-1stclassvideo-links "2022yttranscript")
# Subs: (find-1stclassvideolsubs  "2022yttranscript")

wget -nc http://anggtwu.net/eev-videos/2022-yttranscript.mp4
wget -N  http://anggtwu.net/eev-videos/2022-yttranscript.vtt
mpv --fs --osd-level=2 2022-yttranscript.mp4

4. The subtitles

You can read the subtitles of this video here.