diff --git a/beetsplug/gmusic.py b/beetsplug/gmusic.py index 259d2725a..98f368cb4 100644 --- a/beetsplug/gmusic.py +++ b/beetsplug/gmusic.py @@ -38,6 +38,12 @@ class Gmusic(BeetsPlugin): else: self.m.perform_oauth() + self.config.add({ + u'auto': False, + }) + if self.config['auto']: + self.import_stages = [self.autoupload] + def commands(self): gupload = Subcommand('gmusic-upload', help=u'upload your tracks to Google Play Music') @@ -57,11 +63,22 @@ class Gmusic(BeetsPlugin): def upload(self, lib, opts, args): items = lib.items(ui.decargs(args)) - files = [x.path.decode('utf-8') for x in items] + files = self.getpaths(items) ui.print_(u'Uploading your files...') self.m.upload(filepaths=files) ui.print_(u'Your files were successfully added to library') + def autoupload(self, session, task): + items = task.imported_items() + files = self.getpaths(items) + self._log.info(u'Uploading files to Google Play Music...', files) + self.m.upload(filepaths=files) + self._log.info(u'Your files were successfully added to your ' + + 'Google Play Music library') + + def getpaths(self, items): + return [x.path for x in items] + def search(self, lib, opts, args): password = config['gmusic']['password'] email = config['gmusic']['email'] diff --git a/docs/changelog.rst b/docs/changelog.rst index d487f31f5..4a8b9daf3 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -16,6 +16,8 @@ New features: :bug:`2944` * Added whitespace padding to missing tracks dialog to improve readability. :user:`jams2` +* Automatically upload to Google Play Music library on track import. + :user:`shuaiscott` Fixes: diff --git a/docs/plugins/gmusic.rst b/docs/plugins/gmusic.rst index d0ba96671..a08c0abfa 100644 --- a/docs/plugins/gmusic.rst +++ b/docs/plugins/gmusic.rst @@ -21,6 +21,14 @@ 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 + To upload tracks to Google Play Music, use the ``gmusic-upload`` command:: beet gmusic-upload [QUERY]