func Load(configPath string, dataPath string) { ConfigPath = DefaultConfigPath(configPath) DataPath = DefaultDataPath(dataPath) CreateDefaultConfig(ConfigPath) CreateDataPath(DataPath) fmt.Println("Config: %q", ConfigPath) config, err := loadJsonConfig(ConfigPath) if err != nil { panic(err) } Config.WeatherUndergroundKey = config["weather_underground_key"] Config.WeatherUndergroundLocation = config["weather_underground_location"] observer.Notify("config.loaded", struct{}{}) }
func Play(song library.Song) error { LastSong = CurrentSong CurrentSong = &song log.Printf("player: playing %q (%f)", song.Path, song.Rank) logMetadata(song.Path) if sleepPlayer { playerCmd = exec.Command("sleep", "5") } else { playerCmd = exec.Command(playerBin, song.Path) } err := playerCmd.Run() if err != nil { return fmt.Errorf("player: %v", err) } observer.Notify("player.played", &song) return nil }
// loads Songs from either song_hashes.txt or songs.txt (first to exist). // loads the path graph func Load() { songHashMap = make(map[string][]*Song, 1000) songPathMap = make(map[string]*Song, 1000) songHashesPath := path.Join(config.DataPath, "song_hashes.txt") //songsPath := path.Join(config.DataPath, "songs.txt") songErrorsPath := path.Join(config.DataPath, "song_errors.txt") loadSongErrors(songErrorsPath) //loadSongs(songsPath) loadSongHashesMap(songHashesPath) go IdentifySongs(Songs, songHashesPath) observer.Notify("library.loaded", struct{}{}) log.Printf("Loaded %d songs", len(Songs)) PathRoots = graph.LoadGraph(Songs) }
// Build up the SongKarma map, and spread impressiosn to library.Song.Rank func Load() error { SongKarma = make(map[string]int) impressionCount := 0 timestampIdx := 0 logTypeIdx := 1 // logType = karma hashIdx := 2 impressionIdx := 3 // logType = env tagIdx := 2 valIdx := 3 impressionLogPath := path.Join(config.DataPath, "impression.log") log.Printf("Reading impressions from: %q", impressionLogPath) f, err := os.Open(impressionLogPath) if err != nil { return err } defer f.Close() r := csv.NewReader(f) r.Comma = '\t' r.Comment = '#' records, err := r.ReadAll() if err != nil { return err } for _, record := range records { if len(record) != 4 { return fmt.Errorf("Malformed impression.log, wrong number of columns %d expected 4", len(record)) } timestampStr := record[timestampIdx] timestamp, _ := time.Parse("2016/02/21 20:18:49.091737", timestampStr) logType := record[logTypeIdx] switch logType { case "karma": hash := record[hashIdx] impression, _ := strconv.Atoi(record[impressionIdx]) SongKarma[hash] += impression song, err := library.ByHash(hash) if err != nil { continue } impressionCount++ historicalEnv.Impress(timestamp, song, impression) go song.PathGraphImpress(impression) case "env": sensor := record[tagIdx] val := record[valIdx] historicalEnv.Update(timestamp, sensor, val) } } //historicalEnv.Print() //log.Printf("%v", SongKarma) sort.Sort(library.Songs) observer.Notify("karma.loaded", struct{}{}) log.Printf("Loading karma: %d impressions loaded", impressionCount) return nil }
func Skip() error { observer.Notify("player.skip", CurrentSong) return Stop() }