-
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.
api breakage: rework the subtitle dl code, added usage example
- Loading branch information
1 parent
e2ac6cb
commit 20ea91b
Showing
7 changed files
with
118 additions
and
79 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 @@ | ||
conformance-files/ |
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,7 @@ | ||
#!/bin/sh | ||
|
||
mkdir -p conformance-files/thesubdb | ||
|
||
# fetch conformance check videos from http://thesubdb.com/api/ | ||
curl http://thesubdb.com/api/samples/dexter.mp4 -o conformance-files/thesubdb/dexter.mp4 | ||
curl http://thesubdb.com/api/samples/justified.mp4 -o conformance-files/thesubdb/justified.mp4 |
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,21 @@ | ||
package subtitles | ||
|
||
import "os" | ||
|
||
// SubFinder represents a video being queried for subtitles | ||
type SubFinder struct { | ||
FileName string | ||
Language string | ||
VideoFile *os.File | ||
Quiet bool | ||
} | ||
|
||
// NewSubFinder creates a SubFilePair object used to download subs for a video | ||
func NewSubFinder(video *os.File, fileName string, language string) *SubFinder { | ||
|
||
return &SubFinder{ | ||
FileName: fileName, | ||
Language: language, | ||
VideoFile: video, | ||
} | ||
} |
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 |
---|---|---|
@@ -1,30 +1,53 @@ | ||
package subtitles | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCreateMovieHashFromMovieFile(t *testing.T) { | ||
func TestDownloadFromTheSubDb(t *testing.T) { | ||
|
||
fileName := createTempFile(1024 * 1024 * 2) | ||
fileName := createZeroedTempFile(1024 * 1024 * 4) | ||
defer os.Remove(fileName) | ||
|
||
hash, err := createMovieHashFromMovieFile(fileName) | ||
f, err := os.Open(fileName) | ||
assert.Equal(t, nil, err) | ||
|
||
hash, err := SubDbHashFromFile(f) | ||
assert.Equal(t, nil, err) | ||
assert.Equal(t, "38a503307786991a982f8ded498b90e0", hash) | ||
assert.Equal(t, "0dfbe8aa4c20b52e1b8bf3cb6cbdf193", hash) | ||
|
||
os.Remove(fileName) | ||
finder := NewSubFinder(f, fileName, "en") | ||
|
||
text, err := finder.TheSubDb("sandbox.thesubdb.com") | ||
assert.Equal(t, nil, err) | ||
assert.True(t, len(text) > 1000) | ||
} | ||
|
||
func TestDownloadFromTheSubDb(t *testing.T) { | ||
fileName := createZeroedTempFile(1024 * 1024 * 2) | ||
func subDbConformTest(t *testing.T, fileName string, expectedHash string) { | ||
if !exists(fileName) { | ||
fmt.Println("ERROR thesubdb.com conformance tests missing, run ./hash-conformance-deps if you want to run these tests") | ||
return | ||
} | ||
|
||
text, err := fromTheSubDb(fileName, "en", "sandbox.thesubdb.com") | ||
f, err := os.Open(fileName) | ||
assert.Equal(t, nil, err) | ||
assert.True(t, len(text) > 1000) | ||
|
||
os.Remove(fileName) | ||
hash, err := SubDbHashFromFile(f) | ||
assert.Equal(t, nil, err) | ||
assert.Equal(t, expectedHash, hash) | ||
} | ||
|
||
func TestSubDbHashFromFile(t *testing.T) { | ||
|
||
// NOTE for this to work, run "./hash-conformance-deps" to fetch needed files | ||
|
||
// http://thesubdb.com/api/samples/dexter.mp4 | ||
subDbConformTest(t, "conformance-files/thesubdb/dexter.mp4", "ffd8d4aa68033dc03d1c8ef373b9028c") | ||
|
||
// http://thesubdb.com/api/samples/justified.mp4 | ||
subDbConformTest(t, "conformance-files/thesubdb/justified.mp4", "edc1981d6459c6111fe36205b4aff6c2") | ||
} |