Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduced the youtube processing time 90% (#391)
* Reduced the youtube processing time 90% * Updated youtube player * Update * Travis fix * Update music_server.py * Update auto_boot.sh * Updated modules in requirements file * Added vlc in install file * Update music_server.py * Update install.sh
- Loading branch information
Showing
6 changed files
with
82 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[Unit] | ||
Description=Python Server for SUSI Linux | ||
After=multi-user.target | ||
|
||
[Service] | ||
Type=simple | ||
ExecStart=/usr/bin/python3 /home/pi/SUSI.AI/susi_linux/youtube_player/music_server.py | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from flask import Flask , render_template , request | ||
from flask import jsonify | ||
import pafy | ||
import vlc | ||
|
||
app = Flask(__name__) | ||
Instance = vlc.Instance('--no-video') | ||
player = Instance.media_player_new() | ||
url = '' | ||
|
||
@app.route('/') | ||
def index(): | ||
return render_template('index.html') | ||
|
||
@app.route('/song', methods=['GET']) | ||
def youtube(): | ||
vid = request.args.get('vid') | ||
url = 'https://www.youtube.com/watch?v=' + vid | ||
video = pafy.new(url) | ||
streams = video.audiostreams | ||
best = streams[3] | ||
playurl = best.url | ||
Media = Instance.media_new(playurl) | ||
Media.get_mrl() | ||
player.set_media(Media) | ||
player.play() | ||
display_message = {"song":"started"} | ||
resp = jsonify(display_message) | ||
resp.status_code = 200 | ||
return resp | ||
|
||
@app.route('/pause') | ||
def pause(): | ||
player.pause() | ||
display_message = {"song":"paused"} | ||
resp = jsonify(display_message) | ||
resp.status_code = 200 | ||
return resp | ||
|
||
@app.route('/stop') | ||
def stop(): | ||
player.stop() | ||
display_message = {"song":"stopped"} | ||
resp = jsonify(display_message) | ||
resp.status_code = 200 | ||
return resp | ||
|
||
@app.route('/restart') | ||
def restart(): | ||
player.stop() | ||
player.player() | ||
display_message = {"song":"restarted"} | ||
resp = jsonify(display_message) | ||
resp.status_code = 200 | ||
return resp | ||
|
||
@app.route('/resume') | ||
def play(): | ||
player.play() | ||
display_message = {"song":"played"} | ||
resp = jsonify(display_message) | ||
resp.status_code = 200 | ||
return resp | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=false, port=7070, host='0.0.0.0') |