Skip to content

Instantly share code, notes, and snippets.

@makihiro
Created April 22, 2012 11:24
Show Gist options
  • Save makihiro/2463727 to your computer and use it in GitHub Desktop.
Save makihiro/2463727 to your computer and use it in GitHub Desktop.
Upload music file to google music
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gmusicapi.api import Api
from getpass import getpass
import sys
def init():
api = Api()
logged_in = False
attempts = 0
while not logged_in and attempts < 3:
#password = getpass()
logged_in = api.login("gmailaddress", "passwordhere")
attempts += 1
return api
def add_to_playlist(api, playlist_name, song_id):
res = api.get_all_playlist_ids(auto=False, instant=False, user=True, always_id_lists=False)
for k,v in res['user'].items():
if k.encode("cp932") == playlist_name:
playlist_id = v
api.add_songs_to_playlist(playlist_id, [song_id])
def upload_song(api, filename):
res = api.upload([filename])
for k, v in res.items():
song_id = v
return v
def main():
if len(sys.argv) < 3:
return
api = init()
if not api.is_authenticated():
return
filename = sys.argv[1]
playlist = sys.argv[2]
song_id = upload_song(api,filename)
add_to_playlist(api, playlist, song_id)
api.logout()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment