示例#1
0
func (tp TracksProcessor) ProcessAll(tracks []track.Track) {
	if len(tracks) == 0 {
		ui.Term("there are no tracks to download", nil)
	}

	var errors []string
	// Start with last track
	for i := len(tracks) - 1; i >= 0; i-- {
		track := tracks[i]
		if err := tp.Process(track); err != nil {
			errors = append(errors, track.Fullname()+": "+err.Error())
			ui.Error("there was an error while downloading "+track.Fullname(), err)
		}
		ui.Println("")
	}

	if len(errors) > 0 {
		ui.Println(ui.RedString("There were errors while downloading tracks:"))
		for _, errText := range errors {
			ui.Println(ui.RedString("  " + errText))
		}
		ui.Println("")
	}

	ui.Success("Done!")
	ui.Quit()
}
示例#2
0
func (tp TracksProcessor) Process(t track.Track) error {
	// Download track
	ui.Println("Downloading " + t.Artist() + " - " + t.Title())
	trackPath := filepath.Join(tp.DownloadFolder, t.Filename())
	if _, e := os.Create(trackPath); e != nil {
		return fmt.Errorf("couldn't create track file:", e)
	}
	if e := downloadTrack(t, trackPath); e != nil {
		return fmt.Errorf("couldn't download track:", e)
	}

	// err lets us to not prevent the processing of track further.
	var err error

	// Download artwork
	var artworkPath string
	var artworkBytes []byte
	artworkFile, e := ioutil.TempFile("", "")
	if e != nil {
		err = fmt.Errorf("couldn't create artwork file:", e)
	} else {
		artworkPath = artworkFile.Name()
		if e = downloadArtwork(t, artworkPath); e != nil {
			err = fmt.Errorf("couldn't download artwork file:", e)
		}
		if err == nil {
			artworkBytes, e = ioutil.ReadAll(artworkFile)
			if e != nil {
				err = fmt.Errorf("couldn't read artwork file:", e)
			}
		}
	}

	// Tag track
	if e := tag(t, trackPath, artworkBytes); e != nil {
		err = fmt.Errorf("coudln't tag file:", e)
	}

	// Delete artwork
	if e := artworkFile.Close(); e != nil {
		err = fmt.Errorf("couldn't close artwork file:", e)
	}
	if e := os.Remove(artworkPath); e != nil {
		err = fmt.Errorf("couldn't remove artwork file:", e)
	}

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

	return err
}
示例#3
0
文件: client.go 项目: bogem/nehm
func UID(permalink string) string {
	params := url.Values{}
	params.Set("url", soundCloudLink+permalink)

	ui.Println("Getting ID of user")
	bUser, err := resolve(params)
	if err != nil {
		ui.Term("there was a problem by resolving an id of user", err)
	}

	var jUser JSONUser
	if err := json.Unmarshal(bUser, &jUser); err != nil {
		ui.Term("couldn't unmarshall JSON with user object", err)
	}

	return strconv.Itoa(jUser.ID)
}
示例#4
0
func downloadArtwork(t track.Track, path string) error {
	ui.Println("Downloading artwork")
	return runDownloadCmd(path, t.ArtworkURL())
}
示例#5
0
文件: version.go 项目: bogem/nehm
func showVersion(cmd *cobra.Command, args []string) {
	ui.Println(version)
}