From b1d5cc1485dd9a1ea845f758bc489b11e6207f3c Mon Sep 17 00:00:00 2001 From: thetarkus Date: Mon, 13 Aug 2018 02:52:16 -0400 Subject: [PATCH 1/4] Add uploader_id, uploader_name, and device_id for gmusicapi auth. --- beetsplug/gmusic.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) 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_( From 2b031be99c52b5aad75d51815e1f194ed5467fe2 Mon Sep 17 00:00:00 2001 From: Mike Mob Date: Mon, 13 Aug 2018 19:16:01 -0400 Subject: [PATCH 2/4] Update gmusic.rst --- docs/plugins/gmusic.rst | 65 ++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/docs/plugins/gmusic.rst b/docs/plugins/gmusic.rst index a08c0abfa..e585ec742 100644 --- a/docs/plugins/gmusic.rst +++ b/docs/plugins/gmusic.rst @@ -20,14 +20,7 @@ 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:: - - gmusic: - auto: yes - email: user@example.com - password: seekrit +**Configuration required before use.** To upload tracks to Google Play Music, use the ``gmusic-upload`` command:: @@ -35,19 +28,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 +40,45 @@ 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. + +Below is an example configuration:: + + gmusic: + email: user@example.com + password: seekrit + auto: yes + uploader_id: 00:11:22:33:AA:BB + device_id: F96AE4C643A5 From e13faf7f2473ba043d7c4bf55d140e3508026b30 Mon Sep 17 00:00:00 2001 From: Mike Mob Date: Mon, 13 Aug 2018 22:25:36 -0400 Subject: [PATCH 3/4] Update gmusic.rst --- docs/plugins/gmusic.rst | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/docs/plugins/gmusic.rst b/docs/plugins/gmusic.rst index e585ec742..e760f73a2 100644 --- a/docs/plugins/gmusic.rst +++ b/docs/plugins/gmusic.rst @@ -20,7 +20,15 @@ Then, you can enable the ``gmusic`` plugin in your configuration (see Usage ----- -**Configuration required before use.** +Configuration is required before use. Below is an example configuration:: + + gmusic: + 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:: @@ -73,12 +81,3 @@ The available options are: Refer to the `Google Play Music Help `__ page for more details on authorized devices. - -Below is an example configuration:: - - gmusic: - email: user@example.com - password: seekrit - auto: yes - uploader_id: 00:11:22:33:AA:BB - device_id: F96AE4C643A5 From 599a6c54480dc71e45e8645fa9d370de82aafd27 Mon Sep 17 00:00:00 2001 From: Mike Mob Date: Mon, 13 Aug 2018 22:36:17 -0400 Subject: [PATCH 4/4] Update changelog.rst --- docs/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) 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: