Exemple #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.Newline()
	}

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

	ui.Success("Done!")
	ui.Quit()
}
Exemple #2
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
}
Exemple #3
0
func downloadTrack(t track.Track, path string) error {
	ui.Println("Downloading " + t.Artist() + " - " + t.Title())
	return runDownloadCmd(path, t.URL())
}
Exemple #4
0
func showMessage() {
	ui.Println("1. Open this link in your browser: " + client.AuthURL())
	ui.Println("2. Click \"Allow\"")
	ui.Print("3. Copy link from address bar of your browser and paste here: ")
}
Exemple #5
0
func showVersion(cmd *cobra.Command, args []string) {
	ui.Println(version)
}
Exemple #6
0
// getTracksFromVKWall returns an id of post. It knows, what uri is
// correct VK link to post.
func getTracksFromVKWall(uri string) ([]track.Track, error) {
	ui.Println("Downloading audio(s) from the post")
	index := strings.Index(uri, "wall")
	postID := uri[index+len("wall"):]
	return client.WallAudios(postID, config.Get("token"))
}