Create a gist now

Instantly share code, notes, and snippets.

combine WWDC subtitle files (fileSequence*.webvtt) to a srt file.
#!/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
}
@qiaoxueshi
Owner

Fisrt get fileSequence*.webvtt files of WWDC video via extract.py , then combine them to a srt file via this script.

@qiaoxueshi
Owner

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
......
@lexrus
lexrus commented Jul 14, 2013

这事用 bash 就一句话:
for d infind . -mindepth 1 -maxdepth 1 -type d; do find "$d" -name *.webvtt -exec cat {} >> "$d/${d:2}.srt" \;; done

@qiaoxueshi
Owner

@lexrus Cooool 受教

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment