Use google app engine.
authorstephendenham <stephendenham@2dec19e3-eb1d-4749-8193-008c8bba0994>
Sun, 21 Aug 2011 13:59:29 +0000 (13:59 +0000)
committerstephendenham <stephendenham@2dec19e3-eb1d-4749-8193-008c8bba0994>
Sun, 21 Aug 2011 13:59:29 +0000 (13:59 +0000)
git-svn-id: svn://svn.code.sf.net/p/xbmc-groove/code@49 2dec19e3-eb1d-4749-8193-008c8bba0994

addon.xml
changelog.txt
description.xml
resources/lib/GroovesharkAPI-test.py [new file with mode: 0644]
resources/lib/GroovesharkAPI.py

index 22f0fe0..5e25c0a 100644 (file)
--- a/addon.xml
+++ b/addon.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <addon id="plugin.audio.groove" name="Grooveshark XBMC"
-       version="0.5.1" provider-name="Stephen Denham">
+       version="0.5.2" provider-name="Stephen Denham">
        <requires>
                <import addon="xbmc.python" version="1.0" />
        </requires>
index b92bc62..9c1015d 100644 (file)
@@ -1,3 +1,7 @@
+0.5.2
+
+Use google app engine to serve requests.
+
 0.5.1:
 
 Refactor getting song duration to improve performance.
index 0ac420e..5079812 100644 (file)
@@ -18,7 +18,7 @@
        <title>Grooveshark XBMC</title>
 
        <!-- (required) Major.minor.build -->
-       <version>0.5.1</version>
+       <version>0.5.2</version>
 
        <!--
                (required) author name & email. at least one author name is required
diff --git a/resources/lib/GroovesharkAPI-test.py b/resources/lib/GroovesharkAPI-test.py
new file mode 100644 (file)
index 0000000..9cf14b0
--- /dev/null
@@ -0,0 +1,30 @@
+# Test
+import sys
+res = []
+groovesharkApi = GrooveAPI()
+res = groovesharkApi.pingService()
+res = groovesharkApi.login(sys.argv[1], sys.argv[2])
+#songIds = []
+#songIds.append('28645456')
+#songIds.append('26579347')
+#res=groovesharkApi.playlistRename(58197714, 'renamed playlist2')
+#res = groovesharkApi.createPlaylist("Test", songIDs)
+#res = groovesharkApi.setPlaylistSongs('58197714',songIds)
+#pprint.pprint(res)
+#res = groovesharkApi.getPlaylistSongs('58197714')
+#res = groovesharkApi.getSongSearchResults('jimmy jazz', 3)
+#res = groovesharkApi.getPopularSongsToday(3)
+#res = groovesharkApi.getSongURLFromSongID('26579347')
+#res = groovesharkApi.getAlbumSearchResults('london calling', 3)
+#res = groovesharkApi.getArtistAlbums('52283')
+#res = groovesharkApi.getArtistSearchResults('the clash', 3)
+res = groovesharkApi.getUserFavoriteSongs()
+#res = groovesharkApi.getUserPlaylists()
+#res = groovesharkApi.getSongInfos('27425375')
+#res = groovesharkApi.getPlaylistSongs(40902662)
+#res = groovesharkApi.addUserFavoriteSong('27425375')
+#res = groovesharkApi.logout()
+#res = groovesharkApi.getUserPlaylistsByUsername('stephendenham')
+#res = groovesharkApi.getArtistPopularSongs('3707')
+#
+pprint.pprint(res)
index 2f8f340..0c09e25 100644 (file)
@@ -1,7 +1,10 @@
-import socket, hmac, urllib2, pprint, md5, os, pickle, tempfile, time, re, groovesharkAccess
+import socket, hmac, urllib, urllib2, pprint, md5, os, pickle, tempfile, time, re, simplejson
 
 SESSION_EXPIRY = 1209600 # 2 weeks
 
+# Web app
+WEB_APP_URL = "http://xbmc-groove.appspot.com/"
+
 # GrooveAPI constants
 THUMB_URL = 'http://beta.grooveshark.com/static/amazonart/m'
 SONG_LIMIT = 25
@@ -23,7 +26,6 @@ class GrooveAPI:
        # Constructor
        def __init__(self):
                
-               import simplejson
                self.simplejson = simplejson
                socket.setdefaulttimeout(40)
                self.cacheDir = os.path.join(tempfile.gettempdir(), 'groovesharkapi')
@@ -44,9 +46,38 @@ class GrooveAPI:
 
        # Call to API
        def _callRemote(self, method, params):
-               self._setParams(params)
-               return groovesharkAccess.callRemote(method, self._sessionID)
-               
+               try:
+                       res = self._getRemote(method, params)
+                       url = res['url']
+                       postData = res['postData']
+                       req = urllib2.Request(url, postData)
+                       response = urllib2.urlopen(req)
+                       result = response.read()
+                       print "Response..."
+                       pprint.pprint(result)
+                       response.close()
+                       result = simplejson.loads(result)
+                       return result
+               except:
+                       return []       
+
+       # Get the API call
+       def _getRemote(self, method, params = {}):
+               postData = { "method": method, "sessionid": self._sessionID, "parameters": params }
+               postData = simplejson.dumps(postData)
+               url = WEB_APP_URL + "?postData=" + urllib.quote_plus(postData)
+               req = urllib2.Request(url)
+               response = urllib2.urlopen(req)
+               result = response.read()
+               print "Request..."
+               pprint.pprint(result)
+               response.close()
+               try:
+                       result = simplejson.loads(result)
+                       return result
+               except:
+                       return []               
+
        # Get a session id
        def _getSessionID(self):
                params = {}
@@ -133,7 +164,10 @@ class GrooveAPI:
                params = {'login': login, 'password': md5pwd}
                
                result = self._callRemote('authenticate', params)
-               uid = result['result']['UserID']
+               try:
+                       uid = result['result']['UserID']
+               except:
+                       uid = 0
                if (uid > 0):
                        return uid
                else:
@@ -474,34 +508,3 @@ class GrooveAPI:
                        list.append([str(s['PlaylistName']).encode('ascii', 'ignore'), s['PlaylistID']])
                        i = i + 1
                return list
-
-# Test
-#import sys
-#res = []
-#groovesharkApi = GrooveAPI()
-#res = groovesharkApi.pingService()
-#res = groovesharkApi.login(sys.argv[1], sys.argv[2])
-#songIds = []
-#songIds.append('28645456')
-#songIds.append('26579347')
-#res=groovesharkApi.playlistRename(58197714, 'renamed playlist2')
-#res = groovesharkApi.createPlaylist("Test", songIDs)
-#res = groovesharkApi.setPlaylistSongs('58197714',songIds)
-#pprint.pprint(res)
-#res = groovesharkApi.getPlaylistSongs('58197714')
-#res = groovesharkApi.getSongSearchResults('jimmy jazz', 3)
-#res = groovesharkApi.getPopularSongsToday(3)
-#res = groovesharkApi.getSongURLFromSongID('26579347')
-#res = groovesharkApi.getAlbumSearchResults('london calling', 3)
-#res = groovesharkApi.getArtistAlbums('52283')
-#res = groovesharkApi.getArtistSearchResults('the clash', 3)
-#res = groovesharkApi.getUserFavoriteSongs()
-#res = groovesharkApi.getUserPlaylists()
-#res = groovesharkApi.getSongInfos('27425375')
-#res = groovesharkApi.getPlaylistSongs(40902662)
-#res = groovesharkApi.addUserFavoriteSong('27425375')
-#res = groovesharkApi.logout()
-#res = groovesharkApi.getUserPlaylistsByUsername('stephendenham')
-#res = groovesharkApi.getArtistPopularSongs('3707')
-#
-#pprint.pprint(res)