示例#1
0
文件: update.go 项目: jcswart/godock
// Program launched. Create and activate applet.
//
func main() {
	app := Update()

	log.SetPrefix(term.Yellow("[" + app.AppletName + "] "))
	log.Println(term.Green("Applet started"))
	defer log.Println(term.Yellow("Applet stopped"))

	// Start main loop and wait for events. Until the End signal is received from the dock.
	ticker, restart := app.poller.NewTicker()
	for { // Main loop, waiting for events.
		select {
		case <-app.Close: // That's all folks.
			return

		// not triggered yet.
		case <-restart: // Want to recheck now ?
			log.Println(term.Yellow("timer restart"))
			ticker, restart = app.poller.NewTicker()

		case <-ticker.C: // It's time to work !
			//~ log.Println(term.Yellow("timer"))
			app.poller.Check()
		}
	}
}
示例#2
0
文件: opensubs.go 项目: sqp/opensubs
func NewQuery(userAgent string) *Query {
	log.SetPrefix(term.Yellow("[OpenSubs] "))
	return &Query{
		hashs:     make(map[string]string),
		userAgent: userAgent,
	}
}
示例#3
0
文件: opensubs.go 项目: sqp/opensubs
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()
}
示例#4
0
文件: opensubs.go 项目: sqp/opensubs
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)
}
示例#5
0
文件: opensubs.go 项目: sqp/opensubs
func warn(source string, data ...interface{}) {
	args := []interface{}{}
	args = append(args, term.Yellow(source))
	args = append(args, data...)
	log.Println(args...)
}