diff --git a/beetsplug/gmusic.py b/beetsplug/gmusic.py index 98f368cb4..1d5449ab9 100644 --- a/beetsplug/gmusic.py +++ b/beetsplug/gmusic.py @@ -30,17 +30,23 @@ import gmusicapi.clients class Gmusic(BeetsPlugin): def __init__(self): super(Gmusic, self).__init__() + self.config.add({ + u'auto': False, + u'uploader_id': '', + u'uploader_name': '', + u'device_id': '', + }) # Checks for OAuth2 credentials, # if they don't exist - performs authorization self.m = Musicmanager() if os.path.isfile(gmusicapi.clients.OAUTH_FILEPATH): - self.m.login() + uploader_id = self.config['uploader_id'] + uploader_name = self.config['uploader_name'] + self.m.login(uploader_id=uploader_id.as_str().upper() or None, + uploader_name=uploader_name.as_str() or None) else: self.m.perform_oauth() - self.config.add({ - u'auto': False, - }) if self.config['auto']: self.import_stages = [self.autoupload] @@ -82,6 +88,7 @@ class Gmusic(BeetsPlugin): def search(self, lib, opts, args): password = config['gmusic']['password'] email = config['gmusic']['email'] + device_id = config['gmusic']['device_id'] password.redact = True email.redact = True # Since Musicmanager doesn't support library management @@ -89,7 +96,7 @@ class Gmusic(BeetsPlugin): mobile = Mobileclient() try: mobile.login(email.as_str(), password.as_str(), - Mobileclient.FROM_MAC_ADDRESS) + device_id.as_str() or Mobileclient.FROM_MAC_ADDRESS) files = mobile.get_all_songs() except NotLoggedIn: ui.print_( diff --git a/docs/changelog.rst b/docs/changelog.rst index 4a8b9daf3..05d1f626d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -18,6 +18,8 @@ New features: :user:`jams2` * Automatically upload to Google Play Music library on track import. :user:`shuaiscott` +* New options for Google Play Music authentication in gmusic plugin. + :user:`thetarkus` Fixes: diff --git a/docs/plugins/gmusic.rst b/docs/plugins/gmusic.rst index a08c0abfa..e760f73a2 100644 --- a/docs/plugins/gmusic.rst +++ b/docs/plugins/gmusic.rst @@ -20,14 +20,15 @@ Then, you can enable the ``gmusic`` plugin in your configuration (see Usage ----- - -To automatically upload all tracks to Google Play Music, add the ``auto: yes`` -parameter to your configuration file like the example below:: +Configuration is required before use. Below is an example configuration:: gmusic: - auto: yes email: user@example.com password: seekrit + auto: yes + uploader_id: 00:11:22:33:AA:BB + device_id: F96AE4C643A5 + To upload tracks to Google Play Music, use the ``gmusic-upload`` command:: @@ -35,19 +36,7 @@ To upload tracks to Google Play Music, use the ``gmusic-upload`` command:: If you don't include a query, the plugin will upload your entire collection. -To query the songs in your collection, you will need to add your Google -credentials to your beets configuration file. Put your Google username and -password under a section called ``gmusic``, like so:: - - gmusic: - email: user@example.com - password: seekrit - -If you have enabled two-factor authentication in your Google account, you will -need to set up and use an *application-specific password*. You can obtain one -from your Google security settings page. - -Then, use the ``gmusic-songs`` command to list music:: +To list your music collection, use the ``gmusic-songs`` command:: beet gmusic-songs [-at] [ARGS] @@ -59,3 +48,36 @@ example:: For a list of all songs in your library, run ``beet gmusic-songs`` without any arguments. + + +Configuration +------------- +To configure the plugin, make a ``gmusic:`` section in your configuration file. +The available options are: + +- **email**: Your Google account email address. + Default: none. +- **password**: Password to your Google account. Required to query songs in + your collection. + For accounts with 2-step-verification, an + `app password `__ + will need to be generated. An app password for an account without + 2-step-verification is not required but is recommended. + Default: none. +- **auto**: Set to ``yes`` to automatically upload new imports to Google Play + Music. + Default: ``no`` +- **uploader_id**: Unique id as a MAC address, eg ``'00:11:22:33:AA:BB'``. + This option should be set before the maximum number of authorized devices is + reached. + If provided, use the same id for all future runs on this, and other, beets + installations as to not reach the maximum number of authorized devices. + Default: device's MAC address. +- **device_id**: Unique device ID for authorized devices. + This option only needs to be set if you receive an `InvalidDeviceId` + exception. Below the exception will be a list of valid device IDs. + Default: none. + +Refer to the `Google Play Music Help +`__ +page for more details on authorized devices.