Created
April 22, 2012 11:24
-
-
Save makihiro/2463727 to your computer and use it in GitHub Desktop.
Upload music file to google music
This file contains 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
#!/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