Skip to content

Commit

Permalink
Implemented Several Features & Bug Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ProIcons committed Feb 2, 2021
1 parent 61a7d88 commit cd75f95
Show file tree
Hide file tree
Showing 31 changed files with 1,148 additions and 502 deletions.
28 changes: 28 additions & 0 deletions SpotNetCore/SpotNetCore/Endpoints/AlbumEndpoint.cs
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);
}
}
}
27 changes: 27 additions & 0 deletions SpotNetCore/SpotNetCore/Endpoints/ArtistEndpoint.cs
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");
}
}
}
63 changes: 63 additions & 0 deletions SpotNetCore/SpotNetCore/Endpoints/PlayerEndpoint.cs
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");
}
}
}
22 changes: 22 additions & 0 deletions SpotNetCore/SpotNetCore/Endpoints/PlaylistEndpoint.cs
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");
}
}
}
46 changes: 46 additions & 0 deletions SpotNetCore/SpotNetCore/Endpoints/SearchEndpoint.cs
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;
}
}
}
37 changes: 37 additions & 0 deletions SpotNetCore/SpotNetCore/Implementation/AppConstants.cs
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>";
}
}
Loading

0 comments on commit cd75f95

Please sign in to comment.