-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge in tools into same repo, retire their old repos
- Loading branch information
1 parent
9228f87
commit b96fd96
Showing
35 changed files
with
826 additions
and
216 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
language: go | ||
|
||
go: | ||
- 1.8 | ||
- tip | ||
|
||
before_install: | ||
- go get github.com/stretchr/testify/assert | ||
- go get github.com/onsi/gomega | ||
- go get github.com/onsi/ginkgo | ||
- go get golang.org/x/tools/cmd/cover | ||
|
||
script: | ||
- go test -coverprofile=coverage.txt -covermode=atomic | ||
- go test -v ./... | ||
|
||
after_success: | ||
- bash <(curl -s https://codecov.io/bash) |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# About | ||
|
||
Command line util to convert DCSubtitles into .srt format | ||
|
||
|
||
# Installation | ||
``` | ||
go get -u github.com/martinlindhe/subtitles/cmd/dcsub2srt | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// XXX should just invoke "subber vid.xml -o vid.srt" | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
|
||
"gopkg.in/alecthomas/kingpin.v2" | ||
|
||
"github.com/martinlindhe/subtitles" | ||
) | ||
|
||
var ( | ||
name = kingpin.Arg("name", "DCSubtitle file.").Required().String() | ||
) | ||
|
||
func main() { | ||
kingpin.Parse() | ||
|
||
data, err := ioutil.ReadFile(*name) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
sub, err := subtitles.NewFromDCSub(string(data)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Print(sub.AsSRT()) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# About | ||
|
||
Converts a .ssa to .srt | ||
|
||
|
||
# Installation | ||
|
||
``` | ||
go install github.com/martinlindhe/subtitles/cmd/ssa2srt | ||
``` | ||
|
||
|
||
# Usage | ||
|
||
``` | ||
$ ssa2srt subtile.ssa | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// XXX should just invoke "subber vid.ssa -o vid.srt" | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
|
||
"github.com/martinlindhe/subtitles" | ||
|
||
"gopkg.in/alecthomas/kingpin.v2" | ||
) | ||
|
||
var ( | ||
file = kingpin.Arg("file", "A .srt (to clean) or video file (to fetch subs).").Required().File() | ||
keepAds = kingpin.Flag("keep-ads", "Do not strip advertisement captions.").Bool() | ||
filterName = kingpin.Flag("filter", "Filter (none, caps, html).").Default("none").String() | ||
) | ||
|
||
const version = "0.1.1" | ||
|
||
func main() { | ||
// support -h for --help | ||
kingpin.Version(version) | ||
kingpin.CommandLine.HelpFlag.Short('h') | ||
kingpin.Parse() | ||
|
||
inFileName := (*file).Name() | ||
ext := path.Ext(inFileName) | ||
subFileName := inFileName[0:len(inFileName)-len(ext)] + ".srt" | ||
|
||
// skip "hidden" .dotfiles | ||
baseName := filepath.Base(inFileName) | ||
if baseName[0] == '.' { | ||
// fmt.Printf("Skipping hidden %s\n", inFileName) | ||
os.Exit(1) | ||
} | ||
|
||
data, err := ioutil.ReadFile(inFileName) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
out, err := cleanupSub(data, *filterName, *keepAds, 0) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
writeText(subFileName, false, out) | ||
|
||
fmt.Printf("Written %s\n", subFileName) | ||
} | ||
|
||
// cleanupSub parses .srt or .ssa, performs cleanup and renders to a .srt, returning a string. caller is responsible for passing UTF8 string | ||
func cleanupSub(data []byte, filterName string, keepAds bool, sync int) (string, error) { | ||
subtitle, err := subtitles.Parse(data) | ||
if err != nil { | ||
return "", err | ||
} | ||
if !keepAds { | ||
subtitle.RemoveAds() | ||
} | ||
if sync != 0 { | ||
subtitle.ResyncSubs(sync) | ||
} | ||
subtitle.FilterCaptions(filterName) | ||
out := subtitle.AsSRT() | ||
return out, nil | ||
} | ||
|
||
func writeText(outFileName string, skipBackups bool, text string) error { | ||
|
||
if !skipBackups && fileExists(outFileName) { | ||
backupFileName := outFileName + ".org" | ||
os.Rename(outFileName, backupFileName) | ||
// fmt.Printf("Backed up to %s\n", backupFileName) | ||
} | ||
|
||
err := ioutil.WriteFile(outFileName, []byte(text), 0644) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func fileExists(name string) bool { | ||
if _, err := os.Stat(name); err == nil { | ||
return true | ||
} | ||
return false | ||
} |
Oops, something went wrong.