-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry-point.py
51 lines (43 loc) · 1.79 KB
/
entry-point.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
from flask import Flask, request, render_template
from flask_restful import Resource, Api
from sqlalchemy import create_engine
from json import dumps
from flask.ext.jsonpify import jsonify
from gmusicapi import Mobileclient
import pymongo, socket
from pymongo import MongoClient
app = Flask(__name__)
mobile_client_handle = Mobileclient()
logged_in = mobile_client_handle.login('sy.yousuf9106@gmail.com', '9881880422', Mobileclient.FROM_MAC_ADDRESS)
# socket_handle = socket.socket()
db_handle = MongoClient('mongodb://localhost:27017/')
db = db_handle['project_heights']
accounts_collection = db['accounts']
@app.route('/search/<asset_name>')
def search(asset_name):
search_result = mobile_client_handle.search(asset_name, max_results=50)
song_hits = search_result['song_hits']
search_result_array = []
for item in song_hits:
search_result_array.append({'title':item['track']['title'], 'storeId':item['track']['storeId'], 'album':item['track']['album'], 'artist':item['track']['artist']})
return jsonify(search_result_array)
@app.route('/stream/<song_id>')
def get_streaming_url(song_id):
stream_url_result = mobile_client_handle.get_stream_url(song_id)
return stream_url_result
@app.route('/login', methods=['POST'])
def login():
username = request.form['username']
password = request.form['password']
accounts_db = db.accounts
result = accounts_db.find_one({'username': username,'password': password})
if result == None:
return jsonify({'status':'failed', 'message':'username, password combination not found'})
else:
# host_name = socket.gethostname()
# port = 3000
# socket_handle.bind((host_name, port))
# socket_handle.listen()
return render_template('dashboard.html', value=result['hash'])
if __name__ == '__main__':
app.run(port='5002')