Skip to content

Instantly share code, notes, and snippets.

@wernight
Created July 21, 2014 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wernight/71e3a8705b198e7cd821 to your computer and use it in GitHub Desktop.
Save wernight/71e3a8705b198e7cd821 to your computer and use it in GitHub Desktop.
"""
Requires gmusicapi from http://unofficial-google-music-api.readthedocs.org/en/latest/usage.html
"""
import os
from gmusicapi import Musicmanager
# From https://support.google.com/googleplay/answer/1100462
AUDIO_FILE_EXTENSIONS = ('.mp3', '.m4a', '.wma', '.flac', '.ogg', '.m4a')
def upload_recursive(basedir):
"""
Upload all audio files below the given directory to Google Music.
"""
# Login (first time will require to open a page and give a code).
mm = Musicmanager()
if not mm.login():
mm.perform_oauth()
if not mm.login():
raise Exception('Could not authenticate.')
# Upload all music files recursively.
for root, subFolders, files in os.walk(basedir):
for filename in files:
if os.path.splitext(filename)[1] in AUDIO_FILE_EXTENSIONS:
mm.upload(os.path.join(root, filename))
upload_recursive('.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment