forked from codeasylums-bootcamp/evil_geniuses_may-19
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app11.py
111 lines (78 loc) · 2.86 KB
/
app11.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from flask import Flask,request,jsonify,render_template
from flask_cors import CORS
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
import wikipedia
import urllib.request
from bs4 import BeautifulSoup
app=Flask(__name__)
CORS(app)
client_id = "f25ca164f4be46c3b3ee7717d200bb7c"
client_secret = "dda0905887ab4cf29bbf17c4f7325201"
client_credentials_manager = SpotifyClientCredentials(client_id=client_id, client_secret=client_secret)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
@app.route("/",methods=['GET'])
def main():
return "Hello Guys!"
@app.route("/search/<string:name>",methods=['GET'])
def search4(name):
query = urllib.parse.quote(name)
url = "https://www.youtube.com/results?search_query=" + query
response = urllib.request.urlopen(url)
html = response.read()
soup = BeautifulSoup(html, 'html.parser')
for vid in soup.findAll(attrs={'class':'yt-uix-tile-link'}):
xxx = 'https://www.youtube.com' + vid['href']
break
return jsonify({"search":xxx})
@app.route("/wiki/<string:name>",methods=['GET'])
def search5(name):
xyzz = (wikipedia.summary(name, sentences=4))
return jsonify({"search":xyzz})
@app.route("/album/<string:name>",methods=['GET'])
def search1(name):
#return name
result = sp.search(name)
result['tracks']['items'][0]['artists']
artist_uri = result['tracks']['items'][0]['artists'][0]['uri']
sp_albums = sp.artist_albums(artist_uri, album_type='album')
album_names = []
album_uris = []
for i in range(len(sp_albums['items'])):
album_names.append(sp_albums['items'][i]['name'])
album_uris.append(sp_albums['items'][i]['uri'])
return jsonify({"name":album_names})
@app.route("/track/<string:name>",methods=['GET'])
def search2(name):
result = sp.search(name)
result['tracks']['items'][0]['artists']
nami=[]
po =len(result['tracks']['items'])
for i in range(0,po):
nami.append(result['tracks']['items'][i]['name'])
return jsonify({"name":nami})
@app.route("/<string:name>",methods=['GET'])
def search3(name):
result = sp.search(name)
nami=[]
namo=[]
album_data=[]
final=[]
artist = result['tracks']['items'][0]['album']['artists'][0]['name']
io=len(result['tracks']['items'])
for i in range(0,io):
album={
'name':result['tracks']['items'][i]['name'],
'duration':result['tracks']['items'][i]['duration_ms'],
'release_date':result['tracks']['items'][i]['album']['release_date'],
}
final.append(album)
img_url=result['tracks']['items'][0]['album']['images'][0]['url']
song_data={
'data':final,
'artist_name':artist,
'img_url':img_url
}
for i in range(0,io):
nami.append(result['tracks']['items'][i]['name'])
return jsonify(song_data)