def spotify_api(): ''' Attempting to use the 'Spotify-api' API wrapper ''' credentials = Client(c.sp_client_id, c.sp_client_secret) print(credentials) spfy = Spotify(credentials) print(spfy) search_result = spotify.search('shadows', ['track']) for trach in search_result: print(track.name)
def spotify_search_api_request(): """Return API responses for search query.""" access_token = session['spotify_token'] query = request.args.get("userquery") spotify_data = spotify.search(query, access_token) youtube_data = youtube.search(query) mixcloud_data = mixcloud.search(query) return jsonify({ 'spotify': spotify_data, 'youtube': youtube_data, 'mixcloud': mixcloud_data })
def add_song(text): if 'playlist' in session: query = text[4:] search_results = spotify.search(query) message = 'Please respond with the song # or none:\n' session['songs'] = [] for i, song in enumerate(search_results): message += '{0}) {1} by {2}\n'.format(i + 1, song.title, song.artist) session['songs'].append({'title': song.title, 'artist': song.artist, 'id': song.id}) session['new_song'] = True return message else: return ('Please use the "choose" or "new" command before "add".')
def add_song(text): if 'playlist' in session: query = text[4:] search_results = spotify.search(query) message = 'Please respond with the song # or none:\n' session['songs'] = [] for i, song in enumerate(search_results): message += '{0}) {1} by {2}\n'.format(i + 1, song.title, song.artist) session['songs'].append({ 'title': song.title, 'artist': song.artist, 'id': song.id }) session['new_song'] = True return message else: return ('Please use the "choose" or "new" command before "add".')
def search(): songName = request.form['songName'] susername = request.form['susername'] spassword = request.form['spassword'] gusername = request.form['gusername'] gpassword = request.form['gpassword'] googlemusic.setup(gusername,gpassword) list1 = []; if gusername and gpassword: list1 = googlemusic.search(songName) list2 = []; if susername and spassword: list2 = spotify.search(songName) list = []; for i in range(min(len(list1),len(list2))): list.append({'track': list1[i], 'platform' : 'google music'}); list.append({'track': list2[i], 'platform' : 'spotify'}); return jsonify({'songs' : list})
def main(): main_form = MainForm() message = None # post method for main form to work with spotify API if main_form.validate_on_submit(): search_name = main_form.search_name.data first_query = spotify.search('artist', search_name, session.get('auth_header')) if (len(first_query[spotify.SPOTIFY_ARTISTS][spotify.SPOTIFY_ITEMS]) == 0): return redirect(url_for('bad_query')) artist_id = first_query[spotify.SPOTIFY_ARTISTS][ spotify.SPOTIFY_ITEMS][0][spotify.SPOTIFY_ID] # getting related artists for a specific artist second_query = spotify.get_related_artists(artist_id, session.get('auth_header')) rel_artists = [] for artist in second_query[spotify.SPOTIFY_ARTISTS]: rel_artists.append(artist['name']) if len(rel_artists) > 10: rel_artists = rel_artists[:10] # getting top tracks for a specific artist third_query = spotify.get_artists_top_tracks( artist_id, session.get('auth_header')) top_tracks = [] for track in third_query[spotify.SPOTIFY_TRACKS]: top_tracks.append(track['name']) if len(top_tracks) > 10: top_tracks = top_tracks[:10] db.db.artist.insert({ "name": search_name, "related_artists": rel_artists, "top_tracks": top_tracks }) return redirect(url_for('user')) return render_template('main.html', main_form=main_form)
def inlinequery(update: Update, context: CallbackContext): """Handle the inline query.""" #print("Handling Inline Query") try: if update.inline_query is not None and update.inline_query.query: query = update.inline_query.query #print(emoji_meaning) emoji_meaning=emojify(f'U000{ord(query[-1]):X}') if emoji_meaning =='NULL': emoji_meaning=emoji.demojize(query) emoji_meaning=emoji_meaning.replace(':','') emoji_meaning=emoji_meaning.replace('_',' ') emoji_meaning=emoji_meaning.replace('face','') #update.message.reply_text(emoji_meaning) #emoji_meaning='love' spotify_data=spotify.search(emoji_meaning) #print(spotify_data) results=[] #print(spotify_data['playlists']['items']) n=len(spotify_data['playlists']['items']) print(n) r = (random.randint(1,n)) print(r-1) data=spotify_data['playlists']['items'][r-1] #print(data['uri']) songs_data=spotify.read_playlist(data['uri']) #for i, t in enumerate(spotify_data['playlists']['items']): # songs_data=spotify.read_playlist(str(t['uri'])) #print(songs_data) for songs in songs_data: results.append(InlineQueryResultArticle(id=uuid4(),title=songs['song_name'], thumb_url=songs['thumbnail'],description=songs['artist_name'], input_message_content=InputTextMessageContent(songs['url']))) update.inline_query.answer(results) except Exception as e: print(e) print_exc()
def get_track_play(db: DbStore, creds, track_name, artist_name): # Check local database first for id local_db_play = db.play_from_name_and_artist(track_name, artist_name) if local_db_play is not None: local_db_play["played_at"] = None local_db_play["context"] = None print("FROM LOCAL DB {} {}".format(track_name, artist_name)) return local_db_play # No luck, spotify search instead to get id query = "track:{} artist:{}".format(track_name, artist_name) result = search(query, "track", "tracks", creds) for track in result: if track["name"] == track_name: for artist in track["artists"]: if artist["name"] == artist_name: print("FROM SPOTIFY {} {}".format(track_name, artist_name)) return { "track": track, "played_at": None, # Fill this out later "context": None # No context in GDPR } return None
def search_handler(): results = search(request.args.get('q')) return jsonify(results)
from __future__ import print_function import sys sys.path.append('../') import spotify # lets first search for an artist... I really like Michael Jackson, lets search for it results = spotify.search(['artist'], 'Michael Jackson') # results is a nest dictionary # if you want to see with your eyes... print(results) # lets see the results and choose the first result as our correct artist # with enough info probably spotify api will rank what you're looking for # correcty print('Search results:') print('-------------------------------------------------------') artists = results['artists']['items'] for a in artists: print('%s, popularity: %s' % (a['name'], a['popularity'])) print() print() # WE HAVE THE ARTIST :D! And now we can make more awesome things with it artist_id = artists[0]['id'] # I want to know more about this artist... let me ask spotify artist_info = spotify.get_artist(artist_id)
import sys sys.path.append('../') import spotify # lets first search for an album... I really like Currents from Tame Impala, lets search for it results = spotify.search(['album'], 'Currents') # results is a nest dictionary # if you want to see with your eyes... print results # lets see the results and choose the first result as our correct album # with enough info probably spotify api will rank what you're looking for # correcty print 'Search results:' print '-------------------------------------------------------' albums = results['albums']['items'] for a in albums: print '%s by %s' % (a['name'], a['artists'][0]['name']) print print # WE HAVE THE ALBUM :D! And now we can make more awesome things with it album_id = albums[0]['id'] # lets see more info about each track of the album print 'Tracks'
def mainthread(param = ''): if(param == ''): input = stt.listen() else: input = param #bot commands -start if(input == 'exit' or input == 'bye' or input == 'quiet'): input = '' tts2.speak('goodbye, have a nice day sir!') global var var = False #spotify commands check - start elif (input == "open spotify"): input = "" import spotify tts2.speak('spotify opened') elif (input == "play" or input == "pause"): input = "" try: spotify.playPause() except NameError: tts2.speak(NameErrorSpeak) elif (input == "exit spotify" or input == "close spotify"): input = "" try: spotify.close() except NameError: tts2.speak(NameErrorSpeak) elif (input == "mute"): input = "" try: spotify.mute() except NameError: tts2.speak(NameErrorSpeak) elif (input == "next"): input = "" try: spotify.next() except NameError: tts2.speak(NameErrorSpeak) elif (input == "previous"): input = "" try: spotify.prev() except NameError: tts2.speak(NameErrorSpeak) elif (input == "shuffle"): input = "" try: spotify.shuffle() except NameError: tts2.speak(NameErrorSpeak) elif (input == "repeat"): input = "" try: spotify.repeat() except NameError: tts2.speak(NameErrorSpeak) elif (input == "like"): input = "" try: spotify.like() except NameError: tts2.speak(NameErrorSpeak) elif (input == "what is playing" or input == "what's playing"): input = "" try: spotify.nowPlaying() except NameError: tts2.speak(NameErrorSpeak) elif ('search' in str(input) and 'spotify' in str(input)): try: stopwords = ['search', 'for', 'spotify', 'on'] querywords = input.split() resultwords = [word for word in querywords if word.lower() not in stopwords] result = ' '.join(resultwords) spotify.search(result) input = "" except NameError: tts2.speak(NameErrorSpeak) except: print("error occured!") elif (input == "test method"): input = "" spotify.search("attention") elif (input == "home"): input = "" try: spotify.home() except NameError: tts2.speak(NameErrorSpeak) #spotify commands check -end #time and date commands -start elif((detectionwords.detectwhat(input) == 'found') and ('time' in str(input))): input = '' tts2.speak(str(timeFunc.exec('time'))) elif((detectionwords.detectwhat(input) == 'found') and ('date' in str(input))): input = '' tts2.speak(str(timeFunc.exec('date'))) elif((detectionwords.detectwhat(input) == 'found') and ('day' in str(input))): input = '' tts2.speak(str(timeFunc.exec('day'))) elif((detectionwords.detectwhat(input) == 'found') and ('month' in str(input))): input = '' tts2.speak(str(timeFunc.exec('month'))) elif((detectionwords.detectwhat(input) == 'found') and ('year' in str(input))): input = '' tts2.speak(str(timeFunc.exec('year'))) elif((detectionwords.detectwhat(input) == 'found') and ('hour' in str(input))): input = '' tts2.speak(str(timeFunc.exec('hour'))) elif((detectionwords.detectwhat(input) == 'found') and (('minute' in str(input)) or ('minutes' in str(input)))): input = '' tts2.speak(str(timeFunc.exec('minute')))
elif (input == "what is playing" or input == "what's playing"): input = "" try: spotify.nowPlaying() except NameError: tts2.speak(NameErrorSpeak) elif ('search' in str(input) and 'spotify' in str(input)): try: stopwords = ['search', 'for', 'spotify', 'on'] querywords = input.split() resultwords = [word for word in querywords if word.lower() not in stopwords] result = ' '.join(resultwords) spotify.search(result) input = "" except NameError: tts2.speak(NameErrorSpeak) except: print("error occured!") elif (input == "test method"): input = "" spotify.search("attention") elif (input == "home"): input = "" try: spotify.home() except NameError: