optimized network calls

This commit is contained in:
janis
2022-11-01 17:28:47 +01:00
parent 27caf79371
commit c1c677f5ea
10 changed files with 83 additions and 36 deletions

View File

@@ -1,3 +1,4 @@
import stat
import requests import requests
class ServerComs: class ServerComs:
@@ -47,7 +48,6 @@ class ServerComs:
return False return False
def getfullscreeninfo(self, url): def getfullscreeninfo(self, url):
print("fullscreencheck")
try: try:
self.x = requests.get(f"{url}/fullscreen") self.x = requests.get(f"{url}/fullscreen")
return self.x.text return self.x.text
@@ -55,10 +55,16 @@ class ServerComs:
print(e) print(e)
return "False" return "False"
def poststatus(self, url, isalive): def poststatus(self, url, statuscode):
print("updating status")
try: try:
self.x = requests.post(f"{url}/poststatus", {"status":f"{isalive}"}) self.x = requests.post(f"{url}/poststatus", {"status":statuscode})
return True
except Exception:
return False
def requestUIupdate(self, url):
try:
self.x = requests.get(f"{url}/requestuiupdate")
return True return True
except Exception: except Exception:
return False return False

View File

@@ -1,3 +1,3 @@
3 4
Tennessee Waltz - New 101 Strings Orchestra | Slow Walz (Langsam),Morning has broken - Cat Stevens | Walzer (Mittel),Magia - Alvaro Soler | Flashmob (Mittel),Say So - Doja Cat | Discofox (Langsam),Save Your Tears (Remix) - The Weeknd & Ariana Grande | Discofox (Langsam),Shivers - Ed Sheeran | Jive/ Rocknroll (Mittel),I feel good - Ray Charles | Jive/Rocknroll (Mittel),Muevelo - Rey Ruiz | Cha cha cha (Mittel),Suelta la cintura - Ruben leon | Cha cha cha (Mittel),Como Volver a Ser Feliz - Luis Enrique | Salsa (Mittel),Mas que nada - black eyed peas | Salsa/Discofox (Mittel),Moon River - Henry Mancini | Slow Walz (Langsam),Dancing Queen - ABBA | Discofox (Langsam),Don't Call Me Up - Mabel | Discofox (Mittel),Magia - Alvaro Soler | Flashmob (Mittel),Lets have a Party - Wanda Jackson | Jive (mittel),Crazy Little Thing Called Love - Queen | Jive / Rocknroll (Schnell),El Diablo Anda Suelto - Rey Ruiz | Cha cha cha (Mittel),Lets get loud - Jennifer Lopez | Cha cha cha (Schnell),Enamorame - Somos del Barrio | Salsa (Mittel),Something Stupid (feat. Reese Witherspoon) - Michael Bublé | Rumba/cha cha cha (Langsam),When a man loves a woman - Percy Sledge | (Langsam),Scharlachrot - Patent Ochsner | Walzer (Langsam),Ily (i love you baby) [feat. Emilee] - Surf Mesa | Discofox (Mittel),Like a sex machine - James Brown | Discofox (Mittel),Uptown Funk (feat. Bruno Mars) - Discofox | Discofox (Schnell),Tutti Frutti - Little Richard | Jive / Rocknroll (Mittel),Jailhouse Rock - Elvis Presley | Jive / Rocknroll (Schnell),Are you lonesome - Elvis Presley | Slow Walz (Langsam),Ay Mujer - Rey Ruiz | Cha cha cha (Mittel),Rico Vacilon - Pedro Garcia & His Del Prado Orchestra | Cha cha cha (Mittel),Jeepers creepers - Benny Goodmann | Foxtrott (Mittel),An der schönen blauen Donau - New 101 Strings Orchestra | Wiener Walzer (Schnell),The Last Waltz - Engelbert Humperdinck | Walzer (Mittel),Stand by me - Sam Brown | Cha cha cha (Lansam),Stayin' Alive - Bee Gees | Discofox (Mittel),Easy On Me - Adele | (Langsam),Magia - Alvaro Soler | Flashmob (Mittel),Friday (feat. Mufasa & Hypeman) [Dopamine Re-Edit] - Riton & Nightcrawlers | Party (Mittel),YMCA - Village People | Party (Mittel),Cotton eyed Joe (Hennustall zermatt mix) - Rednex | Party (Mittel),Gangnam style - PSY | Party (Mittel),Take On Me - a-ha | Jive (Schnell),Rock Around the Clock - Bill Haley & His Comets | Jive / Rocknroll (Schnell),Satisfaction - Rolling Stones | Party (Mittel),"Un, dos, tres - Ricky Martin | Party (Mittel)",Party Rock anthem - LFMBQ | Party (Mittel),I don't care - Icona Pop | Party (Mittel),Love tonight - Shouse & David Guetta | Party (Mittel),Insomnia - Faithless | Party (Mittel),Angels - Robbie Williams | Slow (Langsam),Nothing compares to you - Sinead O'Connor | Slow (Langsam) Tennessee Waltz - New 101 Strings Orchestra | Slow Walz (Langsam),Morning has broken - Cat Stevens | Walzer (Mittel),Magia - Alvaro Soler | Flashmob (Mittel),Say So - Doja Cat | Discofox (Langsam),Save Your Tears (Remix) - The Weeknd & Ariana Grande | Discofox (Langsam),Shivers - Ed Sheeran | Jive/ Rocknroll (Mittel),I feel good - Ray Charles | Jive/Rocknroll (Mittel),Muevelo - Rey Ruiz | Cha cha cha (Mittel),Suelta la cintura - Ruben leon | Cha cha cha (Mittel),Como Volver a Ser Feliz - Luis Enrique | Salsa (Mittel),Mas que nada - black eyed peas | Salsa/Discofox (Mittel),Moon River - Henry Mancini | Slow Walz (Langsam),Dancing Queen - ABBA | Discofox (Langsam),Don't Call Me Up - Mabel | Discofox (Mittel),Magia - Alvaro Soler | Flashmob (Mittel),Lets have a Party - Wanda Jackson | Jive (mittel),Crazy Little Thing Called Love - Queen | Jive / Rocknroll (Schnell),El Diablo Anda Suelto - Rey Ruiz | Cha cha cha (Mittel),Lets get loud - Jennifer Lopez | Cha cha cha (Schnell),Enamorame - Somos del Barrio | Salsa (Mittel),Something Stupid (feat. Reese Witherspoon) - Michael Bublé | Rumba/cha cha cha (Langsam),When a man loves a woman - Percy Sledge | (Langsam),Scharlachrot - Patent Ochsner | Walzer (Langsam),Ily (i love you baby) [feat. Emilee] - Surf Mesa | Discofox (Mittel),Like a sex machine - James Brown | Discofox (Mittel),Uptown Funk (feat. Bruno Mars) - Discofox | Discofox (Schnell),Tutti Frutti - Little Richard | Jive / Rocknroll (Mittel),Jailhouse Rock - Elvis Presley | Jive / Rocknroll (Schnell),Are you lonesome - Elvis Presley | Slow Walz (Langsam),Ay Mujer - Rey Ruiz | Cha cha cha (Mittel),Rico Vacilon - Pedro Garcia & His Del Prado Orchestra | Cha cha cha (Mittel),Jeepers creepers - Benny Goodmann | Foxtrott (Mittel),An der schönen blauen Donau - New 101 Strings Orchestra | Wiener Walzer (Schnell),The Last Waltz - Engelbert Humperdinck | Walzer (Mittel),Stand by me - Sam Brown | Cha cha cha (Lansam),Stayin' Alive - Bee Gees | Discofox (Mittel),Easy On Me - Adele | (Langsam),Magia - Alvaro Soler | Flashmob (Mittel),Friday (feat. Mufasa & Hypeman) [Dopamine Re-Edit] - Riton & Nightcrawlers | Party (Mittel),YMCA - Village People | Party (Mittel),Cotton eyed Joe (Hennustall zermatt mix) - Rednex | Party (Mittel),Gangnam style - PSY | Party (Mittel),Take On Me - a-ha | Jive (Schnell),Rock Around the Clock - Bill Haley & His Comets | Jive / Rocknroll (Schnell),Satisfaction - Rolling Stones | Party (Mittel),"Un, dos, tres - Ricky Martin | Party (Mittel)",Party Rock anthem - LFMBQ | Party (Mittel),I don't care - Icona Pop | Party (Mittel),Love tonight - Shouse & David Guetta | Party (Mittel),Insomnia - Faithless | Party (Mittel),Angels - Robbie Williams | Slow (Langsam),Nothing compares to you - Sinead O'Connor | Slow (Langsam)
237.88844299316406 191.00733947753906
1 3 4
2 Tennessee Waltz - New 101 Strings Orchestra | Slow Walz (Langsam) Tennessee Waltz - New 101 Strings Orchestra | Slow Walz (Langsam)
3 237.88844299316406 191.00733947753906

View File

@@ -81,7 +81,7 @@ class ConnectPU(Popup):
class QuitPU(Popup): class QuitPU(Popup):
def quitapp(self): def quitapp(self):
svc.poststatus(address, False) svc.poststatus(address, "stopped")
time.sleep(1) time.sleep(1)
@@ -192,6 +192,7 @@ class Main(MDScreen):
self.keyboard.bind(on_key_down=self.key_pressed) self.keyboard.bind(on_key_down=self.key_pressed)
self.quit_requests = 0 self.quit_requests = 0
self.__comparepos = 10000 self.__comparepos = 10000
self.__updateui = False
global address global address
def key_pressed(self, keyboard, keycode, text, modifiers): def key_pressed(self, keyboard, keycode, text, modifiers):
@@ -226,7 +227,7 @@ class Main(MDScreen):
self.__comparepos = 10000 self.__comparepos = 10000
if address != "": if address != "":
self.ids.connectstatus.text = f"Connected to: {address}" self.ids.connectstatus.text = f"Connected to: {address}"
svc.poststatus(address, True) svc.poststatus(address, "paused")
if svc.getfullscreeninfo(address) == "True": if svc.getfullscreeninfo(address) == "True":
self.ids.fullscreenc.text = "Exit fullscreen on client display" self.ids.fullscreenc.text = "Exit fullscreen on client display"
else: else:
@@ -261,21 +262,27 @@ class Main(MDScreen):
self.mplayer.start() self.mplayer.start()
def playmusic(self): def playmusic(self):
self.updateremoteUI()
self.others.value = 3 self.others.value = 3
if self.instructions.value == 0: if self.instructions.value == 0:
svc.poststatus(address, "playing")
self.instructions.value = 1 self.instructions.value = 1
self.ids.pp_button.text = "Pause" self.ids.pp_button.text = "Pause"
else: else:
svc.poststatus(address, "paused")
self.instructions.value = 0 self.instructions.value = 0
self.ids.pp_button.text = "Play" self.ids.pp_button.text = "Play"
def nextsong(self): def nextsong(self):
self.updateremoteUI()
self.others.value = 1 self.others.value = 1
def rewindsong(self): def rewindsong(self):
self.updateremoteUI()
self.others.value = 2 self.others.value = 2
def previoussong(self): def previoussong(self):
self.updateremoteUI()
self.others.value = 4 self.others.value = 4
def go_back(self): def go_back(self):
@@ -283,7 +290,7 @@ class Main(MDScreen):
self.mplayer.kill() self.mplayer.kill()
except: except:
pass pass
svc.poststatus(address, False) svc.poststatus(address, "stopped")
self.ids.pp_button.text = "Play" self.ids.pp_button.text = "Play"
self.manager.current = "Home" self.manager.current = "Home"
self.manager.transition.direction = "right" self.manager.transition.direction = "right"
@@ -338,12 +345,12 @@ class Main(MDScreen):
self.__length_output += 1 self.__length_output += 1
self.manager.get_screen("Showcase").ids.upcoming_songs.text = self.__upcoming_output self.manager.get_screen("Showcase").ids.upcoming_songs.text = self.__upcoming_output
if address != "": if address != "":
svc.postplaybackpos(address, self.__songpos) if self.__comparepos > self.__songpos or self.__updateui:
if self.__comparepos > self.__songpos: svc.postplaybackpos(address, self.__songpos)
svc.postcurrentsong(address, self.__current_output) svc.postcurrentsong(address, self.__current_output)
svc.postsonglength(address, self.__songlength) svc.postsonglength(address, self.__songlength)
svc.postupcomingsongs(address, self.__upcoming_output) svc.postupcomingsongs(address, self.__upcoming_output)
# svc.postfullscreen(address, self.__current_output) self.__updateui = False
else: else:
pass pass
self.__comparepos = self.__songpos self.__comparepos = self.__songpos
@@ -359,6 +366,10 @@ class Main(MDScreen):
else: else:
pass pass
def updateremoteUI(self):
self.__updateui = True
svc.requestUIupdate(address)
def open_leave_popup(self): def open_leave_popup(self):
LeavePU().open() LeavePU().open()
@@ -403,7 +414,7 @@ class MusicPlayer(MDApp):
global address global address
AppQuitting().open() AppQuitting().open()
print("leaving...") print("leaving...")
svc.poststatus(address, False) svc.poststatus(address, "stopped")
time.sleep(1) time.sleep(1)
os.killpg(os.getpgid(0), signal.SIGKILL) os.killpg(os.getpgid(0), signal.SIGKILL)

View File

@@ -14,7 +14,9 @@ var upcomingsongs = "Test\nTest2\nTest3"
var currentsong = "This is a song" var currentsong = "This is a song"
var songmaxlength = "100" var songmaxlength = "100"
var fullscreen = "False" var fullscreen = "False"
var isrunning = "False" var status = "n/a"
var doupdateUI = "False"
var isplaying = "False"
// CONFIG FOR EXPRESS // CONFIG FOR EXPRESS
@@ -50,29 +52,40 @@ app.get('/currentsong', (request, response) => {
}) })
app.get('/fullscreen', (request, response) => { app.get('/fullscreen', (request, response) => {
console.log("getting fullscreen status")
response.send(fullscreen) response.send(fullscreen)
}) })
app.get('/isrunning', (request, response) => { app.get('/isrunning', (request, response) => {
response.send(isrunning) response.send(status)
}) })
app.get('/uiupdate', (request, response) => {
response.send(doupdateUI)
doupdateUI = "False"
})
app.get('/isplaying', (request, response) => {
response.send(isplaying)
})
// POST data (Interface for Player) // POST data (Interface for Player)
app.post('/postplayback', (request, response) => { app.post('/postplayback', (request, response) => {
playbackpos = request.body.pos playbackpos = request.body.pos
doupdateUI = "True"
response.send("ok") response.send("ok")
}) })
app.post('/postupcomingsongs', (request, response) => { app.post('/postupcomingsongs', (request, response) => {
console.log("updating upcomingsongs")
upcomingsongs = request.body.songs upcomingsongs = request.body.songs
doupdateUI = "True"
response.send("ok") response.send("ok")
}) })
app.post('/postcurrentsong', (request, response) => { app.post('/postcurrentsong', (request, response) => {
currentsong = request.body.songname currentsong = request.body.songname
doupdateUI = "True"
response.send("ok") response.send("ok")
}) })
@@ -88,12 +101,19 @@ app.get('/changefullscreen', (request, response) => {
app.post('/postsonglength', (request, response) => { app.post('/postsonglength', (request, response) => {
songmaxlength = request.body.length songmaxlength = request.body.length
console.log(songmaxlength)
doupdateUI = "True"
response.send("ok") response.send("ok")
}) })
app.post('/poststatus', (request, response) => { app.post('/poststatus', (request, response) => {
console.log("updating status " + request.body.status) status = request.body.status
isrunning = request.body.status doupdateUI = "True"
response.send("ok")
})
app.get('/requestuiupdate', (request, response) => {
doupdateUI = "True"
response.send("ok") response.send("ok")
}) })

View File

@@ -63,6 +63,13 @@ class Com:
self.x = requests.get(f"{url}/isrunning") self.x = requests.get(f"{url}/isrunning")
except Exception: except Exception:
return False return False
return self.x.text
def getuiupdate(self, url):
try:
self.x = requests.get(f"{url}/uiupdate")
except Exception:
return False
if self.x.text == "True": if self.x.text == "True":
return True return True
else: else:

View File

@@ -57,11 +57,24 @@ class ShowcaseScreen(MDScreen):
self.__upcoming = comHandler.getupcomingsongs(address) self.__upcoming = comHandler.getupcomingsongs(address)
self.songlength = comHandler.getsonglength(address) self.songlength = comHandler.getsonglength(address)
self.songpos = comHandler.getsongpos(address) self.songpos = comHandler.getsongpos(address)
self.ids.current_song.text = self.__current
self.ids.upcoming_songs.text = self.__upcoming
self.ids.progressbars.value = float(self.songpos / float(self.songlength) * 100)
self.isplaying = False self.isplaying = False
Clock.schedule_interval(self.updateProgressbar, 0.1) Clock.schedule_interval(self.updateProgressbar, 0.1)
def updateScreen(self, dmp): def updateScreen(self, dmp):
Window.fullscreen = comHandler.checkiffullscreen(address) Window.fullscreen = comHandler.checkiffullscreen(address)
self.status = comHandler.checkgo(address)
if self.status == "playing":
self.isplaying = True
elif self.status == "paused":
self.isplaying = False
elif self.status == "stopped":
Window.fullscreen = False
screen_manager.current = "Login"
else:
print("ERROR in Status. Please check connection!")
Window.maximize() Window.maximize()
self.__windowsize = Window._get_size() self.__windowsize = Window._get_size()
self.__windowsize_x = self.__windowsize[0] self.__windowsize_x = self.__windowsize[0]
@@ -71,29 +84,19 @@ class ShowcaseScreen(MDScreen):
self.ids.upcoming_songs.font_size = self.__text_size - 5 self.ids.upcoming_songs.font_size = self.__text_size - 5
self.ids.titleinfo.font_size = self.__text_size * 2.2 self.ids.titleinfo.font_size = self.__text_size * 2.2
self.ids.upcoming_ind.font_size = self.__text_size + 10 self.ids.upcoming_ind.font_size = self.__text_size + 10
self.songpos = comHandler.getsongpos(address) self.__doupdateUI = comHandler.getuiupdate(address)
if self.songpos < self.lastsongpos: if self.__doupdateUI:
self.songpos = comHandler.getsongpos(address)
self.__current = comHandler.getcurrentsong(address) self.__current = comHandler.getcurrentsong(address)
self.__upcoming = comHandler.getupcomingsongs(address) self.__upcoming = comHandler.getupcomingsongs(address)
self.songlength = comHandler.getsonglength(address) self.songlength = comHandler.getsonglength(address)
elif self.songpos > self.lastsongpos: self.ids.progressbars.value = float(self.songpos / float(self.songlength) * 100)
self.isplaying = True self.ids.current_song.text = self.__current
elif self.songpos == self.lastsongpos: self.ids.upcoming_songs.text = self.__upcoming
self.isplaying = False
else:
pass
self.lastsongpos = self.songpos
self.ids.current_song.text = self.__current
self.ids.upcoming_songs.text = self.__upcoming
if comHandler.checkgo(address):
pass
else:
Window.fullscreen = False
screen_manager.current = "Login"
def updateProgressbar(self, dmp): def updateProgressbar(self, dmp):
if self.isplaying: if self.isplaying:
self.__songdisplay = float(self.songpos / float(self.songlength) * 100) self.__songdisplay = float(self.songpos / float(self.songlength) * 100) - 1
self.songpos += 0.1 self.songpos += 0.1
self.ids.progressbars.value = self.__songdisplay self.ids.progressbars.value = self.__songdisplay