Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleaning

  • Loading branch information...
commit 686db215d746e15c36934c8aa0251d66dfcf62a8 1 parent bcb3f33
@showi showi authored
View
11 .settings/org.eclipse.core.resources.prefs
@@ -1,5 +1,6 @@
-#Mon Mar 19 23:01:06 CET 2012
-eclipse.preferences.version=1
-encoding//resources/lib/qobuz/node/recommendation.py=UTF-8
-encoding//resources/lib/qobuz/renderer/irenderer.py=UTF-8
-encoding//resources/lib/qobuz/renderer/xbmc.py=UTF-8
+#Mon Dec 24 12:51:39 CET 2012
+eclipse.preferences.version=1
+encoding//resources/lib/qobuz/node/recommendation.py=UTF-8
+encoding//resources/lib/qobuz/renderer/irenderer.py=UTF-8
+encoding//resources/lib/qobuz/renderer/xbmc.py=UTF-8
+encoding/<project>=UTF-8
View
1  default.py
@@ -32,7 +32,6 @@
sys.path.append(qobuzDir)
from bootstrap import QobuzBootstrap
-import qobuz
boot = QobuzBootstrap(__addon__, int(sys.argv[1]))
boot.bootstrap_app()
View
0  resources/lib/qobuz/core.py → resources/lib/qobuz/OLDcore.py
File renamed without changes
View
0  resources/lib/qobuz/images.py → resources/lib/qobuz/OLDimages.py
File renamed without changes
View
24 resources/lib/qobuz/api.py
@@ -14,23 +14,19 @@
#
# You should have received a copy of the GNU General Public License
# along with xbmc-qobuz. If not, see <http://www.gnu.org/licenses/>.
-import os
+#import os
import json
-import time
import requests
-#import hashlib
-#import pickle
import pprint
from time import time
import math
import hashlib
-#import qobuz
-from debug import *
-import socket
-socket.timeout = 5
+from debug import warn, log
+import socket
+socket.timeout = 5
class QobuzApi:
@@ -117,20 +113,19 @@ def _api_request(self,params,uri,**opt):
'''
When something wrong we are deleting our auth token
'''
- if self.auth:
- self.auth.delete_cache()
+# if self.auth:
+# self.auth.delete_cache()
return None
return response_json
def login(self,user,password):
- print "Login with user " + user
- # from cache.authentication import Cache_authentication
+ log(self, 'Login with user ' + user)
params = {
'password': hashlib.md5(password).hexdigest(),
'username': user,
'email': user + '@QobuzXbmc.beta',
}
- data = self._api_request(params,"/user/login",noToken=True)
+ data = self._api_request(params, "/user/login", noToken=True)
if not data: return None
if not 'user' in data: return None
if not 'id' in data['user']: return None
@@ -271,7 +266,8 @@ def playlist_create (self,playlist_name,tracks_id='',description='',album_id='',
'spotify_track_uris':'',
'deezer_playlist_url':''}
- log("info","creating new playlist" + str(playlist_name) + "with (or without) tracks :" + tracks_id + ")")
+ log("info","creating new playlist " + str(playlist_name) + " / tracks[" + tracks_id + "]")
+ log(self, 'Token: ' + self.authtoken)
return self._api_request(params,"/playlist/create")
def playlist_delete (self,playlist_id):
View
74 resources/lib/qobuz/bootstrap.py
@@ -27,6 +27,11 @@
import qobuz
from node.flag import NodeFlag
+from exception import QobuzXbmcError
+
+import json
+import pprint
+
''' Arguments parssing '''
def get_params():
d = dog()
@@ -50,20 +55,27 @@ def get_params():
warn('[DOG]', "--- Invalid key: %s / value: %s" % (splitparams[0], splitparams[1]))
return rparam
-class xbmc_json_rpc():
+class XbmcRPC:
def __init__(self):
pass
-
- def Introspect(self, id):
- return xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "JSONRPC.Introspect", "id": %i }' % (id))
-
- def AudioLibrary_GetAlbums(self, params = {}):
- s = ''
- if 'id' in params: s = '"id": "' + str(params['id']) + '"'
- elif 'name' in params: s = '"Audio.Fields.Artist": "' + str(params['name']) + '"'
- return xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"AudioLibrary.GetAlbums","params":{"genreid": -1 ,"artistid": 1 ,"start": -1,"end": -1 }, "id":"AudioLibraryGetAlbums"}')
-
+
+ def send(self, request):
+ if not request: raise QobuzXbmcError(who=self, what='missing_parameter', additional='request')
+ request['jsonrpc'] = '2.0'
+ request['method'] = 'JSONRPC.' + request['method']
+ if not 'id' in request: request['id'] = 1
+ rjson = json.dumps(request)
+ print 'REQUEST: ' + rjson
+ ret = xbmc.executeJSONRPC(rjson)
+ return ret
+
+ def ping(self):
+ request = {
+ 'method': 'Ping',
+ }
+ return self.send(request)
+
'''
QobuzBootstrap
'''
@@ -73,20 +85,27 @@ def __init__(self, __addon__, __handle__):
qobuz.addon = __addon__
self.handle = __handle__
qobuz.boot = self
+# rpc = XbmcRPC()
+# ret = rpc.ping()
+# pprint.pprint(ret)
def bootstrap_app(self):
self.bootstrap_directories()
self.bootstrap_lang()
self.bootstrap_utils()
self.bootstrap_api()
- self.bootstrap_core()
- self.bootstrap_image()
self.bootstrap_gui()
self.bootstrap_sys_args()
+ self.bootstrap_registry()
+
+ return self.dispatch()
+
+ def bootstrap_lang(self):
+ qobuz.lang = qobuz.addon.getLocalizedString
+
+ def bootstrap_registry(self):
from registry import QobuzRegistry
-
streamFormat = 6 if qobuz.addon.getSetting('streamtype') == 'flac' else 5
- #print 'streamFormat: ' + str(streamFormat)
qobuz.registry = QobuzRegistry(
cacheType='default',
user=qobuz.addon.getSetting('username'),
@@ -96,12 +115,7 @@ def bootstrap_app(self):
if not qobuz.registry.get(name='user'):
qobuz.gui.show_login_failure()
exit(1)
-
- return self.dispatch()
-
- def bootstrap_lang(self):
- qobuz.lang = qobuz.addon.getLocalizedString
-
+
def bootstrap_utils(self):
import utils.string
class Utils():
@@ -155,14 +169,6 @@ def bootstrap_api(self):
from api import QobuzApi
qobuz.api = QobuzApi()
- def bootstrap_core(self):
- from core import QobuzCore
- qobuz.core = QobuzCore()
-
- def bootstrap_image(self):
- pass
- # from images import QobuzImage
- # qobuz.image = QobuzImage()
def bootstrap_gui(self):
from gui.utils import Utils
@@ -207,11 +213,11 @@ def erase_cache(self):
cm = cache_manager()
cm.delete_all_data()
- '''
-
- '''
- def build_url_return(self):
- return sys.argv[2]
+# '''
+#
+# '''
+# def build_url_return(self):
+# return sys.argv[2]
'''
Execute methode based on MODE
'''
View
1  resources/lib/qobuz/constants.py
@@ -18,6 +18,7 @@
__debugging__ = 0
class __Mode():
+
def __init__(self):
self.VIEW = 1
self.PLAY = 2
View
4 resources/lib/qobuz/gui/directory.py
@@ -93,9 +93,7 @@ def end_of_directory(self):
cacheToDisc = success)
if self.total_put == 0:
label = self.root.get_label()
- #print "LABEL: " + label
- #qobuz.gui.notifyH(qobuz.lang(40001), label)
- self.update(100, 100, qobuz.lang(40003), qobuz.lang(40002) + ': ' + str(self.total_put).encode('ascii', 'ignore') + ' items')
+ self.update(100, 100, qobuz.lang(40003), qobuz.lang(40002) + ': ' + str(self.total_put) + ' items')
self.close()
return success
View
7 resources/lib/qobuz/gui/utils.py
@@ -41,16 +41,15 @@ def __init__(self):
def notifyH(self, title, text, image = None, mstime = 2000):
try:
if not image: image = qobuz.image.access.get('qobuzIcon')
- except: pass
-
+ except: pass
s = 'XBMC.Notification("%s", "%s", "%s", "%s")' % (title, text, mstime, image)
- xbmc.executebuiltin(s)
+ xbmc.executebuiltin(s.encode('utf-8', 'replace'))
def notify(self, title, text, image = None, mstime = 2000):
#if not image: image = qobuz.image.access.get('qobuzIcon')
l = qobuz.lang
s = 'XBMC.Notification("%s", "%s", "%s", "%s")' % (l(title), l(text), mstime, image)
- xbmc.executebuiltin(s)
+ xbmc.executebuiltin(s.encode('utf-8', 'replace'))
def show_login_failure(self):
__language__ = qobuz.lang
View
27 resources/lib/qobuz/node/node.py
@@ -43,42 +43,26 @@ def __init__(self,parent=None,parameters=None):
self.label2 = ""
self.is_folder = True
self._data = None
-# self.auto_set_cache = False
-
-
-# def set_cache(self):
-# warn(self, "node::set_cache (must be overloaded")
-# return False
-#
-# def set_auto_set_cache(self, b):
-# if b: self.auto_set_cache = True
-# else: self.auto_set_cache = False
def delete_tree(self):
for child in self.childs:
child.delete_tree()
del self.childs
del self.parent
-# del self._data
del self.parameters
-# del self.cache
-
+
def set_data(self,data):
self._data = data
-# def get_data(self):
-# return self._data
-
-# def fetch_data(self):
-# if not self.cache: return None
-# return self.cache.fetch_data()
+ def get_data(self):
+ return self._data
def get_property(self,path):
if not self._data:
return ''
if isinstance(path,basestring):
if path in self._data and self._data[path] and self._data[path] != 'None':
- return self._data[path] #.encode('utf8','ignore')
+ return self._data[path]
return ''
root = self._data
for i in range(0,len(path)):
@@ -86,7 +70,7 @@ def get_property(self,path):
return ''
root = root[path[i]]
if root and root != 'None':
- return root # .encode('utf8','replace')
+ return root
return ''
def set_is_folder(self,b):
@@ -271,7 +255,6 @@ def help_make_url(self,mode,nt,nid):
return '%s?mode=%i&nt=%i&nid=%s' % (sys.argv[0],mode,nt,nid)
def attach_context_menu(self,item):
- # import urllib
color = qobuz.addon.getSetting('color_item')
menuItems = []
cmd = ''
View
33 resources/lib/qobuz/node/product.py
@@ -97,12 +97,7 @@ def get_artist(self):
if a: return a
a = self.get_property(('composer', 'name'))
if a: return a
- a = self.get_property(('data','artist', 'name'))
- if a: return a
- a = self.get_property(('data','interpreter', 'name'))
- if a: return a
- a = self.get_property(('data','composer', 'name'))
- return a
+ return None
def get_artist_id(self):
a = self.get_property(('artist', 'id'))
@@ -111,31 +106,16 @@ def get_artist_id(self):
if a: return int(a)
a = self.get_property(('composer', 'id'))
if a: return int(a)
- a = self.get_property(('data','artist', 'id'))
- if a: return int(a)
- a = self.get_property(('data','interpreter', 'id'))
- if a: return int(a)
- a = self.get_property(('data','composer', 'id'))
- if a: return int(a)
return None
def get_title(self):
- title = self.get_property('title')
- if title:
- return title
- return self.get_property(('data','title'))
- #if not title: title = self.get_property(('data','subtitle'))
- #return title
+ return self.get_property('title')
def get_image(self):
image = self.get_property(( 'image', 'large'))
if image:
self.image = image
return image
-# image = self.get_property(( 'data', 'image', 'large'))
-# if image:
-# self.image = image
-# return image
if self.parent:
image = self.parent.get_image()
if image: self.image = image
@@ -153,16 +133,13 @@ def get_label2(self):
return self.get_label()
def get_genre(self):
- genre = self.get_property(('genre', 'name'))
- if genre:
- return genre
- return self.get_property(('data','genre', 'name'))
+ return self.get_property(('genre', 'name'))
def get_year(self):
import time
- date = self.get_property(('data','released_at'))
+ date = self.get_property(('released_at'))
if not date:
- date = self.get_property(('data','released_at'))
+ date = self.get_property(('released_at'))
year = 0
try: year = time.strftime("%Y", time.localtime(date))
except: pass
View
2  resources/lib/qobuz/node/purchases.py
@@ -17,14 +17,12 @@
import qobuz
from flag import NodeFlag
from node import Node
-#from product import Node_product
from debug import error
'''
NODE PURCHASES
'''
-#from cache.purchases import Cache_purchases
from product import Node_product
class Node_purchases(Node):
View
2  resources/lib/qobuz/player.py
@@ -103,7 +103,7 @@ def play(self, id):
PLaying track
'''
if qobuz.addon.getSetting('notification_playingsong') == 'true':
- qobuz.gui.notifyH(lang(34000), node.get_label().encode('utf8', 'replace'), node.get_image())
+ qobuz.gui.notifyH(lang(34000), node.get_label(), node.get_image())
'''
We are called from playlist...
View
2  resources/lib/qobuz/qobuz.py
@@ -22,7 +22,7 @@
lang = None
gui = None
api = None
-core = None
+#core = None
db = None
boot = None
debug = None
View
34 resources/lib/qobuz/registry.py
@@ -9,17 +9,17 @@
class QobuzLocalStorage(object):
- def __init__(self,*args,**kwargs):
+ def __init__(self,**ka):
# Checking mandatory parameters
mandatory = ['user', 'password', 'streamFormat']
for key in mandatory:
- if not key in kwargs: raise QobuzXbmcError(
+ if not key in ka: raise QobuzXbmcError(
who=self,
what='missing_parameter',
additional=key)
# Setting our options
- self.options = kwargs
+ self.options = ka
if not 'autoSave' in self.options:
self.options['autoSave'] = True
if not 'autoLoad' in self.options:
@@ -37,10 +37,12 @@ def __init__(self,*args,**kwargs):
# Login into Qobuz our raise exception
key = self.make_key(name='user', id=0)
- data = self.get(name='user', id=0, user=kwargs['user'], password=kwargs['password'])
- if not data: raise QobuzXbmcError(who= self, what= 'login_failure', additional= kwargs['user'])
+ data = self.get(name='user', id=0, user=ka['user'], password=ka['password'])
+ if not data: raise QobuzXbmcError(who= self, what= 'login_failure', additional= ka['user'])
+ print "We are logged"
# We feed our api wit user data (auth_token, rights ...)
self.api.set_logged(**data)
+ print 'Token: ' + self.api.authtoken
def lastError(self):
@@ -82,7 +84,7 @@ def get(self,*args, **kwargs):
return None
def load(self, **ka):
- log(self, "Loading with Qobuz API")
+ log(self, "Loading data from Qobuz")
if ka['name'] == 'user':
response = self.api.login(ka['user'], ka['password'])
elif ka['name'] == 'product':
@@ -169,7 +171,6 @@ def load(self, **kwargs):
key = self.make_key(**kwargs)
if not self._load_from_disk(**kwargs):
pass
-# print "Loading from disk fail"
if key in self.data and self.fresh(key):
return self.data[key]
return super(QobuzCacheDefault, self).load(**kwargs)
@@ -184,7 +185,6 @@ def save(self, key = None):
return count
if not key in self.data:
QobuzXbmcError({'Who': self,'What': 'undefined_key','With': key})
- #print 'Saving key ' + key
cache = os.path.join(self.options['basePath'], key+'.dat');
with open(cache, 'wb') as f:
s = pickle.dump(self.data[key], f, protocol = pickle.HIGHEST_PROTOCOL)
@@ -223,9 +223,8 @@ def make_key(self, *args, **kwargs):
def load(self, **kwargs):
key = self.make_key(**kwargs)
- #self.storage.delete(key)
data = self.storage.get(key)
- print "LOADING " + key + ' / ' + pprint.pformat(data)
+ log(self, "LOADING " + key + ' / ' + pprint.pformat(data))
if data:
print pprint.pformat(data)
return pickle.loads(data)
@@ -248,6 +247,7 @@ def save(self, key = None):
return 1
class QobuzRegistry():
+
def __init__(self,*args,**kwargs):
if not 'cacheType' in kwargs:
kwargs['cacheType'] = 'default'
@@ -255,12 +255,10 @@ def __init__(self,*args,**kwargs):
self.cache = QobuzCacheDefault(*args,**kwargs)
elif kwargs['cacheType'] == 'xbmc-common':
cache = None
-# try:
- cache = QobuzCacheCommon(*args, **kwargs)
-# except Exception:
-# pass
- #pprint.pformat(Exception)
- #cache = QobuzCacheDefault(*args, **kwargs)
+ try:
+ cache = QobuzCacheCommon(*args, **kwargs)
+ except Exception:
+ cache = QobuzCacheDefault(*args, **kwargs)
self.cache = cache
else:
QobuzXbmcError(who=self, what='unknown_cache_type',additionnal=kwargs['cacheType'])
@@ -287,6 +285,8 @@ def delete(self, **kwargs):
def make_key(self, **kwargs):
return self.cache.make_key(**kwargs)
+
+
if __name__ == '__main__':
# try:
# QobuzXbmcError({'Who': 'TestException','What': 'test_exception','With': 'TestingException'})
@@ -304,4 +304,4 @@ def make_key(self, **kwargs):
for pl in user_playlists['data']['playlists']['items']:
print '[' + repr(pl['id']) + ']' + "Name: " + pl['name']
playlist = reg.get(name='playlist', id=pl['id'])
-
+
Please sign in to comment.
Something went wrong with that request. Please try again.