diff --git a/clay/gp.py b/clay/gp.py index 08bb805..ec77045 100644 --- a/clay/gp.py +++ b/clay/gp.py @@ -5,7 +5,10 @@ Google Play Music integration via gmusicapi. # pylint: disable=too-many-arguments # pylint: disable=too-many-instance-attributes # pylint: disable=too-many-return-statements +# pylint: disable=protected-access from __future__ import print_function +import os +import json from threading import Thread, Lock from uuid import UUID @@ -415,7 +418,12 @@ class GP(object): def __init__(self): assert self.__class__.instance is None, 'Can be created only once!' + self.is_debug = os.getenv('CLAY_DEBUG') self.mobile_client = Mobileclient() + if self.is_debug: + self.mobile_client._make_call = self._make_call_proxy(self.mobile_client._make_call) + self.debug_file = open('/tmp/clay-api-log.json', 'w') + self._last_call_index = 0 self.cached_tracks = None self.cached_playlists = None @@ -433,6 +441,26 @@ class GP(object): return cls.instance + def _make_call_proxy(self, func): + """ + Return a function that wraps *fn* and logs args & return values. + """ + def _make_call(protocol, *args, **kwargs): + """ + Wrapper function. + """ + result = func(protocol, *args, **kwargs) + self._last_call_index += 1 + call_index = self._last_call_index + self.debug_file.write(json.dumps([ + call_index, + protocol.__name__, args, kwargs, + result + ]) + '\n') + self.debug_file.flush() + return result + return _make_call + def invalidate_caches(self): """ Clear cached tracks & playlists. diff --git a/clay/meta.py b/clay/meta.py index 33c1a6a..56f0278 100644 --- a/clay/meta.py +++ b/clay/meta.py @@ -7,7 +7,7 @@ except ImportError: codename = None APP_NAME = 'Clay Player' -VERSION = '0.5.3' +VERSION = '0.5.4' if codename is not None: VERSION += '-' + codename(separator='-', id=VERSION) USER_AGENT = ' '.join([