73 lines
2.2 KiB
Python
73 lines
2.2 KiB
Python
from flask import Flask, render_template
|
|
from flask_socketio import SocketIO, emit
|
|
from flask_cors import CORS
|
|
import yt_dlp
|
|
import vlc
|
|
import time
|
|
import os
|
|
import eyed3
|
|
|
|
home_directory = os.path.expanduser("~")
|
|
#app = Flask(__name__,template_folder=home_directory)
|
|
app = Flask(__name__, template_folder=(home_directory + "/Code/GR/GR-Jukebox"))
|
|
socketio = SocketIO(app, cors_allowed_origins="*")
|
|
CORS(app)
|
|
player = vlc.MediaPlayer()
|
|
music_queue = []
|
|
title_queue = []
|
|
music_directory = os.path.expanduser('~/Music')
|
|
|
|
@app.route('/')
|
|
def index():
|
|
return render_template('manage1.html')
|
|
|
|
@app.route('/display')
|
|
def display():
|
|
return render_template('display1.html')
|
|
|
|
@socketio.on('list_music')
|
|
def list_music():
|
|
music_files = []
|
|
for filename in os.listdir(music_directory):
|
|
if filename.endswith('.mp3'):
|
|
path = os.path.join(music_directory, filename)
|
|
audiofile = eyed3.load(path)
|
|
title = audiofile.tag.title if audiofile.tag else 'Unknown Title'
|
|
music_files.append({'id': filename.split('.')[0], 'title': title})
|
|
emit('music_list', music_files)
|
|
|
|
@socketio.on('download')
|
|
def download(data):
|
|
url = data['youtube_url']
|
|
# ... existing download logic ...
|
|
emit('download_status', {'status': 'success', 'message': 'Song added successfully'})
|
|
|
|
@socketio.on('play')
|
|
def play(data):
|
|
global playing_thread
|
|
music_queue.append(data['songId'])
|
|
title_queue.append(data['songTitle'])
|
|
if not playing_thread:
|
|
# ... existing play logic ...
|
|
emit('play_status', {'status': 'success', 'message': 'Playing song'})
|
|
|
|
@socketio.on('get_queue')
|
|
def get_queue():
|
|
emit('queue', [{'id': idx, 'title': title} for idx, title in enumerate(title_queue)])
|
|
|
|
@socketio.on('remove_from_queue')
|
|
def remove_from_queue(data):
|
|
song_id = int(data['songId'])
|
|
# ... existing remove logic ...
|
|
emit('remove_status', {'status': 'success', 'message': 'Song removed successfully'})
|
|
|
|
@socketio.on('current')
|
|
def current():
|
|
if len(title_queue) > 0:
|
|
emit('current_song', {'title': title_queue[0]})
|
|
else:
|
|
emit('current_song', {'title': 'Nothing is playing'})
|
|
|
|
if __name__ == "__main__":
|
|
socketio.run(app, host='0.0.0.0', debug=True, port=5000)
|