Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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()
Add Comment
Please, Sign In to add comment