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!

My Current Phone Set up at Work

A word of warning: this post is very Android-heavy, and not likely very relevant if you’re using basically any other smart phone.  Turn away now if you’re in the wrong ecosystem!  (Or, keep reading if you’re interested in some of the cool things you can set up with Android to stay productive.)

I’m always trying to find a way to stay productive while still keeping on top of the personal demands on my phone.  My phone is primarily a personal device, and strictly speaking, is not necessary for my job.  However, I use it constantly to keep in touch with my wife through messaging (we use Allo; I also use text messages for just about everyone else).  Other things that come through include email, Twitter, Facebook, etc.  I keep my phone on silent, but I don’t want to miss anything that might be an important notification.  So, I came up with a pretty good solution.  At least it’s good for me.

The other purpose for this set up is to help stretch my battery life a little bit.  The less that I activate my screen, the longer the battery lasts.

The Basic Setup

Phone: Samsung Galaxy S7 Edge
Android version: 7.0 (Nougat)
Root? Nope!
Other apps in use:

You can probably accomplish this set up with any Android device – it doesn’t have to be a Samsung product, and I think you’re probably fine running Android 4.4+ (KitKat and above), but I can only “guarantee” functionality based on what I’ve got going on here.  To replicate exactly what I’ve done, you’ll definitely need Tasker.  As Tasker is a great program for automation in general, I think it’s a great app to buy anyway.

Right off the bat, I would recommend reading my article about using the FitBit Charge 2 as a Smart Watch.  At the end of the day, the functionality here can be duplicated with any smart watch or any device that accepts notifications.  Form isn’t as important here as function.  The end result is that I have certain notifications sending to my phone – specifically, text messages, Allo messages, FaceBook Messenger messages, and phone calls.  There might be a few other things I’m forgetting but those are the important ones.

Most of the time I will use my device to respond to the instant messages; however there are web-based solutions for everything here.  Allo has a web interface (it mirrors what’s on your phone and has some limitations); you can go to Facebook in a browser to access messenger; and using Join you can send & receive messages through your browser (more on Join in a bit).  Basically if I need to I can leave my device off for everything except phone calls.  Oh – but I could forward my calls to my work number if I wanted to do that.  That’s a basic service provider option that most people probably have too.

Join

Join is a fantastic app.  If you’ve ever heard of Pushbullet, Join is in a similar category – except that it’s free.  The short version of what you can do with it is send browser tabs to / from connected devices, send notifications between devices, send files between devices, copy/paste text between devices, and so on.  You can read more about it here: https://joaoapps.com/join/ 

I use it primarily now to send notifications to my work laptop while I’m at work.  I haven’t figured out entirely how I want to automate it when I work at home, but for when I’m in the office, I have Tasker activate sending notifications to my work laptop as soon as I connect to wifi.  Join is a stand-alone app developed with Tasker plugins in mind, so it works really easily with Tasker as a plugin.  If you want to learn more, leave a comment…I don’t want to get too technical.

I picked a few apps within the Join app that I want notifications from, including Inbox (my gmail app) and Twitter.  These notifications pop up in the bottom corner of my computer whether or not I have a browser window open.  Join is available as both a Chrome plugin and a Windows 10 app; the plugin is free, but you have to pay for the app.  I just use the plugin.  When you click on the notification, you have a few options – you can dismiss it from the device (and if there are any buttons on the notification on your phone, they’ll appear on desktop too) or open it in a new browser window.  The great thing is that if it’s an email notification, it’ll bring you to your inbox; similarly if it’s Twitter or Facebook it’ll bring you to those sites too.

I could go on and on – I highly recommend watching the videos on the Join website to see all the things you can do with it.  But already we have several ways of handling phone notifications without having to turn the screen on and waste precious battery life.

The primary purpose of this isn’t really to avoid using my phone, it’s mostly because as I said I keep my phone on silent.  I may not always be staring at my screen and see I have a new notification.  So, this is a really helpful way to make sure I don’t miss anything.

Tasker

I alluded to using Tasker to automate when I send notifications through Join.  I also turn my “Always On Display” off when I’m connected to work wifi.  So now my screen is entirely disabled while I’m at work.  I should point out that I use several plugins with Tasker, which I pay for through a monthly subscription.  Check out the AutoApps suite (which you can try out for free) – there are lots of cool things to do here.

To accomplish controlling the Always On Display, I use AutoTools – Secure Settings.  To use this you need to enable ADB access.  It’s not too complicated to set this up, but there are some steps involved – you should read it in a better, step-by-step format.

That’s pretty much it.  I find this setup extremely useful so far, and battery life is great.  I’ve been using “AccuBattery” lately and it recommends charging phones only to 80% (based on scientific studies) to extend the battery’s overall life.  Any battery saving tips of your own?