Exemplo n.º 1
0
func (tp TracksProcessor) Process(t track.Track) error {
	// Download track
	trackPath := filepath.Join(tp.DownloadFolder, t.Filename())
	if _, e := os.Create(trackPath); e != nil {
		return fmt.Errorf("couldn't create track file: %v", e)
	}
	if e := downloadTrack(t, trackPath); e != nil {
		return fmt.Errorf("couldn't download track: %v", e)
	}

	// Tag track
	var err error
	if err = tag(t, trackPath); err != nil {
		// Don't return error immediately, because it isn't important reason
		// to prevent the processing of track further.
		err = fmt.Errorf("coudln't tag file: %v", err)
	}

	// Add to iTunes
	if tp.ItunesPlaylist != "" {
		ui.Println("Adding to iTunes")
		if e := applescript.AddTrackToPlaylist(trackPath, tp.ItunesPlaylist); e != nil {
			return fmt.Errorf("couldn't add track to playlist: %v", e)
		}
	}

	return err
}