当前位置: 首页>>代码示例>>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;未经允许,请勿转载。