eev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

M-x find-yttranscript-links


From: Eduardo Ochs
Subject: M-x find-yttranscript-links
Date: Wed, 30 Mar 2022 02:17:09 -0300

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'. These links point to
their sources:

  (find-eev "eev-tlinks.el" "find-yttranscript-links")
  (find-eev "eev-tlinks.el" "find-pip3-links")


This blog post:

<https://ag91.github.io/blog/2022/03/27/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,

<https://ag91.github.io/blog/2022/03/28/something-i-missed-point-free-composition-in-elisp/>

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,

  http://www.youtube.com/watch?v=dP1xVpMPn8M
  (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    = "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))
print(trits1)

Most of the functions in eev that generate temporary buffers use
either `find-elinks' or `find-elinks-elisp':

  (find-eev "eev-elinks.el" "find-elinks")
  (find-eev "eev-elinks.el" "find-elinks" "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

  print(trits1)

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")

to:

  # (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.

  Cheers =),
    Eduardo Ochs
    http://angg.twu.net/#eev



reply via email to

[Prev in Thread] Current Thread [Next in Thread]