mirror of
https://github.com/vale981/clay
synced 2025-03-05 09:31:40 -05:00
Added CLAY_DEBUG that writes all Google Play Music traffic to /tmp/clay-api-log.json
This commit is contained in:
parent
cccc97522b
commit
32f7936f4e
2 changed files with 29 additions and 1 deletions
28
clay/gp.py
28
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.
|
||||
|
|
|
@ -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([
|
||||
|
|
Loading…
Add table
Reference in a new issue