Skip to content

Commit

Permalink
Merge pull request #3002 from thetarkus/gmusic-additions-1
Browse files Browse the repository at this point in the history
Add uploader_id, uploader_name, and device_id for gmusicapi auth in gmusic plugin
  • Loading branch information
sampsyo authored Aug 14, 2018
2 parents bac8faa + 599a6c5 commit 86d3537
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 22 deletions.
17 changes: 12 additions & 5 deletions beetsplug/gmusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,23 @@
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]

Expand Down Expand Up @@ -82,14 +88,15 @@ def getpaths(self, items):
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
# we need to use mobileclient interface
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_(
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
56 changes: 39 additions & 17 deletions docs/plugins/gmusic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,23 @@ 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::

beet gmusic-upload [QUERY]

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]

Expand All @@ -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 <https://support.google.com/accounts/answer/185833?hl=en>`__
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
<https://support.google.com/googleplaymusic/answer/3139562?hl=en>`__
page for more details on authorized devices.

0 comments on commit 86d3537

Please sign in to comment.