예제 #1
0
        private void AudioFeaturesCommand(CommandLineApplication tracks)
        {
            tracks.Command("audio-features", (audioFeatures) =>
            {
                audioFeatures.Description = "Gets audio-features of one or multiple tracks.";

                var ids = audioFeatures.Argument <List <SpotifyUri> >(
                    "ids|uris",
                    "A list of Spotify track ids or uris, seperated by comma."
                    ).IsRequired();

                var output = new OutputArgument(audioFeatures);
                var onJson = output.WithFormat("json", true);

                audioFeatures.OnExecuteAsync(async(cancel) =>
                {
                    _spotifyService.EnsureCredentialsSet(out var spotify);

                    var features = await spotify.Tracks.GetSeveralAudioFeatures(new TracksAudioFeaturesRequest(
                                                                                    ids.ParsedValue.Select((uri) => uri.Id).ToList()
                                                                                    ));

                    onJson(() => features.AudioFeatures.ForEach((track) => _console.WriteObject(track)));
                });
            });
        }
예제 #2
0
        public void Register(CommandLineApplication app)
        {
            app.Command("user-profile", (userProfile) =>
            {
                userProfile.Description = "Gets information about a spotify user.";

                var ids = userProfile.OptionalOption <List <string> >(
                    "-i|--ids",
                    "A list of Spotify user ids, seperated by comma",
                    "currently logged in user",
                    CommandOptionType.SingleValue
                    );
                var output = new OutputArgument(userProfile);

                var onJson = output.WithFormat("json", true);
                var onId   = output.WithFormat("id");
                var onUri  = output.WithFormat("uri");

                userProfile.OnExecuteAsync(async(cancel) =>
                {
                    if (ids.ParsedValue != null)
                    {
                        _spotifyService.EnsureCredentialsSet(out var spotify);

                        var users = await Task.WhenAll(ids.ParsedValue.Select((id) => spotify.UserProfile.Get(id)));
                        foreach (var user in users)
                        {
                            onJson(() => _console.WriteObject(user));
                            onId(() => _console.WriteLine(user.Id));
                            onUri(() => _console.WriteLine(user.Uri));
                        }
                    }
                    else
                    {
                        _spotifyService.EnsureUserLoggedIn(out var spotify);

                        var user = await spotify.UserProfile.Current();
                        onJson(() => _console.WriteObject(user));
                        onId(() => _console.WriteLine(user.Id));
                        onUri(() => _console.WriteLine(user.Uri));
                    }
                });
            });
        }
예제 #3
0
        private void GetCommand(CommandLineApplication tracks)
        {
            tracks.Command("get", (get) =>
            {
                get.Description = "Gets information about one or multiple tracks.";

                var ids = get.Argument <List <SpotifyUri> >(
                    "ids|uris",
                    "A list of Spotify track ids or uris, seperated by comma."
                    ).IsRequired();

                var market = get.OptionalOption <string>(
                    "-m|--market",
                    "The specifc market, used for track re-linking",
                    "none",
                    CommandOptionType.SingleValue
                    );

                var output = new OutputArgument(get);
                var onJson = output.WithFormat("json", true);
                var onId   = output.WithFormat("id");
                var onUri  = output.WithFormat("uri");

                get.OnExecuteAsync(async(cancel) =>
                {
                    _spotifyService.EnsureCredentialsSet(out var spotify);

                    var tracks = await spotify.Tracks.GetSeveral(new TracksRequest(
                                                                     ids.ParsedValue.Select((uri) => uri.Id).ToList()
                                                                     )
                    {
                        Market = market.Value()
                    });

                    onJson(() => tracks.Tracks.ForEach((track) => _console.WriteObject(track)));
                    onId(() => tracks.Tracks.ForEach((track) => _console.WriteLine(track.Id)));
                    onUri(() => tracks.Tracks.ForEach((track) => _console.WriteLine(track.Uri)));
                });
            });
        }
예제 #4
0
        private void AudioAnalysisCommand(CommandLineApplication tracks)
        {
            tracks.Command("audio-analysis", (audioAnalysis) =>
            {
                audioAnalysis.Description = "Gets audio-analysis of one track.";

                var id = audioAnalysis.Argument <SpotifyUri>(
                    "id|uri",
                    "A Spotify track id or uri."
                    ).IsRequired();

                var output = new OutputArgument(audioAnalysis);
                var onJson = output.WithFormat("json", true);

                audioAnalysis.OnExecuteAsync(async(cancel) =>
                {
                    _spotifyService.EnsureCredentialsSet(out var spotify);

                    var analysis = await spotify.Tracks.GetAudioAnalysis(id.ParsedValue.Id);

                    onJson(() => _console.WriteObject(analysis));
                });
            });
        }
예제 #5
0
        private void OfUserCommand(CommandLineApplication playlists)
        {
            playlists.Command("of-user", (ofUser) =>
            {
                ofUser.Description = "Get a List of a User's Playlists";

                var userId = ofUser.OptionalOption <string>(
                    "-u|--user-id",
                    "The user’s Spotify user ID.",
                    "Currently logged in user",
                    CommandOptionType.SingleValue
                    );

                var paging = new PagingOptions(ofUser);

                var output = new OutputArgument(ofUser);
                var onJson = output.WithFormat("json", true);
                var onId   = output.WithFormat("id");
                var onUri  = output.WithFormat("uri");

                ofUser.OnExecuteAsync(async(cancel) =>
                {
                    if (userId.HasValue())
                    {
                        _spotifyService.EnsureCredentialsSet(out var spotify);
                        var page = await spotify.Playlists.GetUsers(userId.Value() !, new PlaylistGetUsersRequest
                        {
                            Limit  = paging.Limit.ParsedValue ?? 50,
                            Offset = paging.Offset.ParsedValue ?? 0
                        });
                        if (paging.All.HasValue())
                        {
                            var allPages = await spotify.PaginateAll(page);
                            onJson(() => allPages.ToList().ForEach((playlist) => _console.WriteObject(playlist)));
                            onId(() => allPages.ToList().ForEach((playlist) => _console.WriteLine(playlist.Id)));
                            onUri(() => allPages.ToList().ForEach((playlist) => _console.WriteLine(playlist.Uri)));
                        }
                        else
                        {
                            onJson(() => _console.WriteObject(page));
                            onId(() => page.Items.ForEach((item) => _console.WriteLine(item.Id)));
                            onUri(() => page.Items.ForEach((item) => _console.WriteLine(item.Uri)));
                        }
                    }
                    else
                    {
                        _spotifyService.EnsureUserLoggedIn(out var spotify);
                        var page = await spotify.Playlists.CurrentUsers(new PlaylistCurrentUsersRequest
                        {
                            Limit  = paging.Limit.ParsedValue ?? 50,
                            Offset = paging.Offset.ParsedValue ?? 0
                        });
                        if (paging.All.HasValue())
                        {
                            var allPages = await spotify.PaginateAll(page);
                            onJson(() => allPages.ToList().ForEach((playlist) => _console.WriteObject(playlist)));
                            onId(() => allPages.ToList().ForEach((playlist) => _console.WriteLine(playlist.Id)));
                            onUri(() => allPages.ToList().ForEach((playlist) => _console.WriteLine(playlist.Uri)));
                        }
                        else
                        {
                            onJson(() => _console.WriteObject(page));
                            onId(() => page.Items.ForEach((item) => _console.WriteLine(item.Id)));
                            onUri(() => page.Items.ForEach((item) => _console.WriteLine(item.Uri)));
                        }
                    }
                });