tons of comment updates
probaby gonna make some incompatible changes soon to the format of the songDatabase
This commit is contained in:
parent
da423f49aa
commit
7c580b7bef
2 changed files with 30 additions and 6 deletions
|
|
@ -46,19 +46,23 @@ if args.art.lower() == "true":
|
||||||
|
|
||||||
for i in songFiles:
|
for i in songFiles:
|
||||||
try:
|
try:
|
||||||
|
# get the metadata
|
||||||
song = EasyID3(soundLocation+"/"+i)
|
song = EasyID3(soundLocation+"/"+i)
|
||||||
title = song['title'][0]
|
title = song['title'][0]
|
||||||
artist = song['artist'][0]
|
artist = song['artist'][0]
|
||||||
except:
|
except:
|
||||||
try:
|
try:
|
||||||
|
# if metadata is missing, try to use file name following title_artist.mp3
|
||||||
song = i.split("_")
|
song = i.split("_")
|
||||||
title = song[0]
|
title = song[0]
|
||||||
artist = song[1].split(".")[0]
|
artist = song[1].split(".")[0]
|
||||||
except:
|
except:
|
||||||
|
#if the file is not formatted with an underscore, the title is the file name
|
||||||
title = i
|
title = i
|
||||||
artist = None
|
artist = None
|
||||||
if args.art.lower() == "true" and not(args.apikey == ""):
|
if args.art.lower() == "true" and not(args.apikey == ""):
|
||||||
try:
|
try:
|
||||||
|
# get the smallest possible image from lastFM
|
||||||
image = ast.literal_eval(requests.post(url="http://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key="+apikeylastfm+"&artist="+artist+"&track="+title+"&format=json").text)["track"]["album"]["image"][1]["#text"]
|
image = ast.literal_eval(requests.post(url="http://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key="+apikeylastfm+"&artist="+artist+"&track="+title+"&format=json").text)["track"]["album"]["image"][1]["#text"]
|
||||||
if image == "":
|
if image == "":
|
||||||
image = ast.literal_eval(requests.post(url="http://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key="+apikeylastfm+"&artist="+artist+"&track="+title+"&format=json").text)["track"]["album"]["image"][2]["#text"]
|
image = ast.literal_eval(requests.post(url="http://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key="+apikeylastfm+"&artist="+artist+"&track="+title+"&format=json").text)["track"]["album"]["image"][2]["#text"]
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask import request
|
from flask import request
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
import json,vlc,csv,threading,time,random, argparse
|
import json,vlc,threading,time,random, argparse
|
||||||
|
# Argparse Stuff
|
||||||
parser=argparse.ArgumentParser(description="Options for the Webby Bits")
|
parser=argparse.ArgumentParser(description="Options for the Webby Bits")
|
||||||
parser.add_argument('-p','--port',help="Pick a port to host on, not the same as the web (client) port",default='19054')
|
parser.add_argument('-p','--port',help="Pick a port to host on, not the same as the web (client) port",default='19054')
|
||||||
porttheuserpicked=parser.parse_args().port
|
porttheuserpicked=parser.parse_args().port
|
||||||
|
#Initializing all the global stuff
|
||||||
random.seed()
|
random.seed()
|
||||||
global partyMode
|
global partyMode
|
||||||
global skipNow
|
global skipNow
|
||||||
|
|
@ -19,7 +21,9 @@ player = fakeplayer.media_player_new()
|
||||||
# for client side volume to work as well as possible, set system volume to 100 and control in app
|
# for client side volume to work as well as possible, set system volume to 100 and control in app
|
||||||
player.audio_set_volume(100)
|
player.audio_set_volume(100)
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
# because you are posting from another domain to this one, you need CORS
|
||||||
CORS(app)
|
CORS(app)
|
||||||
|
# open the json file as a dictionary
|
||||||
with open('./songDatabase.json', 'r') as handle:
|
with open('./songDatabase.json', 'r') as handle:
|
||||||
songDatabaseList = json.load(handle)
|
songDatabaseList = json.load(handle)
|
||||||
|
|
||||||
|
|
@ -36,6 +40,7 @@ def playQueuedSongs():
|
||||||
z = str(player.get_state())
|
z = str(player.get_state())
|
||||||
|
|
||||||
if playlist and (z == "State.Ended" or z== "State.Stopped" or z == "State.NothingSpecial" or skipNow == True):
|
if playlist and (z == "State.Ended" or z== "State.Stopped" or z == "State.NothingSpecial" or skipNow == True):
|
||||||
|
# New song is in the queue and (the previous song is over or skip has been pressed)
|
||||||
player.stop()
|
player.stop()
|
||||||
skipNow = False
|
skipNow = False
|
||||||
songNext = playlist.pop(0)
|
songNext = playlist.pop(0)
|
||||||
|
|
@ -43,21 +48,28 @@ def playQueuedSongs():
|
||||||
player.set_media(media)
|
player.set_media(media)
|
||||||
player.play()
|
player.play()
|
||||||
elif (len(playlist) == 0) and skipNow==True:
|
elif (len(playlist) == 0) and skipNow==True:
|
||||||
|
# skip was pressed and there are no new songs
|
||||||
skipNow=False
|
skipNow=False
|
||||||
songNext = None
|
songNext = None
|
||||||
player.stop()
|
player.stop()
|
||||||
elif (len(playlist) == 0) and (z == "State.Ended" or z == "State.NothingSpecial" or z=="State.Stopped"):
|
elif (len(playlist) == 0) and (z == "State.Ended" or z == "State.NothingSpecial" or z=="State.Stopped"):
|
||||||
|
# i feel like this could actually be combined with the above, but imma not do that rn
|
||||||
songNext = None
|
songNext = None
|
||||||
elif (len(playlist)<1) and (partyMode == True):
|
elif (len(playlist)<1) and (partyMode == True):
|
||||||
playlist.append(random.choice(songDatabaseList)["file"])
|
# adds the random songs for party mode
|
||||||
|
# the above 2 means this only applies if (a song is playing (or paused)) and the queue is empty
|
||||||
|
playlist.append(random.choice(songDatabaseList)["file"])
|
||||||
|
# check for new songs every second
|
||||||
|
# I just didn't want to eat too much processing looping
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
# start the media player thread
|
||||||
queueThread = threading.Thread(target=playQueuedSongs)
|
queueThread = threading.Thread(target=playQueuedSongs)
|
||||||
queueThread.daemon = True
|
queueThread.daemon = True
|
||||||
queueThread.start()
|
queueThread.start()
|
||||||
|
|
||||||
@app.route("/controls", methods=['POST'])
|
@app.route("/controls", methods=['POST'])
|
||||||
def playerControls():
|
def playerControls():
|
||||||
|
# recieve control inputs (play/pause and skip) from the webUI
|
||||||
global skipNow
|
global skipNow
|
||||||
global media
|
global media
|
||||||
global partyMode
|
global partyMode
|
||||||
|
|
@ -75,19 +87,22 @@ def playerControls():
|
||||||
|
|
||||||
@app.route("/settings", methods=['POST'])
|
@app.route("/settings", methods=['POST'])
|
||||||
def settingsControl():
|
def settingsControl():
|
||||||
|
# set the volume and partymode
|
||||||
global partyMode
|
global partyMode
|
||||||
recieveData = request.get_json(force=True)
|
recieveData = request.get_json(force=True)
|
||||||
if recieveData["setting"] == "volume":
|
if recieveData["setting"] == "volume":
|
||||||
player.audio_set_volume(int(recieveData["level"]))
|
player.audio_set_volume(int(recieveData["level"]))
|
||||||
return "200"
|
return "200"
|
||||||
elif recieveData["setting"] == "getsettings":
|
|
||||||
x = {"partymode":partyMode,"volume":player.audio_get_volume()}
|
|
||||||
return x
|
|
||||||
elif recieveData["setting"] == "partymode-toggle":
|
elif recieveData["setting"] == "partymode-toggle":
|
||||||
partyMode = not(partyMode)
|
partyMode = not(partyMode)
|
||||||
return "200"
|
return "200"
|
||||||
|
elif recieveData["setting"] == "getsettings":
|
||||||
|
# probably should have made this a different request type or something but it works
|
||||||
|
x = {"partymode":partyMode,"volume":player.audio_get_volume()}
|
||||||
|
return x
|
||||||
else:
|
else:
|
||||||
return "400"
|
return "400"
|
||||||
|
|
||||||
@app.route("/search", methods=['POST'])
|
@app.route("/search", methods=['POST'])
|
||||||
def searchSongDB():
|
def searchSongDB():
|
||||||
recieveData=request.get_json(force=True)
|
recieveData=request.get_json(force=True)
|
||||||
|
|
@ -114,6 +129,9 @@ def songadd():
|
||||||
def getPlaylist():
|
def getPlaylist():
|
||||||
global songNext
|
global songNext
|
||||||
tempPlaylist = []
|
tempPlaylist = []
|
||||||
|
# what went through my head to make past-me think this is a good idea???
|
||||||
|
# i mean actually looping through once still shouldn't ever take that long
|
||||||
|
# but like a binary search must exist in python and be faster
|
||||||
for k in songDatabaseList:
|
for k in songDatabaseList:
|
||||||
if k["file"] == songNext:
|
if k["file"] == songNext:
|
||||||
temp = k.copy()
|
temp = k.copy()
|
||||||
|
|
@ -121,6 +139,8 @@ def getPlaylist():
|
||||||
temp["time"] = player.get_time()/1000
|
temp["time"] = player.get_time()/1000
|
||||||
tempPlaylist.append(temp)
|
tempPlaylist.append(temp)
|
||||||
for i in playlist:
|
for i in playlist:
|
||||||
|
# oh my goodness i did it again
|
||||||
|
# i seriously need to rewrite the databaseGenerator and this code
|
||||||
for j in songDatabaseList:
|
for j in songDatabaseList:
|
||||||
if j["file"] == i:
|
if j["file"] == i:
|
||||||
tempPlaylist.append(j)
|
tempPlaylist.append(j)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue