Skip to content

Instantly share code, notes, and snippets.

@XueshiQiao
Last active August 21, 2018 00:34
Show Gist options
  • Save XueshiQiao/5992949 to your computer and use it in GitHub Desktop.
Save XueshiQiao/5992949 to your computer and use it in GitHub Desktop.
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
}
@XueshiQiao
Copy link
Author

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

@XueshiQiao
Copy link
Author

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
Copy link

lexrus commented Jul 14, 2013

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

@XueshiQiao
Copy link
Author

@lexrus Cooool 受教

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