本文整理汇总了Python中rdio.Rdio类的典型用法代码示例。如果您正苦于以下问题:Python Rdio类的具体用法?Python Rdio怎么用?Python Rdio使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Rdio类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: auth
def auth():
request_token = session.get('rt')
request_token_secret = session.get('rts')
verifier = request.args.get('oauth_verifier', '')
if request_token and request_token_secret and verifier:
rdio = Rdio((RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET), (request_token, request_token_secret))
rdio.complete_authentication(verifier)
session['at'] = rdio.token[0]
session['ats'] = rdio.token[1]
session['rt'] = ''
session['rts'] = ''
rdio_data = rdio.call('currentUser', params={'extras': 'username,displayName'})['result']
username = rdio_data['username']
print 'Creating user model.'
user = User.query.filter(User.username == username).first()
if user is None:
user = User(username=username, key=rdio_data['key'], icon=rdio_data['icon'], name=rdio_data['displayName'])
db_session.add(user)
db_session.commit()
playlists = rdio.call('getPlaylists', params={'extras': 'tracks,description,isViewable'})['result']['owned']
#print playlists
import_new_user_playlists(playlists, user.id)
print 'Committed.'
session['user_id'] = user.id
print session
return redirect(url_for('main'))
else:
# Login failed, clear everything
print 'Auth failed.'
logout()
return redirect(url_for('main'))
示例2: search
def search(song):
song = song.replace(';', '')
song = song.replace('&', '')
song = song.replace('With Lyrics', '')
song = song.replace('(Official Video)', '')
song = song.replace('(Official Music Video)', '')
song = song.replace('[Official Video]', '')
song = song.replace('[Official Music Video]', '')
song = song.replace('-', '')
spotify_request = requests.get('http://ws.spotify.com/search/1/track?q=%s' % song)
spotify_root = ET.fromstring(spotify_request.content) #parse the xml out so we can do things with it
spotify_song = ''
spotify_attrib =''
if spotify_root[1].text != '0':
spotify_attrib = spotify_root[4].attrib #this looks like {'href': 'spotify:track:5TdAgcKS5HlxMcclStHODW'}
spotify_attrib = spotify_attrib["href"]
spotify_song = spotify_root[4][0].text
spotify_attrib = spotify_attrib.replace('spotify:track:', 'http://open.spotify.com/track/');
#at this point, we have the spotify song
#rdio is up next
rdio_title = ''
rdio_artist = ''
rdio_url = ''
rdio = Rdio(("ad6x8mefbh2b2kh3deezgfq2", "tdWYdpKBfH"))
rdio_song = rdio.call("search", {"query": song, "types": "Track"})
if (rdio_song["status"] == "ok" and rdio_song["result"]["track_count"] != 0):
rdio_turl = rdio_song["result"]["results"][0]["url"]
rdio_url = "http://rdio.com"
rdio_url += rdio_turl
return jsonify(spotify_url = spotify_attrib, rdio_url = rdio_url)
示例3: login
def login():
access_token = session.get('at')
access_token_secret = session.get('ats')
if access_token and access_token_secret:
rdio = Rdio((RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET), (access_token, access_token_secret))
try:
rdio_data = rdio.call('currentUser', params={'extras': 'username,displayName'})['result']
username = rdio_data['username']
user = User.query.filter(User.username == username).first()
session['user_id'] = user.id
print current_user
return redirect(url_for('main'))
except urllib2.HTTPError:
# Something went horribly wrong, like Rdio told us our app sucks.
logout()
return redirect(url_for('main'))
else:
session['at'] = ''
session['ats'] = ''
session['rt'] = ''
session['rts'] = ''
rdio = Rdio((RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET))
login_url = rdio.begin_authentication(callback_url='http://' + request.host + '/auth')
session['rt'] = rdio.token[0]
session['rts'] = rdio.token[1]
return jsonify(login_url=login_url)
示例4: GET
def GET(self):
access_token = web.cookies().get('at')
access_token_secret = web.cookies().get('ats')
if access_token and access_token_secret:
rdio = Rdio((RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET),
(access_token, access_token_secret))
# make sure that we can make an authenticated call
try:
currentUser = rdio.call('currentUser')['result']
except urllib2.HTTPError:
# this almost certainly means that authentication has been revoked for the app. log out.
raise web.seeother('/logout')
myPlaylists = rdio.call('getPlaylists')['result']['owned']
response = '''
<html><head><title>Rdio-Simple Example</title></head><body>
<p>%s's playlists:</p>
<ul>
''' % currentUser['firstName']
for playlist in myPlaylists:
response += '''<li><a href="%(shortUrl)s">%(name)s</a></li>''' % playlist
response += '''</ul><a href="/logout">Log out of Rdio</a></body></html>'''
return response
else:
return '''
示例5: rdio_access_token
def rdio_access_token(request=None, oauth_temp_db=None):
'''OAuth dance.'''
callback_token = request.args.get('oauth_token')
callback_verifier = request.args.get('oauth_verifier')
oauth_dance_token = oauth_temp_db.find_one({'oauth token': callback_token})
oauth_dance_token = oauth_dance_token['oauth_dance_token']
rdio = Rdio((CONSUMER_KEY, CONSUMER_SECRET), oauth_dance_token)
rdio.complete_authentication(callback_verifier)
access_token = rdio.token
return access_token
示例6: login_callback
def login_callback():
params = dict([part.split('=') for part in request.query_string.split('&')])
token = session['rt']
secret = session['rts']
api = Rdio((rdio_key, rdio_secret), (token, secret))
api.complete_authentication(params.get('oauth_verifier'))
session['rt'] = None
session['rts'] = None
session['at'] = api.token[0]
session['ats'] = api.token[1]
return redirect(url_for('index'))
示例7: login_callback
def login_callback():
params = dict([part.split("=") for part in request.query_string.split("&")])
token = session["rt"]
secret = session["rts"]
api = Rdio((rdio_key, rdio_secret), (token, secret))
api.complete_authentication(params.get("oauth_verifier"))
session["rt"] = None
session["rts"] = None
session["at"] = api.token[0]
session["ats"] = api.token[1]
return redirect(url_for("index"))
示例8: home
def home():
access_token = session['at']
access_token_secret = session['ats']
if len(access_token) > 0 and len(access_token_secret) > 0 and access_token and access_token_secret:
rdio = Rdio((RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET), (access_token, access_token_secret))
try:
currentUser = rdio.call('currentUser')['result']
except urllib2.HTTPError:
# this almost certainly means that authentication has been revoked for the app. log out.
return redirect(url_for(logout))
return render_template('search_form.html')
else:
return redirect(url_for('login'))
示例9: login
def login():
session['at'] = ''
session['ats'] = ''
session['rt'] = ''
session['rts'] = ''
# begin the authentication process
rdio = Rdio((RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET))
url = rdio.begin_authentication(callback_url = 'http://localhost:5000/callback')
# save our request token in cookies
session['rt'] = rdio.token[0]
session['rts'] = rdio.token[1]
# go to Rdio to authenticate the app
return redirect(url)
示例10: login
def login():
#clear all of our auth cookies
#begin auth
rdio = Rdio(RDIO_CREDENTIALS)
app.logger.debug(request.host)
url = rdio.begin_authentication(callback_url='http://'+request.host+'/callback')
redirect_to_rdio = redirect(url)
#save our request token in cookies
response = make_response(redirect_to_rdio)
print(rdio.token)
response.set_cookie('rt', rdio.token[0], expires=60*60*24)
response.set_cookie('rts', rdio.token[1], expires=60*60*24)
#go to Rdio to authenticate the app
return response
示例11: __init__
class rdio_simple:
def __init__(self, CK, CS):
self.rdio_obj = Rdio((CK, CS))
def get_user_key_from_name(self, user_name):
name = self.rdio_obj.call("findUser", {"vanityName": user_name})
return name['result']['key']
def get_collection_from_key(self, key):
collection = self.rdio_obj.call("getTracksInCollection", {"user":key})
return collection
def get_tracks_from_collection(self, collection):
for item in collection['result']:
print item['name']
示例12: __init__
class rdio_simple:
def __init__(self, CK, CS):
self.rdio_obj = Rdio((CK, CS))
def get_user_key_from_name(self, user_name):
name = self.rdio_obj.call("findUser", {"vanityName": user_name})
return name['result']['key']
def get_collection_from_key(self, key, count="100"):
collection = self.rdio_obj.call("getTracksInCollection", {"user":key, "extras":"playCount", "count":count})
return collection
def get_artists_from_collection(self, collection):
my_list = []
for item in collection['result']:
my_list.append(item['artist'].encode('utf-8'))
return my_list
示例13: top_track
def top_track(sesh):
access_token = sesh['at']
access_token_secret = sesh['ats']
if len(access_token) > 0 and len(access_token_secret) > 0 and access_token and access_token_secret:
rdio = Rdio((RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET), (access_token, access_token_secret))
try:
currentUser = rdio.call('currentUser')['result']
except urllib2.HTTPError:
# this almost certainly means that authentication has been revoked for the app. log out.
return {"error" : "failure"}
topcharts = rdio.call('getTopCharts', {'type': 'Track', 'count' : 100})
playbackToken = rdio.call('getPlaybackToken', {'domain' : 'localhost'})
import random
randomint = random.randint(0,99)
song = topcharts['result'][randomint]
song['playbackToken'] = playbackToken['result']
return song
else:
return {"error" : "failure"}
示例14: MainTest
class MainTest(unittest.TestCase):
def setUp(self):
self.consumer = ('test', 'test')
self.rdio = Rdio(self.consumer)
@patch('rdio.urlopen', mock_urlopen)
def test_unicode_params(self):
r = self.rdio.call('search', {
'query': 'Röyksopp'
})
示例15: callback
def callback():
request_token = session['rt']
request_token_secret = session['rts']
verifier = request.args["oauth_verifier"]
# make sure we have everything we need
if request_token and request_token_secret and verifier:
# exchange the verifier and request token for an access token
rdio = Rdio((RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET), (request_token, request_token_secret))
rdio.complete_authentication(verifier)
# save the access token in cookies (and discard the request token)
session['at'] = rdio.token[0]
session['ats'] = rdio.token[1]
session['rt'] = ''
session['rts'] = ''
# go to the home page
return redirect(url_for('home'))
else:
# we're missing something important
return redirect(url_for('logout'))