Project Time: Scan CD Barcode & Play in Spotify

It’s been a long time since I’ve started a fun tech project.  I’m not too hands-on when it comes to the hardware, but I like dabbling in the software side of things.  Without further ado, here’s what I’m trying to accomplish, in a nutshell:

Using my phone (or a tablet, that works too), scan a CD barcode and play it in Spotify (or whatever music app I happen to be subscribed to at the time).

This post is being written as I walk through the project.  There are quite a few pieces involved in getting it to work, and I’m piecing it together one at a time.


Day One – Gathering Materials & Initial Tests

This is where I figure out what it is that I need to make this thing work.  As far as I can tell, this is what I’ll need:

The first test I came up with was to figure out how to trigger everything in the first place.  I found this handy Reddit post that used a different method to scan barcodes as a starting off point.  To save you a click though, I’m triggering the task by launching when the Barcode Scanner app is open AND the clipboard is set (that’s how the app works – it copies the barcode to the clipboard).

In the task itself, I want to look up the barcode information.  Apparently you can do this using EAN, which stands for International Article Number (it was originally European, hence the “E”).  Autoweb has a web service to look up product info from the EAN database, which is perfect! So in Tasker, I am sending the barcode (which is stored in the clipboard at this point) to the EAN database, which returns a bunch of different results from product name, description, category, etc.  Well, as long as all that information is in the database, that is.

Grand & Toy Highlighter
Grand & Toy Highlighter

I tested it with the closest object I could find with a barcode – a Grand & Toy highlighter (pictured).  Unfortunately that test didn’t give me any meaningful results, so I had to test something else.  I tried a bag of chips (it was free – technically expired, from the vending machine) and still, nothing came up.  I seem to be doing something wrong.  I think the rest of Day One will be spent trying to figure this out.

So I figured it out with a different method.  I couldn’t figure out how to use the Autoweb API action, so I decided to just eliminate that variable and use an Autotools JSON Read (you can view a tutorial here).  In conjunction with the JSON Editor Online (link), I figured out how to get Tasker to display the information I needed.  After some fiddling, success!  “Roundedge Yellow Highlighter” (incidentally the EAN entry for Grand & Toy has the company name entered as “Grand & Tory”).

Now that I’ve got this basic, most important part of the process figured out, I can now start scanning CDs to see what information comes up in the JSON file and look up via Spotify.

I’m having mixed results – my personal CD collection is packed away right now, so I’m using my parents’ collection to test.  I got a positive match for “Crazy for Gershwin”, but looking up the barcode for Gordon Lightfoot’s Gord’s Gold gave me the following product description:

Lorcos Cinnamon Orange Christmas Cat In A Boot Single Soap Bar 10.5 Oz. From France

So…this might not be the smoothest exercise, but it DOES work.  Sort of.  I count this as a success.


Day Two – Connecting with Spotify

Connecting to Spotify has been somewhat problematic.  While I’ve been able to read barcodes and get the album name, searching the Spotify database hasn’t been so easy.  I used the Tasker plugin AutoSpotify to run a search.  I think I’m just not clear on how the plugin works because no information would return to me.  None of my attempts to get the Spotify API in Autoweb to work either.

So that’s frustrating.  To top it off, randomly my “HTTP GET” action (the function that is reading the EAN database) is failing.

All said, things are not going as smoothly as I would like.


Day Three – Changing things up

I was getting frustrated on day two trying to get the Spotify automation to work.  So I decided to change things up and go back to methods I know have worked for me in the past.  Enter AutoInput; it’s another plugin that simulates and automates user input.

I created a test task with a pre-set search string.  It opens Spotify, clicks on the search icon, pastes the search string, and clicks on the top result.  For the two tests that I ran, I used “our lady peace clumsy” and “oasis what’s the story morning glory”.  In both cases the top result was the correct album.  So this part of the puzzle works fine.  The next step was to put the barcode read and the automated search function and put them together.

I’m not having very much luck.  I think the problem is that I’m sorely lacking in CDs to test with; I did one test at Wal-Mart, but came up with nothing.  I think if I had the CD in hand I might be able to see if it returned actual artist / album information as opposed to what I’ve been looking at (an amalgamation of the two on a greatest hits album – reportedly, greatest hits albums aren’t reliable for EAN scans).

Leaning more toward the much more manual intensive process of printing QR codes for each album. I’d rather not put that much work into it, however.


To Be Continued…

I’m going to put this project on hold for now.  The bones are there, I just don’t have the time or the materials present to continue testing.  There will definitely be a follow-up to this entry though!

One thought on “Project Time: Scan CD Barcode & Play in Spotify

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax