Skip to content

Instantly share code, notes, and snippets.

@ianhomer
Last active August 29, 2015 14:25
Show Gist options
  • Save ianhomer/7ca6616e8fb31620f4eb to your computer and use it in GitHub Desktop.
Save ianhomer/7ca6616e8fb31620f4eb to your computer and use it in GitHub Desktop.

Thank you https://gist.github.com/shuichinet/8159878

Installation

This is how I install on my mac

brew reinstall python
brew install libav
sudo pip install gmusicapi
pip install urllib3
pip install certifi

Usage

Ask for username and password from terminal

./tidy-my-music.py

Or pipe in without user interaction (only do on private machine since password visible in ps)

read username ; read -s password
echo $username/$password | tr '/' '\n' | ./tidy-my-music.py

Background Reading

https://urllib3.readthedocs.org/en/latest/security.html

#!/usr/bin/env python
#
# Tidy up my music in google.
#
import ssl
import sys
import urllib3
import certifi
http = urllib3.PoolManager(
cert_reqs='CERT_REQUIRED', # Force certificate check.
ca_certs=certifi.where(), # Path to the Certifi bundle.
)
from sets import Set
from gmusicapi import Mobileclient
from getpass import getpass
username = raw_input( "Username: " )
#
# Get password from terminal or stdin if passed in
#
if sys.stdin.isatty():
password = getpass()
else:
print 'Using readline'
password = sys.stdin.readline().rstrip()
client = Mobileclient()
client.login( username, password, Mobileclient.FROM_MAC_ADDRESS )
print "Getting all songs ..."
all_songs = client.get_all_songs()
#all_songs = [ { 'album' : 'test'}, { 'album' : 'another'} ]
albums = Set([])
for song in all_songs:
album = song.get('album')
albums.add ( album )
for album in sorted(albums) :
print album
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment