I'm terrible with names, period. I just can't remember the nickname of a person I've just met, the title of a song I've heard or any name in general. This becomes really frustrating when you want to listen to music. Most often I recall who was playing the song, so I found myself in the need of browsing really fast through the discography of a specific artist with the possibility to listen to a short preview of every song (it would be too easy to track the song only by its name). And because I'm spending quite a lot of time in the terminal, wouldn't it be cool to do it from the command line?

Deezer API

There are quite a few music streaming services out there, but I'm using Deezer for a long time now and I can say it's amazing. More than this, they published a public API that can be used by anyone who wants to grab data about songs, artists, albums, etc. You need only to login (you can do it with your Google account) on developers.deezer.com and start exploring. The API is really easy to consume, and there are many examples on the website so it is fairly easy to get going.

Oracle Functions

Based on Fn Project, Oracle Functions is a serverless service that you can use to deploy your code without worrying about the infrastructure and dependencies underneath. A very simple explanation would sound like this: once you wrote your code, Oracle Functions will build a container around it and handle the deployment.

Go ahead and create your first application. You can think at this as a collection of functions, working together (or not) to the server the same purpose. Whenever you will want to work with a specific function, you will call it by referencing the application which stores it.

The first place to look is the Getting Started tab. You will find there the steps required to deploy the hello-world app, no matter what programming language you prefer. I'm not going to cover these steps because they are very well explained and you can always check the Oracle Functions Quickstart, which takes you from zero to almost hero.

My python app is not very different from than hello-world. It's as simple as it can be. It's just calling the Deezer API using requests by passing the name of the artist. We grab from the response only the title and the link for the preview. We put everything in a JSON format which you get back in your browser.

fn init --runtime python <APP-NAME>

Grab the python code from Github, put it in your func.py file and you're ready to go. If everything is configured properly, you can deploy your code using the following command.

fn deploy --app <APP-NAME>

Go back to the console and check if everything looks good. You will have your function published, and once you start invoking it you can monitor the number of requests directly from the browser.

The result?

There are multiple ways of invoking Oracle Functions, I'm currently using the fn directly but I plan to use API Gateway once it will become generally available. We need to pass the artist name and if everything looks good, you will get a JSON formatted response. I'm using jq to parse it and make it more appealing.

echo -n '{"artist":"The Teskey Brothers"}' | fn invoke faas-Deezer deezer-get | jq '.[]'

Once you found your song by title, you can use ffplay to listen the preview .. just to be sure!

Until next time,