Skip to content

Commit

Permalink
Switch to oauth authentication for MobileClient and update Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedikt Putz committed Dec 10, 2018
1 parent 15f023b commit bd680cf
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ venv.bak/
.mypy_cache/

# specific
.idea/
noresults.txt
*.ini
*.cred
*.txt
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions GoogleMusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

class GoogleMusic:
def __init__(self):
conf = settings['google']
self.api = Mobileclient(debug_logging=False)
self.api.login(conf['email'], conf['password'], Mobileclient.FROM_MAC_ADDRESS)
self.api.login(self.api.login(settings['google']['mobileclient']))

def createPlaylist(self, name, songs):
playlistId = self.api.create_playlist(name=name, description=None, public=False)
Expand Down
10 changes: 2 additions & 8 deletions GoogleMusicManager.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import sys
import settings
from gmusicapi import Musicmanager

credentials = u'./oauth.cred'

class GoogleMusicManager:
def __init__(self):
self.api = Musicmanager(debug_logging=False)
self.api.login(credentials)
self.api.login(settings['google']['musicmanager'])

def upload_song(self, file):
self.api.upload(file)

if __name__ == "__main__":
if sys.argv[0] == "setup":
api = Musicmanager(debug_logging=True)
api.perform_oauth(credentials)
exit()

gmusic = GoogleMusicManager()
gmusic.upload_song(sys.argv[0])
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
# spotifyplaylist_to_gmusic
A simple script to clone a Spotify playlist to Google Play Music.

Initially you should create a new settings.ini containing your credentials for Google Play Music and Spotify.
Initially you should create a new settings.ini containing your Spotify credentials. Simply copy settings.ini.example to a new file settings.ini and fill in your client_id and client_secret from https://developer.spotify.com/my-applications

For Google Play Music, get an app password from https://myaccount.google.com/apppasswords.
For Google Play Music, run

For Spotify, get your client_id and client_secret from https://developer.spotify.com/my-applications
`python Setup.py <client>`

After you've create the settings file, you can simply run the script from the command line using
and follow the command line instructions to grant the app access to your account. All credentials are stored locally in the file `settings.ini`.

Replace `<client>` with `mobileclient` to setup playlist transfers. Replace with `musicmanager` to be able to upload files with GoogleMusicManager.py.

After you've created the settings file, you can simply run the script from the command line using

`python GoogleMusic.py <spotifylink>`

where `<spotifylink>` is a link like https://open.spotify.com/user/edmsauce/playlist/3yGp845Tz2duWCORALQHFO


The script will log its progress and output songs that were not found in Google Play Music to **noresults.txt**.


To upload songs, run

`python GoogleMusic.py <filepath>`
12 changes: 12 additions & 0 deletions Setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import sys
import settings
from gmusicapi import Musicmanager, Mobileclient

if __name__ == "__main__":
if sys.argv[1] == "mobileclient":
api = Mobileclient(debug_logging=True)
settings['google']['mobileclient'] = api.perform_oauth(open_browser=True).to_json()
elif sys.argv[1] == "musicmanager":
api = Musicmanager(debug_logging=True)
settings['google']['musicmanager'] = api.perform_oauth(open_browser=True).to_json()
settings.save()
3 changes: 1 addition & 2 deletions settings.ini.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[google]
email = [email protected]
password = 123kd72k1h


[spotify]
client_id = id_from_developer_console
Expand Down
18 changes: 15 additions & 3 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@
import os

config = configparser.ConfigParser()
config.read(os.path.dirname(os.path.realpath(__file__)) + '/settings.ini')
filepath = os.path.dirname(os.path.realpath(__file__)) + '/settings.ini'
config.read(filepath)


class Settings(types.ModuleType):

class settings(types.ModuleType):
def __getitem__(self, key):
return config[key]

sys.modules[__name__] = settings("settings")
def __setitem__(self, section, key, value):
config.set(section, key, value)

def save(self):
with open(filepath, 'w') as f:
config.write(f)



sys.modules[__name__] = Settings("settings")

0 comments on commit bd680cf

Please sign in to comment.