Ejemplo n.º 1
0
func Listener() {
	reader := bufio.NewReader(os.Stdin)
	for {
		text, _ := reader.ReadString('\n')
		text = strings.TrimSuffix(text, "\n")
		args := strings.Split(text, " ")
		command := args[0]
		switch command {
		case "n":
			log.Printf("cmd: n - Next (no punishment)")
			api.SkipNoPunish()

		case "s":
			log.Printf("cmd: s - Skip")
			api.Skip()

		case "p":
			log.Printf("cmd: p - PlayPause")
			api.PlayPause()

		case "r":
			log.Printf("cmd: r - Reward")
			api.Reward()

		case "search":
			term := strings.Join(args[1:], " ")
			log.Printf("cmd: search - %q", term)
			songs := api.Search(term)
			printSearchResults(term, songs)

		case "request":
			term := strings.Join(args[1:], " ")
			log.Printf("cmd: request - %q", term)
			songs := api.SearchRequest(term)
			fmt.Printf("Requested %d songs\n", len(songs))

		case "taglast":
			tag := strings.Join(args[1:], " ")
			log.Printf("cmd: tag last song - %q", tag)
			api.TagLastSong(tag)

		case "tag":
			tag := strings.Join(args[1:], " ")
			log.Printf("cmd: tag current song - %q", tag)
			api.TagCurrentSong(tag)

		case "clear":
			log.Printf("cmd: clear request")
			api.ClearRequests()
			fmt.Printf("Requests Cleared\n")

		default:
			log.Printf("cmd: %q - unknown command", text)
		}
	}
}
Ejemplo n.º 2
0
Archivo: rest.go Proyecto: andynu/rfk
func requestsHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")
	w.Header().Set("Content-type", "application/javascript")
	switch r.Method {
	case "GET":
		fmt.Fprintf(w, toJSON(api.Requests()))
	case "DELETE":
		api.ClearRequests()
		fmt.Fprintf(w, toJSON(api.Requests()))
	}
}
Ejemplo n.º 3
0
Archivo: rest.go Proyecto: andynu/rfk
func clearRequestsHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")
	w.Header().Set("Content-type", "application/javascript")
	api.ClearRequests()
	fmt.Fprintf(w, toJSON(api.Requests()))
}