How to remove duplicates from your Google Music library using the gmusicapi and Cygwin on Windows
Update: If you’re using Windows 10 Anniversary Update and you have Bash installed, and/or want to use Python 3.5, I’ve updated the script for Python 3.5 and you can save yourself some work and skip Cygwin. Check this out.
I previously showed you my guide for removing duplicates from Google Music using the unofficial gmusicapi and OS X. OS X offers a full POSIX command line which makes it easy to work with Python (as a long-time Windows user, I wonder if this is actually OS X’s greatest single feature). Python does offer an installer/interpreter for Windows, but the Windows Command Prompt doesn’t play nicely with many Python scripts due to differences in Unicode handling, so we’re not going to use it. Instead, a few brilliant minds have blessed the Earth with Cygwin, which gives us POSIX functionality on Windows. If you’re running Windows and are ready to strip duplicates from your Google Music library, look no further.
To follow my guide, you’ll need:
- A PC running Windows (I have only tested on Windows 10). If you’re on a Mac, follow my tried and true OS X guide.
- A solid web connection. I recommend Google Fiber or FiOS. If you can’t already get it in your area, ensure you’re voting for candidates that promote competition in the broadband space.
- Some experience with a POSIX command line (and if you need it, I recommend completing this tutorial).
- A Google Music library.
- Cygwin and a few dependencies. We’ll install this in step 1.
- The unofficial gmusicapi. We’ll install this in step 2.
- If you are using two-factor authentication on your Google account, you will also need an application-specific password to use exclusively with the gmusicapi. If you’re not using two-factor authentication, you probably should be.
Step 1: Install Cygwin and the gmusicapi dependencies
We need to install Cygwin and several additional packages selectable during the installer. Grab the Cygwin installer and start the wizard. When prompted to choose packages, add these:
Devel > gcc-core, gcc-g++, openssl-devel
Python > python (Python language interpreter), python-setuptools
Web > wget
Libs > libffi-devel
and follow the on-screen instructions to finish the installation.
Step 2: Start the Cygwin terminal
Hit Start and type Cygwin and choose Cygwin Terminal. The terminal looks like the Windows Command Prompt except that it is actually useful.
Step 3: Install the gmusicapi
pip makes installing Python packages easy. In Cygwin,
pip install gmusicapi
If you get any errors, you’ve missed something. Review the prerequisites and especially ensure you’ve installed all dependencies using Cygwin.
Step 4: Download deletegmusicdupes.py
Save it somewhere convenient. This is the script that’s going to do the heavy lifting identifying your duplicates, and offer to delete them. You may review the source code here.
Step 5: Run deletegmusicdupes.py
Cygwin uses a different root directory than you may expect. To access your Windows drives, type
To list your drives. Then navigate to the folder where you saved deletegmusicdupes.py. Then run:
When you’re prompted for Username, use your Google email address. When you’re prompted for your password, provide your application-specific password. Once logged in, the script will show you a list of duplicates in your account — there may be hundreds. It will ask if you want to delete duplicates. Well, yeah, at this point, you probably do.
The API can only return so many results at a time, so if you have a large enough library, you’ll need to run the script multiple times. Run the script again (you’ll be prompted to log in each time) until the script reports “no duplicates found” — at which point you are done!
Keep on keeping on,