Created
July 21, 2014 08:27
-
-
Save wernight/71e3a8705b198e7cd821 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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