Compare commits
11
Commits
b99dc3b5b2
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1568dbca9d | ||
|
|
f4c9a65427 | ||
|
|
5463bdddc9 | ||
|
|
1bcc6cf6c4 | ||
|
|
13efc2c85c | ||
|
|
e144bc65ca | ||
|
|
b67318b169 | ||
|
|
ecc77d4269 | ||
|
|
6066e69b45 | ||
|
|
dad2acc197 | ||
|
|
901990d6f5 |
No files matched your search
@@ -1,3 +1,10 @@
|
||||
# yt-transcript-tools
|
||||
Getting transcripts into epub format.
|
||||
|
||||
Download a transcript, place it in this directory, run
|
||||
`./convert_transcript.lua FILE`, fill in author and link as
|
||||
requested, and you will have a usable epub.
|
||||
|
||||
This is heavily WIP.
|
||||
|
||||
I used the apply_margin script on a transcript downloaded from
|
||||
@@ -14,3 +21,9 @@ the export will be different enough to fuck up the margin fix.
|
||||
I am really frustrated because pandoc doesn't support plain text.
|
||||
I went through many tests and iterations before coming to even
|
||||
this minimal start and it was extremely frustrating.
|
||||
|
||||
## Tasks
|
||||
- [x] I need an option / 2nd script to output a version with no
|
||||
timecode formatting for easier text extraction.
|
||||
- I made it actually just combine both in the same document,
|
||||
easier to manage that way.
|
||||
@@ -1,16 +0,0 @@
|
||||
#!/usr/bin/env luajit
|
||||
local a, b = arg[1], arg[2]
|
||||
|
||||
local file = io.open(b, "w")
|
||||
assert(file, "Couldn't open \"" .. b .. "\"")
|
||||
|
||||
for line in io.lines(a) do
|
||||
if not (line:sub(3, 3) == ":") then
|
||||
file:write(string.rep(" ", 6))
|
||||
end
|
||||
|
||||
file:write(line)
|
||||
file:write("\n")
|
||||
end
|
||||
|
||||
file:close()
|
||||
+42
-22
@@ -1,4 +1,6 @@
|
||||
#!/usr/bin/env luajit
|
||||
local version = "0.4.0"
|
||||
|
||||
local input_file_name = arg[1]
|
||||
assert(input_file_name,
|
||||
"You must enter an input file (its name will be the title).")
|
||||
@@ -11,38 +13,56 @@ local link = io.read("*line")
|
||||
local title = input_file_name:sub(1, -5) -- assumes .txt extension
|
||||
local output_file_name = title .. ".md"
|
||||
|
||||
local output_file = io.open(output_file_name, "w")
|
||||
assert(output_file, "Could not open \"" .. output_file_name .. "\"")
|
||||
|
||||
for _, line in ipairs{
|
||||
local frontmatter = {
|
||||
"---",
|
||||
"title: \"" .. title .. "\"",
|
||||
"author: \"" .. author .. "\"",
|
||||
"publisher: \"yt-transcript-tools v0.1\"",
|
||||
"publisher: \"yt-transcript-tools v" .. version .. "\"",
|
||||
"---",
|
||||
"",
|
||||
"From [" .. link .. "](" .. link .. ")",
|
||||
"",
|
||||
} do
|
||||
output_file:write(line)
|
||||
output_file:write("\n")
|
||||
}
|
||||
|
||||
if link and #link > 0 then
|
||||
frontmatter[#frontmatter + 1] = "From [" .. link .. "](" .. link .. ")\n"
|
||||
end
|
||||
|
||||
local input_lines = {}
|
||||
for line in io.lines(input_file_name) do
|
||||
output_file:write("`") -- make this line a code block on its own
|
||||
|
||||
-- if not appearing to start with a timecode,
|
||||
-- indent by the width of a timecode
|
||||
if not (line:sub(3, 3) == ":") then
|
||||
output_file:write(string.rep(" ", 6))
|
||||
end
|
||||
|
||||
output_file:write(line)
|
||||
output_file:write("`") -- close the code block
|
||||
output_file:write("\n")
|
||||
input_lines[#input_lines + 1] = line
|
||||
end
|
||||
|
||||
local output_lines = {}
|
||||
local timecode_free_lines = {}
|
||||
for index, line in ipairs(input_lines) do
|
||||
if not (line:sub(3, 3) == ":") then
|
||||
local previous_line = input_lines[index - 1]
|
||||
if previous_line and previous_line:sub(3, 3) == ":" then
|
||||
output_lines[#output_lines] = "```\n" .. previous_line
|
||||
output_lines[#output_lines + 1] = string.rep(" ", 6) .. line .. "\n```"
|
||||
else
|
||||
output_lines[#output_lines + 1] = "`" .. string.rep(" ", 6) .. line .. "`" -- pandoc will ignore this margin
|
||||
end
|
||||
timecode_free_lines[#timecode_free_lines + 1] = line
|
||||
else
|
||||
output_lines[#output_lines + 1] = "`" .. line .. "`"
|
||||
timecode_free_lines[#timecode_free_lines + 1] = line:sub(7)
|
||||
end
|
||||
end
|
||||
|
||||
local output_file = io.open(output_file_name, "w")
|
||||
assert(output_file, "Could not open \"" .. output_file_name .. "\"")
|
||||
|
||||
output_file:write(table.concat(frontmatter, "\n"))
|
||||
output_file:write("\n")
|
||||
|
||||
output_file:write("# Raw Transcript\n\n")
|
||||
output_file:write(table.concat(timecode_free_lines, "\n"))
|
||||
output_file:write("\n\n")
|
||||
|
||||
output_file:write("# Timecoded Transcript\n\n")
|
||||
output_file:write(table.concat(output_lines, "\n"))
|
||||
output_file:write("\n")
|
||||
output_file:close()
|
||||
|
||||
os.execute("pandoc --from markdown+hard_line_breaks \""
|
||||
.. output_file_name .. "\" -o \"" .. title .. ".epub\"")
|
||||
.. output_file_name .. "\" --toc=true -o \"" .. title .. ".epub\"")
|
||||
@@ -1,14 +0,0 @@
|
||||
#!/usr/bin/env luajit
|
||||
local a, b = arg[1], arg[2]
|
||||
|
||||
local file = io.open(b, "w")
|
||||
assert(file, "Couldn't open \"" .. b .. "\"")
|
||||
|
||||
for line in io.lines(a) do
|
||||
file:write("`")
|
||||
file:write(line)
|
||||
file:write("`")
|
||||
file:write("\n")
|
||||
end
|
||||
|
||||
file:close()
|
||||
Reference in new issue
Block a user