Skip to content

Instantly share code, notes, and snippets.

@stemmlerjs
Created October 1, 2020 08:22
Show Gist options
  • Select an option

  • Save stemmlerjs/07d51335a630e17b0510c407853140e5 to your computer and use it in GitHub Desktop.

Select an option

Save stemmlerjs/07d51335a630e17b0510c407853140e5 to your computer and use it in GitHub Desktop.
Strip annotations from a YouTube transcript
function hasAnnotations (text) {
return getNextAnnotationStartIndex(text) !== -1 ||
getNextAnnotationEndIndex(text) !== -1;
}
function getNextAnnotationStartIndex (text) {
return text.indexOf(`\n\n**`)
}
function getNextAnnotationEndIndex (text) {
return text.indexOf(`**\n\n`)
}
function stripAnnotations (text) {
while (hasAnnotations(text)) {
let startIndex = getNextAnnotationStartIndex(text);
let endIndex = getNextAnnotationEndIndex(text);
let newText = text.substring(0, startIndex) + " " + text.substring(endIndex + 4);
text = newText;
}
return text;
}
var transcript = `for jean-paul sartre freedom was
**00:08**
everything the lover wants to be loved
**00:11**
but not by someone who has taken a love
**00:12**
potion he wants to be loved by someone
**00:15**
who has freely chosen to love him the
**00:18**
kind of possession we seek in loving
**00:20**
someone else is completely different
**00:21**
from the possession of a thing because a
**00:24**
thing can't possess us back but for
**00:27**
Sartre the reality of romantic love
**00:29**
isn't blissful mutual respect and a
**00:32**
merging of freedoms, far from it
**00:34**
love is conflict the loved person wants`;
stripAnnotations(transcript);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment