initial commit
This commit is contained in:
commit
b516177d7c
5
go.mod
Normal file
5
go.mod
Normal file
@ -0,0 +1,5 @@
|
||||
module git.milar.in/animan/parsers
|
||||
|
||||
go 1.18
|
||||
|
||||
require git.milar.in/animan/model v0.0.0-20220803215306-905563410463
|
2
go.sum
Normal file
2
go.sum
Normal file
@ -0,0 +1,2 @@
|
||||
git.milar.in/animan/model v0.0.0-20220803215306-905563410463 h1:M7Xxqbv7WQ3xwW66APwI7KQ8wD8IN/v6ZZbq1JB1T2M=
|
||||
git.milar.in/animan/model v0.0.0-20220803215306-905563410463/go.mod h1:FmgisUVGJd8EEvGP4uk9pEv6Ic9aiEhAy5eZF8zZsgU=
|
11
lang_parser_funcs.go
Normal file
11
lang_parser_funcs.go
Normal file
@ -0,0 +1,11 @@
|
||||
package parsers
|
||||
|
||||
import "regexp"
|
||||
|
||||
type LanguageParserFunc func(str string) []string
|
||||
|
||||
var SquareBracketsLanguageParserRegex = regexp.MustCompile(`\[.+?\]`)
|
||||
|
||||
func SquareBracketsLanguageParser(str string) []string {
|
||||
return SquareBracketsLanguageParserRegex.FindAllString(str, -1)
|
||||
}
|
25
parsers.go
Normal file
25
parsers.go
Normal file
@ -0,0 +1,25 @@
|
||||
package parsers
|
||||
|
||||
import "git.milar.in/animan/model"
|
||||
|
||||
/*
|
||||
how to get all torrent names on a nyaa page:
|
||||
|
||||
let s = "";
|
||||
document.querySelectorAll("tr > td:nth-child(2) > a:not(.comments)").forEach((element, index) => {
|
||||
s += element.textContent + "\n";
|
||||
})
|
||||
console.log(s);
|
||||
|
||||
*/
|
||||
|
||||
var Parsers = []model.Parser{
|
||||
{
|
||||
Identity: "Erai-Raws",
|
||||
TorrentParser: torrentNameEpLangsRegex(
|
||||
`^\[Erai-raws\] (.*) - (.*?) \[1080p\](?:\[HEVC\])?(?:\[Multiple Subtitle\])? (\[.*?\]+)?$`,
|
||||
SquareBracketsLanguageParser,
|
||||
),
|
||||
FileParser: nil,
|
||||
},
|
||||
}
|
58
torrent_parser_funcs.go
Normal file
58
torrent_parser_funcs.go
Normal file
@ -0,0 +1,58 @@
|
||||
package parsers
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"git.milar.in/animan/model"
|
||||
)
|
||||
|
||||
// torrentNameEpRegex returns a TorrentParserFunc with the following regex groups:
|
||||
// 1: name
|
||||
// 2: episode
|
||||
func torrentNameEpRegex(regex string) model.TorrentParserFunc {
|
||||
pattern := regexp.MustCompile(regex)
|
||||
|
||||
return func(parser *model.Parser, torrent *model.Torrent) (ParsedTorrent *model.ParsedTorrent, ok bool) {
|
||||
matches := pattern.FindStringSubmatch(torrent.Title)
|
||||
if len(matches) <= 2 {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
name := matches[1]
|
||||
episode, ok := atoi(matches[2])
|
||||
|
||||
return &model.ParsedTorrent{
|
||||
Torrent: torrent,
|
||||
Name: name,
|
||||
Episode: episode,
|
||||
Parser: parser,
|
||||
}, ok
|
||||
}
|
||||
}
|
||||
|
||||
// torrentNameEpRegex returns a TorrentParserFunc with the following regex groups:
|
||||
// 1: name
|
||||
// 2: episode
|
||||
// 3: languages
|
||||
func torrentNameEpLangsRegex(regex string, languageParser LanguageParserFunc) model.TorrentParserFunc {
|
||||
pattern := regexp.MustCompile(regex)
|
||||
|
||||
return func(parser *model.Parser, torrent *model.Torrent) (ParsedTorrent *model.ParsedTorrent, ok bool) {
|
||||
matches := pattern.FindStringSubmatch(torrent.Title)
|
||||
if len(matches) <= 2 {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
name := matches[1]
|
||||
episode, ok := atoi(matches[2])
|
||||
languages := languageParser(matches[3])
|
||||
|
||||
return &model.ParsedTorrent{
|
||||
Torrent: torrent,
|
||||
Name: name,
|
||||
Episode: episode,
|
||||
Languages: languages,
|
||||
Parser: parser,
|
||||
}, ok
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user