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:
|
||||
try:
|
||||
# get the metadata
|
||||
song = EasyID3(soundLocation+"/"+i)
|
||||
title = song['title'][0]
|
||||
artist = song['artist'][0]
|
||||
except:
|
||||
try:
|
||||
# if metadata is missing, try to use file name following title_artist.mp3
|
||||
song = i.split("_")
|
||||
title = song[0]
|
||||
artist = song[1].split(".")[0]
|
||||
except:
|
||||
#if the file is not formatted with an underscore, the title is the file name
|
||||
title = i
|
||||
artist = None
|
||||
if args.art.lower() == "true" and not(args.apikey == ""):
|
||||
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"]
|
||||
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"]
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
from flask import Flask
|
||||
from flask import request
|
||||
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.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
|
||||
#Initializing all the global stuff
|
||||
random.seed()
|
||||
global partyMode
|
||||
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
|
||||
player.audio_set_volume(100)
|
||||
app = Flask(__name__)
|
||||
# because you are posting from another domain to this one, you need CORS
|
||||
CORS(app)
|
||||
# open the json file as a dictionary
|
||||
with open('./songDatabase.json', 'r') as handle:
|
||||
songDatabaseList = json.load(handle)
|
||||
|
||||
|
|
@ -36,6 +40,7 @@ def playQueuedSongs():
|
|||
z = str(player.get_state())
|
||||
|
||||
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()
|
||||
skipNow = False
|
||||
songNext = playlist.pop(0)
|
||||
|
|
@ -43,21 +48,28 @@ def playQueuedSongs():
|
|||
player.set_media(media)
|
||||
player.play()
|
||||
elif (len(playlist) == 0) and skipNow==True:
|
||||
# skip was pressed and there are no new songs
|
||||
skipNow=False
|
||||
songNext = None
|
||||
player.stop()
|
||||
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
|
||||
elif (len(playlist)<1) and (partyMode == True):
|
||||
# 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)
|
||||
|
||||
# start the media player thread
|
||||
queueThread = threading.Thread(target=playQueuedSongs)
|
||||
queueThread.daemon = True
|
||||
queueThread.start()
|
||||
|
||||
@app.route("/controls", methods=['POST'])
|
||||
def playerControls():
|
||||
# recieve control inputs (play/pause and skip) from the webUI
|
||||
global skipNow
|
||||
global media
|
||||
global partyMode
|
||||
|
|
@ -75,19 +87,22 @@ def playerControls():
|
|||
|
||||
@app.route("/settings", methods=['POST'])
|
||||
def settingsControl():
|
||||
# set the volume and partymode
|
||||
global partyMode
|
||||
recieveData = request.get_json(force=True)
|
||||
if recieveData["setting"] == "volume":
|
||||
player.audio_set_volume(int(recieveData["level"]))
|
||||
return "200"
|
||||
elif recieveData["setting"] == "getsettings":
|
||||
x = {"partymode":partyMode,"volume":player.audio_get_volume()}
|
||||
return x
|
||||
elif recieveData["setting"] == "partymode-toggle":
|
||||
partyMode = not(partyMode)
|
||||
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:
|
||||
return "400"
|
||||
|
||||
@app.route("/search", methods=['POST'])
|
||||
def searchSongDB():
|
||||
recieveData=request.get_json(force=True)
|
||||
|
|
@ -114,6 +129,9 @@ def songadd():
|
|||
def getPlaylist():
|
||||
global songNext
|
||||
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:
|
||||
if k["file"] == songNext:
|
||||
temp = k.copy()
|
||||
|
|
@ -121,6 +139,8 @@ def getPlaylist():
|
|||
temp["time"] = player.get_time()/1000
|
||||
tempPlaylist.append(temp)
|
||||
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:
|
||||
if j["file"] == i:
|
||||
tempPlaylist.append(j)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue