Beispiel #1
0
// initializeItunesPlaylist initializes itunesPlaylist value. If there is no
// itunesPlaylist set up, then itunesPlaylist set up to blank string. Blank
// string is the sign, what tracks should not to be added to iTunes.
//
// initializeItunesPlaylist sets blank string to config, if OS is darwin
func initializeItunesPlaylist(cmd *cobra.Command) {
	var playlist string

	if runtime.GOOS == "darwin" {
		if flagChanged(cmd.Flags(), "itunesPlaylist") {
			playlist = itunesPlaylist
		} else {
			playlist = config.Get("itunesPlaylist")
		}

		if playlist == "" {
			ui.Warning("you didn't set an iTunes playlist. Tracks won't be added to iTunes.")
		} else {
			playlistsList, err := applescript.ListOfPlaylists()
			if err != nil {
				ui.Term("couldn't get list of playlists", err)
			}
			if !strings.Contains(playlistsList, playlist) {
				ui.Term("playlist "+playlist+" doesn't exist. Please enter correct name.", nil)
			}
		}
	}

	config.Set("itunesPlaylist", playlist)
}
Beispiel #2
0
func handleError(err error) {
	switch {
	case strings.Contains(err.Error(), "403"):
		ui.Term("you're not allowed to see these tracks", nil)
	case strings.Contains(err.Error(), "404"):
		ui.Term("there are no tracks", nil)
	}
}
Beispiel #3
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()
}
Beispiel #4
0
func getTracks(cmd *cobra.Command, args []string) {
	initializeConfig(cmd)

	tp := tracksprocessor.NewConfiguredTracksProcessor()

	var arg string
	if len(args) == 0 {
		arg = "1"
	} else {
		arg = args[0]
	}

	var downloadTracks []track.Track
	var err error
	if isVKWallURL(arg) {
		downloadTracks, err = getTracksFromVKWall(arg)
	} else if num, err := strconv.Atoi(arg); err == nil {
		downloadTracks, err = getLastTracks(uint(num))
	} else {
		ui.Term("you've entered invalid argument. Run 'vnehm get --help' for usage.", nil)
	}

	if err != nil {
		handleError(err)
	}

	tp.ProcessAll(downloadTracks)
}
Beispiel #5
0
// initializeConfig initializes a config with flags.
func initializeConfig(cmd *cobra.Command) {
	err := config.ReadInConfig()
	if err == config.ErrNotExist {
		ui.Warning("there is no config file. Read README to configure vnehm")
	} else if err != nil {
		ui.Term("", err)
	}
	checkToken()

	loadDefaultSettings()

	initializeDlFolder(cmd)
	initializeItunesPlaylist(cmd)
}
Beispiel #6
0
func invalidURLMessage() {
	ui.Term("you've entered invalind URL!\nPlease execute `auth` command one more time and check input data\nIf you can't solve this problem, please write an issue on GitHub page: https://github.com/bogem/vnehm", nil)
}
Beispiel #7
0
func checkToken() {
	if config.Get("token") == "" {
		ui.Term("you aren't authorized. Please execute `vnehm auth` command to authorize", nil)
	}
}