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
}
Exemplo n.º 2
0
func contains(s []track.Track, t track.Track) bool {
	for _, v := range s {
		if v.ID() == t.ID() {
			return true
		}
	}
	return false
}
Exemplo n.º 3
0
func tag(t track.Track, trackPath string) error {
	tag, err := id3v2.Open(trackPath)
	if err != nil {
		return err
	}
	defer tag.Close()

	// If there are already frames in tag, do nothing
	if tag.Count() > 0 {
		return nil
	}

	tag.SetArtist(t.Artist())
	tag.SetTitle(t.Title())
	return tag.Save()
}
Exemplo n.º 4
0
func downloadTrack(t track.Track, path string) error {
	ui.Println("Downloading " + t.Artist() + " - " + t.Title())
	return runDownloadCmd(path, t.URL())
}