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 } }