當前位置: 首頁>>代碼示例>>Python>>正文


Python rdio.Rdio類代碼示例

本文整理匯總了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'))
開發者ID:nickdirienzo,項目名稱:playgit,代碼行數:31,代碼來源:main.py

示例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)
開發者ID:adnissen,項目名稱:isiton,代碼行數:33,代碼來源:isiton.py

示例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)
開發者ID:nickdirienzo,項目名稱:playgit,代碼行數:26,代碼來源:main.py

示例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 '''
開發者ID:ColdSauce,項目名稱:rdio-simple,代碼行數:27,代碼來源:web-based.py

示例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
開發者ID:ecalifornica,項目名稱:rdio_playlist,代碼行數:10,代碼來源:lib.py

示例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'))
開發者ID:endenizen,項目名稱:genredio,代碼行數:11,代碼來源:web.py

示例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"))
開發者ID:klobucar,項目名稱:genredio,代碼行數:11,代碼來源:web.py

示例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'))
開發者ID:brettjurgens,項目名稱:voicedio,代碼行數:13,代碼來源:voicedio.py

示例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)
開發者ID:brettjurgens,項目名稱:voicedio,代碼行數:13,代碼來源:voicedio.py

示例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
開發者ID:mrkaiser,項目名稱:pardio,代碼行數:14,代碼來源:services.py

示例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']
開發者ID:josneville,項目名稱:VTHacks-Personalidads,代碼行數:16,代碼來源:test.py

示例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
開發者ID:josneville,項目名稱:VTHacks-Personalidads,代碼行數:18,代碼來源:server.py

示例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"}
開發者ID:brettjurgens,項目名稱:voicedio,代碼行數:19,代碼來源:voicedio.py

示例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'
        })
開發者ID:AdamGaudet,項目名稱:rdio-simple,代碼行數:11,代碼來源:test_main.py

示例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'))
開發者ID:brettjurgens,項目名稱:voicedio,代碼行數:21,代碼來源:voicedio.py


注:本文中的rdio.Rdio類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。