Added readme

This commit is contained in:
Quentin Renard
2017-07-02 15:53:23 +02:00
parent 6c75a0b0f4
commit bf83847f3e
9 changed files with 299 additions and 0 deletions
+74
View File
@@ -0,0 +1,74 @@
[![GoReportCard](http://goreportcard.com/badge/github.com/asticode/go-astisub)](http://goreportcard.com/report/github.com/asticode/go-astisub)
[![GoDoc](https://godoc.org/github.com/asticode/go-astisub?status.svg)](https://godoc.org/github.com/asticode/go-astisub)
[![GoCoverage](https://cover.run/go/github.com/asticode/go-astisub.svg)](https://cover.run/go/github.com/asticode/go-astisub)
This is a Golang library to manipulate subtitles.
It allows you to manipulate `srt`, `ttml` and `webvtt` files for now.
Available operations are `parsing`, `writing`, `syncing`, `fragmenting` and `merging`.
# Installation
To install the library and command line program, use the following:
go get -u github.com/asticode/go-astisub/...
# Using the library in your code
WARNING: the code below doesn't handle errors for readibility purposes. However you SHOULD!
```go
// Open subtitles
s1, _ := astisub.Open("/path/to/example.ttml")
s2, _ := astisub.ReadFromSRT(bytes.NewReader([]byte("00:01:00.000 --> 00:02:00.000\nCredits")))
// Add a duration to every subtitles (syncing)
s1.Add(-2*time.Second)
// Fragment the subtitles
s1.Fragment(2*time.Second)
// Merge subtitles
s1.Merge(s2)
// Write subtitles
s1.Write("/path/to/example.srt")
var buf = &bytes.Buffer{}
s2.WriteToTTML(buf)
```
# Using the CLI
If **astisub** has been installed properly you can:
- convert any type of subtitle to any other type of subtitle:
astisub convert -i example.srt -o example.ttml
- fragment any type of subtitle:
astisub fragment -i example.srt -f 2s -o example.out.srt
- merge any type of subtitle into any other type of subtitle:
astisub merge -i example.srt -i example.ttml -o example.out.srt
- sync any type of subtitle:
astisub sync -i example.srt -s "-2s" -o example.out.srt
# Features and roadmap
- [x] parsing
- [x] writing
- [x] syncing
- [x] fragmenting
- [x] merging
- [x] ordering
- [x] .srt
- [x] .ttml
- [x] .vtt
- [x] .stl
- [ ] .teletext
- [ ] .smi
+26
View File
@@ -0,0 +1,26 @@
1
00:01:39 --> 00:01:41,04
(deep rumbling)
2
00:02:04,08 --> 00:02:07,12
MAN:
How did we end up here?
3
00:02:12,16 --> 00:02:15,20
This place is horrible.
4
00:02:20,24 --> 00:02:22,28
Smells like balls.
5
00:02:28,32 --> 00:02:31,36
We don't belong
in this shithole.
6
00:02:31,40 --> 00:02:33,44
(computer playing
electronic melody)
BIN
View File
Binary file not shown.
+46
View File
@@ -0,0 +1,46 @@
<tt xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2006/10/ttaf1" xmlns:tt="http://www.w3.org/2006/10/ttaf1" xmlns:tts="http://www.w3.org/2006/10/ttaf1#styling" xmlns:ttp="http://www.w3.org/2006/10/ttaf1#parameter" xmlns:ttm="http://www.w3.org/2006/10/ttaf1#metadata" xml:lang="fr-FR" ttp:timeBase="smpte" ttp:frameRate="25" ttp:frameRateMultiplier="1:1" ttp:markerMode="discontinuous">
<head>
<metadata>
<ttm:title>Title test</ttm:title>
<ttm:copyright>Copyright test</ttm:copyright>
</metadata>
<styling>
<style xml:id="style_0" tts:style="style_2" tts:fontFamily="sansSerif" tts:color="white" tts:fontStyle="normal" tts:textAlign="center" tts:origin="0% 90%" tts:extent="100% 10%"/>
<style xml:id="style_1" tts:fontFamily="sansSerif" tts:color="white" tts:fontStyle="normal" tts:textAlign="center" tts:origin="0% 87%" tts:extent="100% 13%"/>
<style xml:id="style_2" tts:fontFamily="sansSerif" tts:color="white" tts:fontStyle="normal" tts:textAlign="center" tts:origin="0% 80%" tts:extent="100% 20%"/>
</styling>
<layout>
<region xml:id="region_0" tt:style="style_0" tt:color="blue"/>
<region xml:id="region_1" tt:style="style_1"/>
<region xml:id="region_2" tt:style="style_2"/>
</layout>
</head>
<body>
<div>
<p xml:id="sub_1" begin="00:01:39.000" end="00:01:41.040" region="region_1" style="style_1" color="red">
<span style="style_1" color="black">(deep rumbling)</span>
</p>
<p xml:id="sub_2" begin="00:02:04.080" end="00:02:07.120" region="region_2">
MAN:
<tt:br/>
How did we <span style="style_1" color="green">end up</span> here?
</p>
<p xml:id="sub_3" begin="00:02:12.160" end="00:02:15.200" region="region_1">
<span style="style_1">This place is horrible.</span>
</p>
<p xml:id="sub_4" begin="00:02:20.240" end="00:02:22.280" region="region_1">
<span style="style_1">Smells like balls.</span>
</p>
<p xml:id="sub_5" begin="00:02:28.320" end="00:02:31.360" region="region_2">
<span style="style_2">We don't belong</span>
<tt:br/>
<span style="style_1">in this shithole.</span>
</p>
<p xml:id="sub_6" begin="00:02:31.400" end="00:02:33:11" region="region_2">
<span style="style_2">(computer playing</span>
<tt:br/>
<span style="style_1">electronic melody)</span>
</p>
</div>
</body>
</tt>
+42
View File
@@ -0,0 +1,42 @@
WEBVTT
NOTE this a nice example
NOTE of a VTT
STYLE
::cue(b) {
color: peachpuff;
}
Region: id=fred width=40% lines=3 regionanchor=0%,100% viewportanchor=10%,90% scroll=up
Region: id=bill width=40% lines=3 regionanchor=100%,100% viewportanchor=90%,90% scroll=up
1
00:01:39 --> 00:01:41.04 region:bill
(deep rumbling)
NOTE This a comment inside the VTT
and this is the second line
2
00:02:04.08 --> 00:02:07.12 region:fred position:10%,start align:left size:35%
MAN:
How did we end up here?
00:02:12.16 --> 00:02:15.20
This place is horrible.
4
00:02:20.24 --> 00:02:22.28
Smells like balls.
5
00:02:28.32 --> 00:02:31.36
We don't belong
in this shithole.
6
00:02:31.40 --> 00:02:33.44
(computer playing
electronic melody)
+26
View File
@@ -0,0 +1,26 @@
1
00:01:39,000 --> 00:01:41,040
(deep rumbling)
2
00:02:04,080 --> 00:02:07,120
MAN:
How did we end up here?
3
00:02:12,160 --> 00:02:15,200
This place is horrible.
4
00:02:20,240 --> 00:02:22,280
Smells like balls.
5
00:02:28,320 --> 00:02:31,360
We don't belong
in this shithole.
6
00:02:31,400 --> 00:02:33,440
(computer playing
electronic melody)
BIN
View File
Binary file not shown.
+48
View File
@@ -0,0 +1,48 @@
<tt xmlns="http://www.w3.org/ns/ttml" xml:lang="fr">
<head>
<metadata xmlns:ttm="http://www.w3.org/ns/ttml#metadata">
<ttm:copyright>Copyright test</ttm:copyright>
<ttm:title>Title test</ttm:title>
</metadata>
<styling xmlns:tts="http://www.w3.org/ns/ttml#styling">
<style xml:id="style_0" style="style_2" tts:color="white" tts:extent="100% 10%" tts:fontFamily="sansSerif" tts:fontStyle="normal" tts:origin="0% 90%" tts:textAlign="center"></style>
<style xml:id="style_1" tts:color="white" tts:extent="100% 13%" tts:fontFamily="sansSerif" tts:fontStyle="normal" tts:origin="0% 87%" tts:textAlign="center"></style>
<style xml:id="style_2" tts:color="white" tts:extent="100% 20%" tts:fontFamily="sansSerif" tts:fontStyle="normal" tts:origin="0% 80%" tts:textAlign="center"></style>
</styling>
<layout xmlns:tts="http://www.w3.org/ns/ttml#styling">
<region xml:id="region_0" style="style_0" tts:color="blue"></region>
<region xml:id="region_1" style="style_1"></region>
<region xml:id="region_2" style="style_2"></region>
</layout>
</head>
<body>
<div>
<p begin="00:01:39.000" end="00:01:41.040" region="region_1" style="style_1" tts:color="red">
<span style="style_1" tts:color="black">(deep rumbling)</span>
</p>
<p begin="00:02:04.080" end="00:02:07.120" region="region_2">
<span>MAN:</span>
<br></br>
<span>How did we</span>
<span style="style_1" tts:color="green">end up</span>
<span>here?</span>
</p>
<p begin="00:02:12.160" end="00:02:15.200" region="region_1">
<span style="style_1">This place is horrible.</span>
</p>
<p begin="00:02:20.240" end="00:02:22.280" region="region_1">
<span style="style_1">Smells like balls.</span>
</p>
<p begin="00:02:28.320" end="00:02:31.360" region="region_2">
<span style="style_2">We don&#39;t belong</span>
<br></br>
<span style="style_1">in this shithole.</span>
</p>
<p begin="00:02:31.400" end="00:02:33.440" region="region_2">
<span style="style_2">(computer playing</span>
<br></br>
<span style="style_1">electronic melody)</span>
</p>
</div>
</body>
</tt>
+37
View File
@@ -0,0 +1,37 @@
WEBVTT
Region: id=fred lines=3 regionanchor=0%,100% scroll=up viewportanchor=10%,90% width=40%
Region: id=bill lines=3 regionanchor=100%,100% scroll=up viewportanchor=90%,90% width=40%
NOTE this a nice example
of a VTT
1
00:01:39.000 --> 00:01:41.040 region:bill
(deep rumbling)
NOTE This a comment inside the VTT
and this is the second line
2
00:02:04.080 --> 00:02:07.120 align:left position:10%,start region:fred size:35%
MAN:
How did we end up here?
3
00:02:12.160 --> 00:02:15.200
This place is horrible.
4
00:02:20.240 --> 00:02:22.280
Smells like balls.
5
00:02:28.320 --> 00:02:31.360
We don't belong
in this shithole.
6
00:02:31.400 --> 00:02:33.440
(computer playing
electronic melody)