示例#1
0
文件: artisttags.go 项目: andynu/rfk
func main() {

	library.Load()

	api := lookupApi{}
	api.ConnectWithConfig("lastfm.json")

	artists := library.Artists()
	artist_count := len(artists)
	fmt.Printf("Artist Count: %d\n", artist_count)

	outPath := path.Join(config.DataPath, "artist_tags.txt")
	f, err := os.OpenFile(outPath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0660)
	if err != nil {
		panic(fmt.Errorf("%q: %v", outPath, err))
	}
	csv := csv.NewWriter(f)

	ticker := time.NewTicker(time.Millisecond * 201)
	i := 0
	for t := range ticker.C {
		fmt.Println("Tick at", t)
		if i >= len(artists) {
			break
		}

		artist := artists[i]
		i += 1

		mbid, err := api.artistMbid(artist)
		if err != nil {
			fmt.Printf("%v\n", err)
			continue
		}

		tags := api.topTagsMbid(mbid)

		var row []string
		row = append(row, artist)
		row = append(row, mbid)
		row = append(row, tags...)
		csv.Write(row)

		fmt.Printf("%q\t%s\n", artist, strings.Join(tags, "\t"))
		fmt.Printf("progress:\t%d of %d (%d%%)\n", i, artist_count, i/artist_count*100)
	}

}
示例#2
0
文件: server.go 项目: andynu/rfk
func main() {
	command := flag.String("e", "", "command")
	configPath := flag.String("c", "", "config path")
	dataPath := flag.String("d", "", "data path")
	webPlayerOnly := flag.Bool("webplayer", false, "webplayer; no mpg123 output")
	startPaused := flag.Bool("paused", false, "start paused")
	flag.Parse()

	config.Load(*configPath, *dataPath)

	ensureBinaryExists("mpg123")
	ensureSongs()

	switch *command {
	case "add":
		library.AddPaths(flag.Args())

	default:

		library.Load()
		dj.SetSongs(library.Songs)

		if *webPlayerOnly {
			player.Silence()
		}

		if *startPaused {
			player.Pause()
		}

		go env.Updater()

		go rpc.Listener()
		go console.Listener()
		go rest.Listener()

		player.PlaySongs()

	} // switch

	doneCh := make(chan struct{})
	<-doneCh
}
示例#3
0
文件: graph.go 项目: andynu/rfk
func main() {
	observer.Observe("library.loaded", func(msg interface{}) {
		fmt.Println("initializing graph building")
		// Load unique paths
		pathsm := make(map[string]bool)
		for _, song := range library.Songs {
			path_parts := strings.Split(song.Path, "/")
			plen := len(path_parts)
			partial_path := ""
			for p, path_part := range path_parts {
				if p > 0 {
					partial_path += "/"
				}
				if p == plen-1 {
					break
				}
				partial_path += path_part
				pathsm[partial_path] = true
			}
		}

		var paths []string
		for path := range pathsm {
			paths = append(paths, path)
		}
		sort.Strings(paths)
		fmt.Printf("paths: %d\n", len(paths))

		graph := make([][]int, len(library.Songs))
		for i := range library.Songs {
			graph[i] = make([]int, len(paths))
		}

		fmt.Println("connecting edges")
		m := 0
		c := 0
		// Connect edges
		for _, song := range library.Songs {
			// find connected songs
			c += 1
			for k, path := range paths {
				if strings.HasPrefix(song.Path, path) {
					graph[songIdx(song)][k] += 1
					m += 1
				}
			}
		}
		fmt.Printf("consider: %d\n", c)
		fmt.Printf("matching: %d\n", m)

		// output graph
		filename := "graph.csv"
		f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0600)
		if err != nil {
			panic(err)
		}
		defer f.Close()
		for row := 0; row < len(library.Songs); row += 1 {
			write(f, strconv.Itoa(row))
			for col := 0; col < len(paths); col += 1 {
				//if graph[row][col] != 0 {
				//  fmt.Printf("%d - %d : %d", row, col, graph[row][col])
				//}
				write(f, ",")
				write(f, strconv.Itoa(graph[row][col]))
			}
			write(f, "\n")
		}
		fmt.Println("done")

	})

	library.Load()
}