# -*- coding: utf-8 -*-
-# VIM MODLINE
+LFM = {'apikey': 'NG4xcDlxcXJwMjk4MTZycTgwM3E3b3I5MTEzb240cG8',
+ 'host':'ws.audioscrobbler.com',
+ 'version': '2.0',
+ }
+
+ECH = {'apikey': 'WlRKQkhTS0JHWFVDUEZZRFA',
+ 'host': 'developer.echonest.com',
+ 'version': 'v4',
+ }
+
+
# vim: ai ts=4 sw=4 sts=4 expandtab
"""
-__version__ = '0.3.0'
+__version__ = '0.3.1'
__author__ = 'Jack Kaliko'
from time import sleep
from xml.etree.cElementTree import ElementTree
+from sima import LFM
+from sima.utils.utils import getws
+getws(LFM)
+
# Some definitions
WAIT_BETWEEN_REQUESTS = timedelta(0, 0.4)
LFM_ERRORS = dict({'2': 'Invalid service -This service does not exist',
class SimaFM():
"""
"""
- api_key = '4a1c9ddec29816ed803d7be9113ba4cb'
- host = 'ws.audioscrobbler.com'
- version = '2.0'
- root_url = 'http://%s/%s/' % (host, version)
+ root_url = 'http://{host}/{version}/'.format(**LFM)
request = dict({'similar': '?method=artist.getsimilar&artist=%s&' +\
- 'api_key=%s' % api_key,
+ 'api_key={apikey}'.format(**LFM),
'top': '?method=artist.gettoptracks&artist=%s&' +\
- 'api_key=%s' % api_key,
+ 'api_key={apikey}'.format(**LFM),
'track': '?method=track.getsimilar&artist=%s' +\
- '&track=%s' + '&api_key=%s' % api_key,
+ '&track=%s' + 'api_key={apikey}'.format(**LFM),
'info': '?method=artist.getinfo&artist=%s' +\
- '&api_key=%s' % api_key,
+ 'api_key={apikey}'.format(**LFM),
})
cache = dict({})
timestamp = datetime.utcnow()
# along with sima. If not, see <http://www.gnu.org/licenses/>.
#
#
-"""generic tools and utilitaries for sima
+"""generic tools and utilities for sima
"""
import traceback
import sys
from argparse import ArgumentError, Action
+from base64 import b64decode as push
+from codecs import getencoder
from os import environ, access, getcwd, W_OK, R_OK
from os.path import dirname, isabs, join, normpath, exists, isdir, isfile
+
+def getws(dic):
+ """
+ Decode Obfuscated api key.
+ Only preventing API keys harvesting over the network
+ https://developer.echonest.com/forums/thread/105
+ """
+ aka = push(bytes(dic.get('apikey') + '=', 'utf-8'))
+ aka = getencoder('rot-13')(str((aka), 'utf-8'))[0]
+ dic.update({'apikey':aka})
+
def get_mpd_environ():
"""
Retrieve MPD env. var.