Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
github.com/dexterlb/osdb
This is a Golang client for Open Subtitles.
This project allows you to search and download subtitles from Open Subtitles. If you are only interested in searching or downloading then you should find what you need from the latest releases, otherwise the TODO section highlights what remains to be done regarding API coverage.
If you need (yet another) CLI interface for Open Subtitles, then install the latest Go release, and run:
go get github.com/oz/osdb && go install github.com/oz/osdb/cmd/osdb
Provided that you setup your Go environment correctly, you now have a basic
osdb
command to interact with OpenSubtitles' API.
$ osdb --help
Usage:
osdb get [--lang=<lang>] <file>
osdb (put|upload) <movie_file> <sub_file>
osdb imdb <query>...
osdb imdb show <movie id>
osdb -h | --help
osdb --version
Hence, to download French or English subtitles for a sample file:
$ osdb get --lang fra,eng sample.avi
- Getting fra subtitles for file: sample.avi
- No subtitles found!
- Getting eng subtitles for file: sample.avi
- Downloading to: sample.srt
The generated documentation for this package is available at: http://godoc.org/github.com/oz/osdb
To get started...
go get -d github.com/oz/osdb
,"github.com/oz/osdb"
in your Go code,To access the OpenSubtitles' XML-RPC server you first need to allocate a client, and then use it to login (even anonymously) in order to receive a session token. With that, you are finally be allowed to talk. Here is a short example:
package main
import "github.com/oz/osdb"
func main() {
c, err := osdb.NewClient()
if err != nil {
// ...
}
// Anonymous login will set c.Token when successful
if err = c.LogIn("", "", ""); err != nil {
// ...
}
// etc.
}
Although this library tries to be simple, to use OpenSubtitles' API you need to login first so as to receive a session token: without it you will not be able to call any API method.
c, err := osdb.NewClient()
if err != nil {
// ...
}
if err = c.LogIn("user", "password", "language"); err != nil {
// ...
}
// c.Token is now set, and subsequent API calls will not be refused.
However, you do not need to register a user. To login anonymously, just leave
the user
and password
parameters blank:
c.LogIn("", "", "")
Subtitle search can be done in a number of ways: using special file-hashes, IMDB movie IDs, or even using full-text queries. Hash-based search will generally yield the best results, so this is what is demoed next. However, in order to search with this method, you must have a movie file to hash.
path := "/path/to/movie.avi"
languages := []string{"eng"}
// Hash movie file, and search...
res, err := client.FileSearch(path, languages)
if err != nil {
// ...
}
for _, sub := range res {
fmt.Printf("Found %s subtitles file \"%s\" at %s\n",
sub.LanguageName, sub.SubFileName, sub.ZipDownloadLink)
}
Let's say you have just made a search, for example using FileSearch()
, and as
the API provided a few results, you decide to pick one for download:
subs, err := c.FileSearch(...)
// Download subtitle file, and write to disk using subs[0].SubFileName
if err := c.Download(&subs[0]); err != nil {
// ...
}
// Alternatively, use the filename of your choice:
if err := c.DownloadTo(&subs[0], "safer-name.srt"); err != nil {
// ...
}
Before trying to upload an allegedly "new" subtitles file to OSDB, you should always check whether they already have it.
As some movies fit on more than one "CD" (remember those?), you will need to
use the Subtitles
type (note the s?), one per subtitle file:
subs := osdb.Subtitles{
{
SubHash: subHash, // md5 hash of subtitle file
SubFileName: subFileName,
MovieHash: movieHash, // see osdb.Hash()
MovieByteSize: movieByteSize, // careful, it's a string...
MovieFileName: movieFileName,
},
}
Then simply feed that to HasSubtitles
, and you will be done.
found, err := c.HasSubtitles(subs)
if err != nil {
// ...
}
OSDB uses a custom checksum-hash to identify movie files. If you ever need these:
hash, err := osdb.Hash("somefile.avi")
if err != nil {
// ...
}
fmt.Println("hash: %x\n", hash)
If you have read OSDB's developer documentation, you should notice that you need to register an "official" user agent in order to use their API.
By default this library will present itself with the "osdb-go" agent, which is
fine for me. However, if you need to change this, simply set the client's
UserAgent
with:
c, err := osdb.NewClient()
if err != nil {
// ...
}
c.UserAgent = "My custom user agent"
BSD, see the LICENSE file.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.