The package of one hash function to match subtitle files against movie files. For a deeper understanding of the algorithm, feel free to explore the OpenSubtitles API documentation.
moviehash
is available as a package.
The package works with Go version 1.17 and newer.
Use the get
command to install the package:
go get github.com/opensubtitlescli/moviehash@latest
... and then import it into your project:
import "github.com/opensubtitlescli/moviehash"
Imagine you have an AVI file from OpenSubtitles and you want to calculate its hash:
package main
import (
"fmt"
"os"
"github.com/opensubtitlescli/moviehash"
)
func main() {
f, _ := os.Open("./breakdance.avi")
h, _ := moviehash.Sum(f)
fmt.Println(h)
}
... result will be:
8e245d9679d31e12
Warning
The error handling is left out for the sake of brevity. However, do not ignore this in actual code.
Additionally, moviehash
is also available as a command-line tool.
Use Go itself to install the command:
go install github.com/opensubtitlescli/moviehash/cmd/moviehash@latest
... or manually download the release binary that matches your operating system.
moviehash: calculate the moviehash of the file.
usage: moviehash [-hv] <path...>
Imagine you have an AVI file from OpenSubtitles and you want to calculate its hash:
moviehash ./breakdance.avi
... output will be:
8e245d9679d31e12
To work on the package, install the following versions of the tools:
$ cat .tool-versions
go 1.17
golangci-lint 1.55
goreleaser 1.25
# make 4.4
Once you have installed the tools, download the dependencies:
go mod download
Now you are ready to start working, good luck:
$ make
all Run all recipes.
build Build a binary.
help Show help information.
lint Lint the source code.
test Run tests.
Thanks to everyone who has previously implemented this algorithm in various languages. Your work has been a joy to read and has greatly contributed to my understanding.
MIT (c) Ivan Uhalin