func (q *Query) Get(n int) (subByRef, subByRef) { var dl []string needed := make(subIndex) // Parsing list byhash. Need one file for _, bylang := range q.byhash { // For each movie for _, list := range bylang { // For each lang if len(list) > 1 { warn("multiple ref for hash matched") } sort.Sort(byDownloads{list}) sub := list[0] needed[sub.IDSubtitleFile] = sub dl = append(dl, sub.IDSubtitleFile) } } //~ printSubByRef("Matched by Hash", q.byhash) // Parsing list byimdb to get multiple files. for imdb, bylang := range q.byimdb { // For each movie for _, list := range bylang { // For each lang sort.Sort(byDownloads{list}) count := 0 log.Println(term.Magenta("Movie found"), " imdb:", imdb) //strconv.Itoa(imdb)) for _, sub := range list { // each sub if n == -1 || count < n { // Unlimited or within limit: add to list. needed[sub.IDSubtitleFile] = sub dl = append(dl, sub.IDSubtitleFile) log.Println(term.Green(sub.SubLanguageID), sub.SubAddDate[:10], term.Yellow(sub.SubDownloadsCnt), sub.UserNickName, term.Bracket(sub.UserRank)) //~ break } else { log.Println(term.Magenta(sub.SubLanguageID), sub.SubAddDate, sub.UserNickName, term.Bracket(sub.UserRank), term.Yellow(sub.SubDownloadsCnt)) } count++ } } } return q.download(dl, needed) }
func printSubByRef(title string, byref subByRef) { if len(byref) == 0 { return } fmt.Println(term.Underscore + title + term.Reset) for imdb, bylang := range byref { fmt.Println(term.Red("Movie ref :"), imdb) for lang, list := range bylang { fmt.Println(" ", term.Yellow(lang)) for index, sub := range list { fmt.Println(" ", term.FgGreen, index, term.Reset, sub.SubAddDate[:10], term.Yellow(sub.SubDownloadsCnt), sub.UserNickName, term.Bracket(sub.UserRank)) //~ fmt.Printf(" ", " ", "#%d : %# v\n", index,sub) } } } fmt.Println() }