Search

Categories

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Send mail to the author(s) E-mail

# Monday, 20 April 2015
( Spotify )

https://github.com/DanielLarsenNZ/Radiostr-SpotifyWebApi

Initial thoughts on his code

  • Tidy, and designed with lots of traditional comments
  • Async all the way (just use .Wait to make it sync)
  • Testable
    • HttpClient mocking out
  • ClientCredentialsAuthorizationApi
  • Caching
  • Defensive code checking for NullOrEmpty

Putting on a test Console App

image

Annoying that breakpoint is caught at top level.

image
Okay so I just need to break in VS!

| | # 
# Friday, 17 April 2015
( LSCC | Spotify )

Thanks to everyone who came last night - really appreciated the questions and laughter!!

http://www.meetup.com/london-software-craftsmanship/events/221749420/
https://skillsmatter.com/meetups/7134-software-craftsmanship-with-music-and-financial-trading

The soundtrack before the talk was:

image

An Elvis impersonator, covering dead people.  I really like this album
http://www.davestopmusic.com/Artists/Details/1W04ZWzAoPZ6eY754HgXQP

The Talk

www.davestopmusic.com  (main site – Amazon EC2)

dmusic.azurewebsites.net (test site - Azure)

https://ci.appveyor.com/project/djhmateer/davesmusic – Build / Test / Deploy to Azure

 

Code and presentation: https://github.com/djhmateer/davesmusic (I’ll put the HQ videos up there this weekend)

Music Discussed

Where to Next?

Got some great questions on testing which is making me think of where next..

| | # 
# Tuesday, 14 April 2015
( Spotify )

image

image
Doing anything that needs authorisation fails.

| | # 
# Tuesday, 24 March 2015
( Async | Spotify )

Exploring how to call multiple webservices in parallel as many of the calls for Spotify can be made at the same time.

WebClient – since 1.1.  common methods for sending data to and receiving data from a resource identified by a URI. Simpler.
HttpWebRequest – since 1.1.  HTTP Specific implementation of WebRequest.  Allows more control
HttpClient – .NET45 or in Nuget.  Based on HttpWebRequest. Task oriented pattern for handling async requests..The benefits that HttpClient brings is with the standard classes like HttpResponseMessage, HttpRequestMessage, HttpContent and all the strongly typed headers

https://www.simple-talk.com/dotnet/.net-framework/the-.net-4.5-asyncawait-feature-in-promise-and-practice/

https://msdn.microsoft.com/en-GB/library/hh696703.aspx

image

static void Main() { //explore async/await for when I do many API calls // what if there is an error? //Sync(); Async(); Console.WriteLine("done"); } static void Sync() { var stopWatch = new Stopwatch(); stopWatch.Start(); var url = "https://api.spotify.com/v1/albums/?ids=3KuXEGcqLcnEYWnn3OEGy0,0eFHYz8NmK75zSplL5qlfM,0lw68yx3MhKflWFqCsGkIs,0HcHPBu9aaF1MxOiZmUQTl,5eJTvSeghTKoqN3Ly4TqEf,1Dh27pjT3IEdiRG9Se5uQn,6AyUVv7MnxxTuijp4WmrhO"; for (int i = 0; i < 5; i++) { Console.WriteLine("Starting " + i); HttpWebRequest request = HttpWebRequest.CreateHttp(url); string text; using (var response = request.GetResponse()) { using (var sr = new StreamReader(response.GetResponseStream())) { text = sr.ReadToEnd(); } } Console.WriteLine("result of " + i + " " + text.Substring(0,400)); } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; string elapsedTime = String.Format("{0:0}", ts.TotalMilliseconds); Console.WriteLine("Total: " + elapsedTime); } static void Async() { var stopWatch = new Stopwatch(); stopWatch.Start(); ServicePointManager.DefaultConnectionLimit = 50; const int n = 5; Task<string>[] tasks = new Task<string>[n]; for (int i = 0; i < n; i++) { tasks[i] = CallAPI(i); } Task.WaitAll(tasks); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; string elapsedTime = String.Format("{0:0}", ts.TotalMilliseconds); Console.WriteLine("Total: " + elapsedTime); } // Switch to HttpClient - .NET45.. http://stackoverflow.com/a/25612028/26086 static async Task<string> CallAPI(int i) { Console.WriteLine("CallAPI enter " + i); var url = "https://api.spotify.com/v1/albums/?ids=3KuXEGcqLcnEYWnn3OEGy0,0eFHYz8NmK75zSplL5qlfM,0lw68yx3MhKflWFqCsGkIs,0HcHPBu9aaF1MxOiZmUQTl,5eJTvSeghTKoqN3Ly4TqEf,1Dh27pjT3IEdiRG9Se5uQn,6AyUVv7MnxxTuijp4WmrhO"; HttpWebRequest request = HttpWebRequest.CreateHttp(url); string text; using (var response = await request.GetResponseAsync()) { using (var sr = new StreamReader(response.GetResponseStream())) { text = sr.ReadToEnd(); } } Console.WriteLine("CallAPI exit " + i + text.Substring(0,400)); return text; }

http://stackoverflow.com/a/5827440/26086 – WebRequest will only make 2 calls to the same host – HTTP niceness!

Results

Connection limit

Sync – 9.7s
1 – 9.7s
2 – 5.3s
3 – 3.7s
4 – 3.2s
5 -  3.1s
6 – 3.0s
10 – 2.4s
20 – 2.2s
50 – 2.2s

| | # 
# Wednesday, 04 March 2015
( Azure | Spotify )

Whilst at work (in Brighton) on a 50meg leased line

image
Huge performance difference in API query time (I think) between Azure in Western Europe and my local line.  I believe Spotify’s servers are in London so this would make sense to be slightly faster, however such a big difference doesn’t.

Azure Different Plans

image
Free website – no (as 185MB data limit)
Shared website – yes.. this is what this is on..costing approx 5UKP per month + 5UKP database?
B1 Small Instance – moved to that. 1 Core.  1.75GB RAM.  20UKP per month + 5UKP database?

Website in West Europe
B Basic - DB is West Europe (max size 2GB)

Spun up a
S1 Small Instance in Northern Europe
B Basic DB in Northern Europe

image
No massive difference coming from Northern Europe

From ADSL

image

Spotify Web API Speed Test Page

A page testing the speed of API calls to Spotify

229 : https://api.spotify.com/v1/artists/3hv9jJF3adDNsBSIQDqcjp

461 : https://api.spotify.com/v1/artists/3hv9jJF3adDNsBSIQDqcjp/top-tracks?country=GB

615 : https://api.spotify.com/v1/albums/?ids=3vLaOYCNCzngDf8QdBg2V1,3vLaOYCNCzngDf8QdBg2V1,3vLaOYCNCzngDf8QdBg2V1,3vLaOYCNCzngDf8QdBg2V1,3vLaOYCNCzngDf8QdBg2V1

987 : https://api.spotify.com/v1/albums/?ids=3vLaOYCNCzngDf8QdBg2V1,1cvcW2kVGrN9tdyoaVjmf0,0m8wvW3WNm9D7J0KUlbf3h,1nojrwBYMmq5jY1gJYtywa,0lrBKnE4qQnr8VM56J3gow,4ttFaYVApnyblaGHNwGAf7,62Qu5QoNx3De0p5qQT0u7o,69UMMsDqpBwy7Dr2oZn2Ra,311yDc6Ow5WF8puYAAte1B,05IBZIkN7fdbiVCgGCJCWX,6Z9OaWRC8Bsb64OyhiZ49L,6GMHua20KrXo7MlfwbTWk1,40pk5HrcQ3TDP0KBP3KhfQ,6KZwPiN4oDTcvgtbHGr1A1,2zlXL0UVwQrH9FRFSvNOBg,5hNZOA0YJBq0bGYnWGSo5x,0QluVU5ReXs7oI1ZyS101F,6pJf6YRFeyj615gGq6yDnZ,777UeiexLMf1mFR42nSoR2,2qkxQSusZ6JXAzpnptVUo1

987 : https://api.spotify.com/v1/artists/3hv9jJF3adDNsBSIQDqcjp/albums?country=GB&limit=50

391 : https://api.spotify.com/v1/artists/3hv9jJF3adDNsBSIQDqcjp/related-artists

194 : http://developer.echonest.com/api/v4/artist/biographies?api_key=SECRET&id=spotify:artist:3hv9jJF3adDNsBSIQDqcjp

image
Home ADSL

image
Work vs Azure

Test to see if it’s actually Spotify limiting me
pass the token?

image
Seems to make no difference passing a token

image
In fact, mostly faster without the token

I guess the next thing to do is try it somewhere else.  Amazon EC2?

EC2

image
EC2 is fast!

Azure VM - Slow

http://davemateer.cloudapp.net/

A1 Azure VM of it being painfully slow.  1.75GB RAM, 1 Core

http://weblog.west-wind.com/posts/2015/Feb/01/Azure-VM-Blues-Fighting-a-losing-Performance-Battle – seems I’m not along.

He went to a high perf cheaper SSD alternative https://www.vultr.com/pricing/

SQL stuff http://www.brentozar.com/archive/2014/09/azure-really-60-faster/

D1 for SSD – creating http://davemateer3.cloudapp.net.. 3.5GB RAM, 50GB SSD, 1core.. £78 per month?

EC2 VM

image

Much faster (even on the micro instance).

Decided to register a domain name – using fasthosts.co.uk.. www.davestopmusic.com

| | # 
# Tuesday, 03 March 2015
( Spotify )

image
2.2 seconds on API calls is feeling slow.

https://developer.spotify.com/developer-terms-of-use/

“The TOS section you're asking about is to prevent people making automated tools that scrape the Spotify catalogue without user interaction. If you're writing a "normal" application and caching data from the Spotify APIs as a result of a user actually doing something like searching, browsing, etc etc you have no problems.” http://stackoverflow.com/a/18273847/26086

| | # 
# Saturday, 28 February 2015
( Spotify )

Annoying that some of the album date times are not there:

image_thumb[9]

Some dates are in different formats.. just deal with it in code/use release_date_precision

image_thumb[11]

image_thumb[13]

| | # 
( Spotify )

image_thumb[7]

Very annoying that when I select “She Talk to Angels” above

  • Its the wrong album – I want the original, not the compilation..
    • Shake Your Money Maker (1990)
  • It will get the wrong date for the track (as its a compilation)

First thing to do is to get dates into the list of all Artists albums:
https://developer.spotify.com/web-api/get-several-albums/

Find just Studio Albums

https://developer.spotify.com/web-api/get-artists-albums/

Filter on album_type: album  (so not single or compilation)
Filter out anything with no available markets?
Look at all tracks in all albums, and find earliest album it appears on?
Exclude: "[Collectors Edition]" and "(Collector's Edition)" etc..  Live?.. filter out Remastered?

image
album_type = single.. Muse

| | # 
( Spotify )

I gave an internal presentation on this side project.  It was great fun.  Some notes:

https://github.com/djhmateer/githubscratch

source: https://github.com/djhmateer/davesmusic live on: http://dmusic.azurewebsites.net/

image
As a programmer, Bob comes to Dmusic, browses top tracks, and adds his favourite tracks which then get sync'd to his Spotify.

image
As a programmer, Alice comes back to Dmusic, logs in via Spotify, and adds tracks to her playlist via searching

This story isn’t quite working, but as an Admin I can add “Spotify Top Tracks” to the “Top Tracks” page

Some musical highlights:

And from me, the best Abba cover versions of all time!
http://dmusic.azurewebsites.net/Artists/Details/5kcL6tVVEBIgiHkXW9JVWo

| | # 
# Friday, 20 February 2015
( Spotify )

image

image

Firstly get playlist uploading for different users!

Each of these screens has button that says “Add” or “Remove”.. then goes to “My Playlist” which uploads it to Spotify

AJAX

To get a button that doesn’t post, I need some form of Ajax. 

http://bobcravens.com/2009/11/ajax-calls-to-asp-net-mvc-action-methods-using-jquery/

<script src="~/Scripts/jquery-1.10.2.min.js"></script> <script type="text/javascript"> function addTrack(trackId) { $.get('@Url.Action("AddTrack","Home")', { trackId: trackId }, function (data) { $("#message").html(data); }); } </script> <button onclick="addTrack(12345)">Add</button> <div id="message"></div>

And controller:
public string AddTrack(string trackId) { return trackId + " added to my playlist"; }

image
| | # 
# Wednesday, 11 February 2015
( Spotify )

image

Next goal is to have tick boxes and a button that says add albums to my DavesMusic playlist.

http://stackoverflow.com/questions/23639808/mvc-view-viewmodel-httppost-return-value-is-always-null
Modelbinder is not returning my ViewModel back to the HttpPost method on the controller.  Possibly it is because I have class names the same as properties.

http://stackoverflow.com/questions/7986991/mvc3-how-to-bind-multiple-checkboxes-to-1-property-in-viewmodel
No not that – interesting issue.

http://sampathloku.blogspot.co.uk/2012/10/how-to-use-viewmodel-with-aspnet-mvc.html – This is a good post on getting a ViewModel working in MVC.  The issue was I wasn’t displaying and posting back the ViewModel data.

I can use Html.HiddenFor helper to pass back data

http://stackoverflow.com/questions/12078808/how-to-pass-an-entire-viewmodel-back-to-the-controller – someone with the same issue.

http://stackoverflow.com/questions/20063695/viewmodel-not-being-passed-back-to-controller-in-post-method – a detailed explanation including passing back collections.

passback to the ID and checked or not – This worked

| | # 
# Monday, 02 February 2015
# Friday, 30 January 2015
( Spotify )

http://dmusic.azurewebsites.net – hosting (free option)
https://github.com/djhmateer/davesmusic – source control
https://uptimerobot.com/ – keep site alive and monitor
error handling?
logging?
google analytics? site visitors

/Home/Search

/Home/Search?artist=muse

/Artists/Details/12345

/Albums/Details/12345

 

/Me/Index – gets current logged in user profile (OAuth)

If not currently authorised redirect to
http://accounts.spotify.com/authorize
comes back to
/Me/SpotifyCallback

 

Am designing my routing to follow Spotify’s API
http://stackoverflow.com/questions/12460060/asp-net-mvc-controller-naming-pluralization – lets go plural

/Browse/NewReleases ??

Errors

image
Was in the SpotifyCallback method

| | # 
# Monday, 26 January 2015
( Spotify )

http://www.programgood.net/2014/12/31/SpotifyWebAPI.aspx

/Home/Spotify

/Home/SpotifyAuthenticate

/Home/SpotifyCallback

https://github.com/JohnnyCrazy/SpotifyAPI-NET – Includes his own http server

https://github.com/slyngelstat/Slyngelstat.Spotify.Api – no authorization

https://spotifywebapi.codeplex.com/SourceControl/latest – useful! (spotify webapi)

http://stackoverflow.com/questions/15176538/net-httpclient-how-to-post-string-value – setting up post and async

Can get an access token now!!

image
Using the access token to get data about the currently logged in user

url = "https://api.spotify.com/v1/me"; client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", access_token); httpResponse = client.GetAsync(url); var result2 = httpResponse.Result.Content.ReadAsStringAsync().Result; //dynamic obj2 = JsonConvert.DeserializeObject(result2); var meReponse = JsonConvert.DeserializeObject<MeResponse>(result2);

Useful bit of dynamic code as it allowed me to see the json and convert it using json2csharp.com into a MeResponse class.

HttpClient and HttpWebRequest

HttpClient uses HttpWebRequest as it’s transport library

“The benefits that HttpClient brings is with the standard classes like HttpResponseMessage, HttpRequestMessage, HttpContent and all the strongly typed headers”
http://stackoverflow.com/questions/16194054/is-async-httpclient-from-net-4-5-a-bad-choice-for-intensive-load-applications

http://tmenier.github.io/Flurl/ – possible useful.. a library for helping with Http calls and dealing with API’s

| | # 
# Friday, 23 January 2015
( Spotify )

http://developer.echonest.com/sandbox/spotify.html

“The Echo Nest has linked our IDs to Spotify”

Biographies

http://developer.echonest.com/api/v4/artist/biographies?api_key=FILDTEOIK2HBORODV&id=spotify:artist:4Z8W4fKeB5YxbusRsdQVPb

image
The last.fm and Wikipedia entries seem to be the best

| | # 
# Thursday, 22 January 2015
( Spotify )

image

Related Artists – I’ve limited it to the top 7 (20 returned by default)

| | # 
# Wednesday, 21 January 2015
( Spotify )

image

image

So now I should make an /Album/Details/ link

image

| | # 
# Monday, 19 January 2015
( Spotify )

image

http://json2csharp.com/ – Calling the Spotify API, putting result into json2csharp, then looking at POCO in VS.

string url = ""; json = spotifyHelper.CallSpotifyAPIArtistTopTracks(stopWatchResult, id, ref url); var artistTopTracks = JsonConvert.DeserializeObject<ArtistTopTracks>(json); apiDebug = new APIDebug { APITime = String.Format("{0:0}", stopWatchResult.ElapsedTime.TotalMilliseconds), APIURL = url };

Passing a debug string by reference, so can easily get it returned

public string CallSpotifyAPIArtistTopTracks(StopWatchResult stopWatchResult, string artistCode, ref string url) { url = String.Format("https://api.spotify.com/v1/artists/{0}/top-tracks?country=GB", artistCode); var json = CallAPI(stopWatchResult, url); return json; }

However this is a smell: 
http://stackoverflow.com/questions/635915/when-to-use-ref-and-when-it-is-not-necessary-in-c-sharp
http://stackoverflow.com/questions/3539252/when-is-using-the-c-sharp-ref-keyword-ever-a-good-idea

“Basically its a way of getting another return value and should usually be avoided precisely because it means the method’s probably trying to do too much” Skeet.

Refactored

var apiResult = spotifyHelper.CallSpotifyAPIArtistTopTracks(stopWatchResult, id); var artistTopTracks = JsonConvert.DeserializeObject<ArtistTopTracks>(apiResult.Json); apiDebug = new APIDebug { APITime = String.Format("{0:0}", stopWatchResult.ElapsedTime.TotalMilliseconds), APIURL = apiResult.Url };

and

public APIResult CallSpotifyAPIArtistTopTracks(StopWatchResult stopWatchResult, string artistCode) { var url = String.Format("https://api.spotify.com/v1/artists/{0}/top-tracks?country=GB", artistCode); var json = CallAPI(stopWatchResult, url); return new APIResult { Json = json, Url = url }; }
public class APIResult { public string Json { get; set; } public string Url { get; set; } }

Similar amounts of code, and is clearer.

image
image
Got previews working with preview_url!

image

| | # 
# Thursday, 15 January 2015
( Spotify )

https://api.spotify.com/v1/artists/12Chz98pHFMPJEknJQMWvI – Muse

image
Not much more detail!

image
The details page of an Artist.. great images are the best bit!

Followers too are interesting vs popularity

/Artist/Search/?artist=muse&offset=0
/Artist/Details/12Chz98pHFMPJEknJQMWvI
/Artist/Details/Random

Random

https://api.spotify.com/v1/search?q=year:2001&type=artist&market=US
https://api.spotify.com/v1/search?q=year%3A2001&type=artist&market=US  - Html Encoded
:2001 brings back 66,896 results.. from 0000:2001
:2014 brings back 672,262 results
:2014 no US 698,288

https://api.spotify.com/v1/search?q=year:0000-9999&type=artist – 2,279,823
https://api.spotify.com/v1/search?q=year:0000-9999&type=artist&market=GB – 2,196,115

then get the total and pick a random offset between 1 and that total
&limit=1&offset=12345

https://api.spotify.com/v1/search?q=year%3A2001&type=artist&market=US&limit=1&offset=12345 – works
https://api.spotify.com/v1/search?query=year%3A0000-9999&offset=871249&limit=1&type=artist&market=GB doesn’t

That offset isn’t bringing back any data, but 12345 does.. found up to 100,000 brings back data

image
Implemented random from 0 to 100,000 offset.  Interesting!  API calls are slower (as am doing 3)..cut it to 2

next – implement back button on random…/Artist/Details/12345&showNextRandomLink=true

| | # 
# Wednesday, 14 January 2015
( Spotify )

image
Want to click on the image to get

  • More info on Muse
  • Full details of their albums

Go with /Artist/Details/123456

image

http://json2csharp.com/

image

External_url – used in open in web spotify eg https://open.spotify.com/artist/5M52tdBnJaKSvOpJGz8mfZ

Open directly – chrome knows about local spotify app:  spotify:artist:5M52tdBnJaKSvOpJGz8mfZ

| | # 
# Thursday, 08 January 2015
# Tuesday, 06 January 2015
( c# | JSON | Spotify )

Goal: Get API calls working to Spotify using a console app

http://www.royjacobs.org/blog/2012/11/13/importing-m3u-playlists-into-spotify/ – c# importer (no auth)

image
Using a deprecated call

image
Interesting I’m getting 224 results back!

image
Can type in the Href and test have got the correct song back.

Searching

http://ws.spotify.com/search/1/track?q=Metallica+One
This old Metadata API, which is now deprecated (but still working).

image
Old API returning XML.

https://api.spotify.com/v1/search?q=metallica&type=artist
The Web API

image
JSON Formatter extension for Chrome

https://developer.spotify.com/web-api/console/
Interactive Console for exploring the API

  • Album
  • Artist
  • Track
  • Playlist

Exploring the json and viewing the image URL’s that are returned

image

An image of the band
https://i.scdn.co/image/15d9ccb37a96d49f69f44f999fb1e9e46f9b3ccd

Am using Newtonsoft’s JsonConvert.DeserializeObject<T> to get into a POCO:

image
Used the API to get a simple search going on the web.

Exploring the json returned results, finding that some artists return 3,4 or 0 images.  So put some simple view logic in to force display of 200 width.  And put in a sample default band (muse) on page load of http://www.davesjokes.co.uk/Home/SpotifyArtistSearch

image

Offset and Limit

https://developer.spotify.com/web-api/search-item/
https://api.spotify.com/v1/search?query=muse&offset=20&limit=20&type=artist

Limit default is 20, max is 50.

Timing

var stopWatch = new Stopwatch(); stopWatch.Start(); string json = CallSpotifyAPI(artistName); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; string elapsedTime = String.Format("{0:0}",ts.TotalMilliseconds); ViewBag.APITime = elapsedTime;
TotalMilliseconds is handy.  Format makes sure no decimal points in the ms.

image
Timing code.  Next and previous buttons.  All GET requests now – form submits via querystring.  Title is different if no search.

| | # 
# Monday, 05 January 2015
( Spotify )

http://static.echonest.com/insights/christmas/BlueChristmas.html

image

Very simple generated page (source is very simple)

| | # 
# Thursday, 01 January 2015
( Spotify )

http://musicmachinery.com/2014/12/19/the-playlist-miner/

Includes playlist searching

  • rock (good!)
  • party
  • 80
  • sleeping baby
  • guitar
  • workout
  • playlist
  • roadtrip
  • easy listening
  • running

fun
love the way it can create playlists easily

image
Many calls to the Spotify API

 

https://developer.spotify.com/showcase/item/every-noise/

Uses Echo Nest API to extract genre information

Spotify Web API to play tracks

image

| | # 
# Wednesday, 31 December 2014
( Spotify )

… lets your applications fetch data from the Spotify music catalog and manage user’s playlists…

https://developer.spotify.com/web-api/ – 3 different OAuth2.0 flows:

  • Authorization Code flow
  • Client Credentials flow
  • Implicit Grant flow

https://api.spotify.com – several endpoints here

Many endpoints are open, however to access private data eg user profiles and playlists, and application must get the user’s permission:

https://accounts.spotify.com – authorisation

  • GET – retrieving resources
  • POST – creating resources
  • PUT – Changing/replacing resources
  • DELETE – Delete resources

Integration with Echo Nest - http://static.echonest.com/enspex/ – lots of demos here

Auth Key

image

image
Name will be shown in the popup that asks the user for authorisation.

Add a redirect URI

http://localhost:8888/callback
myapp-clientidandkey-screen

ClientID – Unique identifier for my app.  not secret

Client Secret – the key that I will need to pass in secure calls to the Spotify Accounts and Web API services.

Installed node.js from http://nodejs.org/download/

/* Load the HTTP library */ var http = require("http"); /* Create an HTTP server to handle responses */ http.createServer(function(request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end(); }).listen(8888);

Saved this as server.js in c:\dev\test\spotify and ran: node server.js then

image
Connecting to the localhost webserver ran by node.

Cloned the example app repository from  https://github.com/spotify/web-api-auth-examples

npm install –g express
npm install –g request
npm install –g querystring

couldn’t get npm to work without the –g

Authorization Code Example

app.js – put in ClientID, Client Secret and Redirect URI.

npm install in the authorizationcode directory

node app.js

image

image

image

Search for an Artist Demo

http://jsfiddle.net/JMPerez/UT7bQ/187/

image
Plays 30s too.

Dot Net Wrapper for Web API

https://github.com/slyngelstat/Slyngelstat.Spotify.Api

uses an open service, which returns json:

http://ws.spotify.com/search/1/album.json?q=Guitar+Gangsters

| | # 
# Monday, 29 December 2014
( Spotify )

As part of a potential project, I’m spiking out what can be done with Spotify.

Web API

"Our Web API lets your applications fetch data from the Spotify music catalog and manage user’s playlists and saved music."

Uses OAuth2

Follow Button

Follow friends, artists and organisations

clip_image001

clip_image002

clip_image001[4]

clip_image002[4]

My Music, Artists, can see him

Then get a notification when he releases something on Spotify.. By email too.

Or go to the artists page in Spotify and just hit follow.

Open

https://open.spotify.com/user/mashablehq - Good Beatles covers here.

A webplayer, which spins up the Spotify client.

Spotify Play Button – Track (Song)

https://developer.spotify.com/technologies/widgets/spotify-play-button/

When a logged-in Spotify user clicks the button, the music will start playing in a Spotify client. (Which client depends on both the platform, and on the user account settings:

https://play.spotify.com/settings

Play – Track

http link: http://open.spotify.com/track/0mDHS1Q7HGtpgjYAyG2Svn

spotify uri: spotify:track:0mDHS1Q7HGtpgjYAyG2Svn

image

embed code: iframe src="https://embed.spotify.com/?uri=spotify:track:0mDHS1Q7HGtpgjYAyG2Svn" width="300" height="80" frameborder="0" allowtransparency="true">

Play – Album

image

Play – Playlist

image

iframe src="https://embed.spotify.com/?uri=spotify:user:hoxsd:playlist:0Z7jXtAId643ujM1UPshct&theme=white" width="300" height="380" frameborder="0" allowtransparency="true"

Only the first 200 tracks are displayed in a playlist.

Takes 10 minutes for updates to appear in this playlist

Multiple Tracks Player

image
iframe src="https://embed.spotify.com/?uri=spotify:trackset:PREFEREDTITLE:5Z7ygHQo02SUrFmcgpwsKW,
1x6ACsKV4UdWS2FMuPFUiT,
4bi73jCM02fMpkI11Lqmfe&theme=white"

Looks like a playlist, but just hardcoded tracks

| | # 
# Sunday, 21 December 2014
( Spotify )

Ctl + right – next song
Ctrl + left – previous

Enter – play
Space – pause

Ctrl + L – search box

search on:

year:1991
title:
artist
album
genre

| | #