Last active
August 21, 2018 00:34
-
-
Save XueshiQiao/5992949 to your computer and use it in GitHub Desktop.
combine WWDC subtitle files (fileSequence*.webvtt) to a srt file.
This file contains hidden or 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
#!/usr/bin/ruby | |
docPath = "wwdc_srts" | |
#exclude . and .. folder | |
folders = Dir.entries(docPath).select{|folder| folder.to_i > 0} | |
folders.each{ |folder| | |
print folder | |
print "\n" | |
sequenceFilePath = docPath + "/" + folder | |
sequenceFiles = Dir.entries(sequenceFilePath).select{|file| file.length > 12} | |
fileCount = sequenceFiles.count | |
f = File.new(docPath + "/" + folder + ".srt", "w") | |
#combine sequence files to xxx.srt, xxx is video num, such as 210.srt. | |
for i in 0..fileCount-1 | |
out = File.open(sequenceFilePath + "/" + "fileSequence" + i.to_s + ".webvtt", "r"); | |
f.write(out.read); | |
out.close; | |
end | |
f.close | |
} |
wwdc_srts folder like this :
➜ Desktop tree wwdc_srts | more
wwdc_srts
├── 201
│ ├── fileSequence0.webvtt
│ ├── fileSequence1.webvtt
│ ├── fileSequence10.webvtt
│ ├── fileSequence11.webvtt
│ ├── fileSequence12.webvtt
│ ├── fileSequence13.webvtt
│ ├── ...... some other fileSequence files
├── 203
│ ├── fileSequence0.webvtt
│ ├── fileSequence1.webvtt
......
这事用 bash 就一句话:
for d in
find . -mindepth 1 -maxdepth 1 -type d; do find "$d" -name *.webvtt -exec cat {} >> "$d/${d:2}.srt" \;; done
@lexrus Cooool 受教
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fisrt get fileSequence*.webvtt files of WWDC video via extract.py , then combine them to a srt file via this script.