forked from Jessicaward/SpotNetCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Several Features & Bug Fixes
- Fixed Jessicaward#76, Jessicaward#73, Jessicaward#70 - Implemented Jessicaward#75, Jessicaward#74, Jessicaward#72, Jessicaward#71, Jessicaward#69
- Loading branch information
Showing
31 changed files
with
1,148 additions
and
537 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using SpotNetCore.Models; | ||
|
||
namespace SpotNetCore.Endpoints | ||
{ | ||
public class AlbumEndpoint | ||
{ | ||
private HttpClient _httpClient; | ||
|
||
internal AlbumEndpoint(HttpClient httpClient) | ||
{ | ||
_httpClient = httpClient; | ||
} | ||
|
||
public async Task<IEnumerable<SpotifyTrack>> GetAlbumTracks(String albumId) | ||
{ | ||
return await _httpClient.GetFromSpotifyJsonAsync<IEnumerable<SpotifyTrack>>($"/v1/albums/{albumId}/tracks"); | ||
} | ||
|
||
public async Task<IEnumerable<SpotifyTrack>> GetAlbumTracks(SpotifyAlbum album) | ||
{ | ||
return await GetAlbumTracks(album.Id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using SpotNetCore.Models; | ||
|
||
namespace SpotNetCore.Endpoints | ||
{ | ||
public class ArtistEndpoint | ||
{ | ||
private HttpClient _httpClient; | ||
|
||
public ArtistEndpoint(HttpClient httpClient) | ||
{ | ||
_httpClient = httpClient; | ||
} | ||
|
||
public async Task<IEnumerable<SpotifyTrack>> GetArtistTopTracks(string artistId) | ||
{ | ||
return await _httpClient.GetFromSpotifyJsonAsync<IEnumerable<SpotifyTrack>>($"/v1/artists/{artistId}/top-tracks"); | ||
} | ||
|
||
public async Task<IEnumerable<SpotifyAlbum>> GetArtistAlbums(string artistId) | ||
{ | ||
return await _httpClient.GetFromSpotifyJsonAsync<IEnumerable<SpotifyAlbum>>($"/v1/artists/{artistId}/albums?include_groups=album"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using SpotNetCore.Models; | ||
|
||
namespace SpotNetCore.Endpoints | ||
{ | ||
public class PlayerEndpoint | ||
{ | ||
private readonly HttpClient _httpClient; | ||
|
||
internal PlayerEndpoint(HttpClient httpClient) | ||
{ | ||
_httpClient = httpClient; | ||
} | ||
|
||
public async Task<HttpResponseMessage> Play() | ||
{ | ||
var response = await _httpClient.PutAsync("/v1/me/player/play", null); | ||
return response; | ||
} | ||
|
||
public async Task<HttpResponseMessage> Pause() | ||
{ | ||
var response = await _httpClient.PutAsync("/v1/me/player/pause", null); | ||
return response; | ||
} | ||
|
||
public async Task<HttpResponseMessage> Next() | ||
{ | ||
var response = await _httpClient.PostAsync("/v1/me/player/next", null); | ||
return response; | ||
} | ||
|
||
public async Task<HttpResponseMessage> Previous() | ||
{ | ||
var response = await _httpClient.PostAsync("/v1/me/player/previous", null); | ||
return response; | ||
} | ||
|
||
public async Task<HttpResponseMessage> Seek(int milliseconds) | ||
{ | ||
var response = await _httpClient.PutAsync($"/v1/me/player/seek?position_ms={milliseconds}", null); | ||
return response; | ||
} | ||
|
||
public async Task<HttpResponseMessage> Shuffle(bool state) | ||
{ | ||
var response = await _httpClient.PutAsync($"/v1/me/player/shuffle?state={state}", null); | ||
return response; | ||
} | ||
|
||
public async Task<HttpResponseMessage> Queue(string trackUri) | ||
{ | ||
var response = await _httpClient.PostAsync($"/v1/me/player/queue?uri={trackUri}", null); | ||
return response; | ||
} | ||
|
||
public async Task<SpotifyPlayerContext> Player() | ||
{ | ||
return await _httpClient.GetFromSpotifyJsonAsync<SpotifyPlayerContext>("/v1/me/player"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using SpotNetCore.Models; | ||
|
||
namespace SpotNetCore.Endpoints | ||
{ | ||
public class PlaylistEndpoint | ||
{ | ||
private HttpClient _httpClient; | ||
|
||
public PlaylistEndpoint(HttpClient httpClient) | ||
{ | ||
_httpClient = httpClient; | ||
} | ||
|
||
public Task<IEnumerable<SpotifyPlaylistTrack>> GetPlaylistTracks(string playlistId) | ||
{ | ||
return _httpClient.GetFromSpotifyJsonAsync<IEnumerable<SpotifyPlaylistTrack>>($"/v1/playlists/{playlistId}/tracks"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using SpotNetCore.Models; | ||
|
||
namespace SpotNetCore.Endpoints | ||
{ | ||
public class SearchEndpoint | ||
{ | ||
private HttpClient _httpClient; | ||
|
||
public SearchEndpoint(HttpClient httpClient) | ||
{ | ||
_httpClient = httpClient; | ||
} | ||
|
||
private async Task<SpotifySearchResult> Search(string query, string type, int limit = 10, int offset = 0) | ||
{ | ||
return await _httpClient.GetFromSpotifyJsonAsync<SpotifySearchResult>($"/v1/search?q={query}&type={type}&limit={limit}&offset={offset}"); | ||
} | ||
|
||
public async Task<IEnumerable<SpotifyTrack>> SearchTracks(string query, int limit = 10, int offset = 0) | ||
{ | ||
var data = await Search(query, "track", limit, offset); | ||
return data.Tracks.Items; | ||
} | ||
|
||
public async Task<IEnumerable<SpotifyAlbum>> SearchAlbums(string query, int limit = 10, int offset = 0) | ||
{ | ||
var data = await Search(query, "album", limit, offset); | ||
return data.Albums.Items; | ||
} | ||
|
||
public async Task<IEnumerable<SpotifyPlaylist>> SearchPlaylists(string query, int limit = 10, int offset = 0) | ||
{ | ||
var data = await Search(query, "playlist", limit, offset); | ||
return data.Playlists.Items; | ||
} | ||
|
||
public async Task<IEnumerable<SpotifyArtist>> SearchArtists(string query, int limit = 10, int offset = 0) | ||
{ | ||
var data = await Search(query, "artist", limit, offset); | ||
return data.Artists.Items; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
namespace SpotNetCore.Implementation | ||
{ | ||
public class AppConstants | ||
{ | ||
public static readonly int CallbackPort = 5000; | ||
public static readonly string Prompt = "Spotify> "; | ||
public static readonly string SuccessHtml = @" | ||
<html style='font-family: sans-serif;'> | ||
<head><title>SpotNetCore - Spotify | Authentication Succeed</title></head> | ||
<body style='text-align: center;'> | ||
<header> | ||
<h1>SpotNetCore</h1> | ||
</header> | ||
<main style='border: 1px solid lightgrey; margin: auto; width: 600px; padding-bottom: 15px;'> | ||
<h2 style='color: limegreen;'>Authentication complete</h2> | ||
<div>You can return to the application. Feel free to close this browser tab.</div> | ||
</main> | ||
</body> | ||
</html>"; | ||
|
||
public static readonly string ErrorHtml = @" | ||
<html style='font-family: sans-serif;'> | ||
<head><title>SpotNetCore - Spotify | Authentication Failed</title></head> | ||
<body style='text-align: center;'> | ||
<header> | ||
<h1>SpotNetCore</h1> | ||
</header> | ||
<main style='border: 1px solid lightgrey; margin: auto; width: 600px; padding-bottom: 15px;'> | ||
<h2 style='color: salmon;'>Authentication failed</h2> | ||
<div><b>Error details:</b> error {0} error_description: {1}</div> | ||
<br> | ||
<div>You can return to the application. Feel free to close this browser tab.</div> | ||
</main> | ||
</body> | ||
</html>"; | ||
} | ||
} |
Oops, something went wrong.