Project: Scan CD Barcode & Play in Spotify – Part Two

Read up on Part One before continuing on – otherwise this post makes no sense.  Why are you reading it out of order?


Day Four – Things Are Working

You’ll remember at the end of Day Three I was getting frustrated with how things were working out, and that I might need to head to a different direction.  In fact, in the intervening days between pausing the project, moving to a new house, and continuing today (Tuesday), I even came across ANOTHER option that might even take all the hard work away from me:

Lifehacker: Stream a Vinyl Album By Snapping a Pic of Its Cover Art With This App

I think this project sounds awesome and is probably a better implementation of what I want to do, but at this point it’s merely a back-up option that I’m going to hold onto.

So I know for sure that using the “auto input” option (described in Day Three) definitely works – but to me that’s very clunky and goes against the entire point of what I’m trying to do with this project.  I did some extra digging and found a barcode for Maroon 5’s Red Pill Blues album (Best Buy is very handy with listing EAN barcode numbers, it turns out).

I went back to AutoSpotify and figured out how to get it to search and return results properly.  I fiddled around briefly with broadcasting intents, and they worked to some extent – but not the way I wanted.

In the end I realized there was a “play media” function with AutoSpotify that I wasn’t leveraging before.  I was able to play the album directly from the URL (obtained from the AutoSpotify Search).

Just to drive the point home, I want to say again – it worked.  I took the barcode from the album (Red Pill Blues), searched the EAN database for the name, plugged the name into a search of Spotify’s database, and then automatically played the album.

I haven’t tested it fully with the barcode scan – that’s next.  But just a quick summary again of the apps I needed to make this work:

  • Tasker
  • AutoTools (JSON Read)
  • AutoSpotify (Search & Play Media)
  • Also need an EAN Database API login (free version)

Full barcode test is next.


Day Five – Putting It All Together (Again)

Finally, it all came together!  I grabbed some CDs from my collection.  Only one of them worked – The Sheepdogs’ Learn & Burn.  That’s okay – I fully expect some of these scans not to return any information (or the correct information).

The ultimate point is that I was able to scan a barcode, look up the album name in Spotify, and play it automatically.  It took me a while to get there, but I’ve got it all set now.

I think the next step will be to add some checks – for example, if it can’t find product information, tell me so that I can decide to try to look it up via image search (the one I mentioned from Day Four).  That type of thing.  Make it a little smarter.

Anyway, if you want a copy of the task (assuming you have Android, and all of the required apps / plugins), let me know and I’ll make it available after I clean it up.

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!