Last active
March 17, 2024 20:13
-
-
Save maxpatiiuk/26588696a006b3a08ac60713a4f72d16 to your computer and use it in GitHub Desktop.
BookPlayer Youtube bookmarks to HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* BookPlayer audiobook player for iOS has a bookmark export option. | |
* BookPlayer can be used to play YouTube videos downloaded using youtube-dl/yt-dlp. | |
* This small gist converts the txt BookPlayer bookmark export into an HTML page with | |
* links to the bookmarked YouTube videos to a correct position within the video | |
*/ | |
// Content of the txt file of your BookPlayer bookmarks exported | |
// Example: | |
const textContent = `Chapter 2 / 18:31 | |
Title: ✊🏻 Why not SOCIALISM-gHFLQecpFEk.m4a | |
---- | |
Chapter 13 / 38:58 | |
Title: 10 Types of Innovation Larry Keeley SingularityU South Africa Summit-GvROlNjLbrA.m4a | |
---- | |
Chapter 16 / 42:50 | |
Title: A Cold Old World (European Energy Crisis)-mpFybJRCKSc.m4a | |
---- | |
`; | |
const linksHtml = textContent | |
.split("----") | |
.map((r) => r.trim().split("\n")) | |
.filter(({ length }) => length === 2) | |
.map(([c, t]) => [ | |
c.replace(/Chapter \d+ \/ /, ""), | |
t.replace(/Title: /, "").replace(/.m4a$/, ""), | |
]) | |
.map(([time, meta]) => [ | |
time, | |
time | |
.split(":") | |
.map( | |
(part, index, { length }) => | |
Math.pow(60, length - index - 1) * Number.parseInt(part), | |
) | |
.reduce((t, v) => t + v, 0), | |
...meta.split(/-(?=[\w -]{11}$)/), | |
]) | |
.map( | |
([stringTime, intTime, title, slug], index, { length }) => | |
`<a href="https://youtu.be/${slug.replaceAll(' ','_')}?t=${intTime}" target="_blank">[${(index + 1).toString().padStart(length.toString().length, "0")}/${length}] ${title} (${stringTime})`, | |
) | |
.join("<br>\n"); | |
// Would look like: | |
// <a href="https://youtu.be/gHFLQecpFEk?t=1111">[1/3] ✊🏻 Why not SOCIALISM (18:31)</a><br> | |
// <a href="https://youtu.be/GvROlNjLbrA?t=2338">[2/3] 10 Types of Innovation Larry Keeley SingularityU South Africa Summit (38:58)</a><br> | |
// <a href="https://youtu.be/mpFybJRCKSc?t=2570">[3/3] A Cold Old World (European Energy Crisis) (42:50)</a> | |
document.body.innerHTML = linksHtml; | |
// (optional) | |
document.body.style.fontFamily = 'monospace' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment