added expressjs server instead of python one
This commit is contained in:
BIN
showcaseScreen/handlers/__pycache__/comHandler.cpython-310.pyc
Normal file
BIN
showcaseScreen/handlers/__pycache__/comHandler.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
26
showcaseScreen/handlers/comHandler.py
Normal file
26
showcaseScreen/handlers/comHandler.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import requests
|
||||
|
||||
|
||||
class Com:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def connect(self, url):
|
||||
self.x = requests.get(f"{url}/tryconnect")
|
||||
print(self.x.text)
|
||||
if self.x.text == "ok":
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def getcurrentsong(self, url):
|
||||
return "Testsong"
|
||||
|
||||
def getsonglength(self, url):
|
||||
return 100
|
||||
|
||||
def getupcomingsongs(self, url):
|
||||
return "Test1\nTest2"
|
||||
|
||||
def getsongpos(self, url):
|
||||
return 2
|
||||
@@ -1,33 +0,0 @@
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
import cgi
|
||||
import os
|
||||
|
||||
|
||||
class MusicPlayerServer(BaseHTTPRequestHandler):
|
||||
def _set_headers(self):
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'text/html')
|
||||
self.end_headers()
|
||||
|
||||
def do_GET(self):
|
||||
self._set_headers()
|
||||
if self.path == '/reloadstyling':
|
||||
pass
|
||||
else:
|
||||
self.opened_file = open(f".{self.path}").read()
|
||||
self.wfile.write(bytes(self.opened_file, 'utf-8'))
|
||||
|
||||
def do_POST(self):
|
||||
self._set_headers()
|
||||
self.returnsPOST = cgi.FieldStorage(
|
||||
fp=self.rfile,
|
||||
headers=self.headers,
|
||||
environ={ 'REQUEST_METHOD' : 'POST'}
|
||||
)
|
||||
print(self.returnsPOST)
|
||||
|
||||
def run(server_class=HTTPServer, handler_class=MusicPlayerServer, port=8080):
|
||||
server_address = ('', port)
|
||||
httpd = server_class(server_address, handler_class)
|
||||
print(f"Server started on {port}")
|
||||
httpd.serve_forever()
|
||||
55
showcaseScreen/handlers/trash/server.py
Normal file
55
showcaseScreen/handlers/trash/server.py
Normal file
@@ -0,0 +1,55 @@
|
||||
from code import interact
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
import cgi
|
||||
import os
|
||||
|
||||
|
||||
class MusicPlayerServer(BaseHTTPRequestHandler):
|
||||
def _set_headers(self):
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'text/html')
|
||||
self.end_headers()
|
||||
|
||||
def do_GET(self):
|
||||
self._set_headers()
|
||||
if self.path == '/reloadstyling':
|
||||
pass
|
||||
elif self.path == '/connect':
|
||||
print("connection being established")
|
||||
global details
|
||||
details.value = 1
|
||||
else:
|
||||
try:
|
||||
self.opened_file = open(f".{self.path}").read()
|
||||
self.wfile.write(bytes(self.opened_file, 'utf-8'))
|
||||
except Exception as e:
|
||||
print("There was an error in opening the specified file: 404")
|
||||
|
||||
def do_POST(self):
|
||||
self._set_headers()
|
||||
self.returnsPOST = cgi.FieldStorage(
|
||||
fp=self.rfile,
|
||||
headers=self.headers,
|
||||
environ={ 'REQUEST_METHOD' : 'POST'}
|
||||
)
|
||||
if self.path == '/publishtime':
|
||||
global playtime
|
||||
playtime.value = 1
|
||||
elif self.path == '/publishsonginfo':
|
||||
global com
|
||||
print(self.returnsPOST.value[0].value)
|
||||
if self.returnsPOST.value[0].name == "songinfos":
|
||||
com.value = self.returnsPOST.value[0].value
|
||||
|
||||
|
||||
def run(interact, instructions, pos, server_class=HTTPServer, handler_class=MusicPlayerServer, port=9999):
|
||||
server_address = ('', port)
|
||||
global details
|
||||
details = interact
|
||||
global com
|
||||
com = instructions
|
||||
global playtime
|
||||
playtime = pos
|
||||
httpd = server_class(server_address, handler_class)
|
||||
print(f"Server started on {port}")
|
||||
httpd.serve_forever()
|
||||
@@ -1,10 +1,15 @@
|
||||
import handlers.server
|
||||
import handlers.server_translator as st
|
||||
import multiprocessing as mp
|
||||
import ctypes
|
||||
|
||||
servert = st.ServerTranslator()
|
||||
|
||||
class ServerHandler:
|
||||
def __init__(self):
|
||||
pass
|
||||
self.details = mp.Manager().Value('i', 0)
|
||||
self.com = mp.Manager().Value(ctypes.c_wchar_p, "Test")
|
||||
self.playbackpos = mp.Manager().Value('i', 0)
|
||||
|
||||
def start_server(self):
|
||||
print("starting server")
|
||||
@@ -12,11 +17,10 @@ class ServerHandler:
|
||||
if self.mpserver.is_alive():
|
||||
pass
|
||||
else:
|
||||
self.mpserver = mp.Process(name="runserver", target=handlers.server.run,)
|
||||
self.mpserver = mp.Process(name="runserver", target=handlers.server.run, args=(self.details, self.com, self.playbackpos ))
|
||||
self.mpserver.start()
|
||||
except AttributeError as e:
|
||||
print(e)
|
||||
self.mpserver = mp.Process(name="runserver", target=handlers.server.run,)
|
||||
self.mpserver = mp.Process(name="runserver", target=handlers.server.run, args=(self.details, self.com, self.playbackpos, ))
|
||||
self.mpserver.start()
|
||||
|
||||
def stop_server(self):
|
||||
@@ -26,4 +30,10 @@ class ServerHandler:
|
||||
try:
|
||||
return self.mpserver.is_alive()
|
||||
except AttributeError:
|
||||
return False
|
||||
return False
|
||||
|
||||
def get_connection_status(self):
|
||||
return servert.connection(self.details)
|
||||
|
||||
def getData(self):
|
||||
return self.com.value
|
||||
13
showcaseScreen/handlers/trash/server_translator.py
Normal file
13
showcaseScreen/handlers/trash/server_translator.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from tkinter.tix import Tree
|
||||
|
||||
|
||||
class ServerTranslator:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def connection(self, details):
|
||||
print(details.value)
|
||||
if details.value == 1:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
@@ -5,24 +5,78 @@ from kivymd.app import MDApp
|
||||
from kivy.base import Builder
|
||||
from kivy.uix.popup import Popup
|
||||
from kivy.clock import Clock
|
||||
import handlers.server_handler as shand
|
||||
import handlers.comHandler
|
||||
import math
|
||||
import bin.csv_parsers
|
||||
Builder.load_file('./ui/connectionPU.kv')
|
||||
|
||||
server_manager = shand.ServerHandler()
|
||||
comHandler = handlers.comHandler.Com()
|
||||
cvr = bin.csv_parsers.CsvRead()
|
||||
|
||||
class ConnectionPU(Popup):
|
||||
pass
|
||||
|
||||
|
||||
class LoginWindow(MDScreen):
|
||||
def startserver(self):
|
||||
self.ids.statusbar.text = "Starting server..."
|
||||
server_manager.start_server()
|
||||
Clock.schedule_once(self.getStatus, 4)
|
||||
|
||||
def getStatus(self, dump):
|
||||
print("status update")
|
||||
if server_manager.get_server_status():
|
||||
self.ids.statusbar.text = "Server running on Port 8080"
|
||||
def connect(self):
|
||||
self.url = self.ids.url.text
|
||||
self.containsPort = False
|
||||
for self.letter in self.url:
|
||||
if self.letter == ":":
|
||||
self.containsPort = True
|
||||
else:
|
||||
pass
|
||||
self.connectionurl = ""
|
||||
if self.url[:8] != "https://" and self.url[:7] != "http://" and self.url[len(self.url) - 1:] == "/" and not self.containsPort:
|
||||
self.connectionurl = f"http://{self.url[:len(self.url) - 1]}:8000"
|
||||
print(comHandler.connect(self.connectionurl))
|
||||
elif self.url[:8] != "https://" and self.url[:7] != "http://" and self.url[len(self.url) - 1:] != "/" and not self.containsPort:
|
||||
self.connectionurl = f"http://{self.url}:8000"
|
||||
print(comHandler.connect(self.connectionurl))
|
||||
else:
|
||||
self.ids.statusbar.text = "There was an error starting the server or it might take longer than expected to start it."
|
||||
Clock.schedule_once(self.getStatus, 4)
|
||||
ConnectionPU().open()
|
||||
global address
|
||||
address = self.url
|
||||
|
||||
|
||||
class ShowcaseScreen(MDScreen):
|
||||
def updateScreen(self):
|
||||
global address
|
||||
self.__windowsize = Window._get_size()
|
||||
self.__windowsize_x = self.__windowsize[0]
|
||||
self.__windowsize_y = self.__windowsize[1]
|
||||
self.__text_size = round(math.sqrt(((self.__windowsize_x + self.__windowsize_y) / 2)), 0)
|
||||
self.ids.current_song.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.upcoming_ind.font_size = self.__text_size + 10
|
||||
self.__current = comHandler.getcurrentsong(address)
|
||||
self.__upcoming = comHandler.getupcomingsongs(address)
|
||||
self.__songdisplay = int(comHandler.getsonglength(address) / float(comHandler.getsongpos(address)) * 100)
|
||||
self.ids.progressbars.value = self.__songdisplay
|
||||
if self.__config == ["1"]:
|
||||
self.ids.current_song.text = self.__current[:(len(self.__current) - 4)]
|
||||
else:
|
||||
self.ids.current_song.text = self.__current
|
||||
if len(self.__upcoming) <= self.__currents:
|
||||
self.ids.upcoming_songs.text = "No more songs in Queue"
|
||||
else:
|
||||
if self.__config == ["1"]:
|
||||
self.__upcoming_output = self.__upcoming[:(len(self.__upcoming) - 4)]
|
||||
else:
|
||||
self.__upcoming_output = self.__upcoming
|
||||
|
||||
self.__length_output = 0
|
||||
for i in range(len(self.__upcoming) - self.__currents):
|
||||
if self.__length_output > 5:
|
||||
pass
|
||||
else:
|
||||
if self.__config == ["1"]:
|
||||
self.__upcoming_output += f"\n{self.__upcoming[:(len(self.__upcoming) - 4)]}"
|
||||
else:
|
||||
self.__upcoming_output += f"\n{self.__upcoming}"
|
||||
self.__length_output += 1
|
||||
self.ids.upcoming_songs.text = self.__upcoming_output
|
||||
|
||||
|
||||
class MusicPlayerShowcaseScreen(MDApp):
|
||||
@@ -34,6 +88,8 @@ class MusicPlayerShowcaseScreen(MDApp):
|
||||
self.theme_cls.primary_palette = "Blue"
|
||||
self.theme_cls.accent_palette = "Gray"
|
||||
screen_manager.add_widget(Builder.load_file("./ui/mainui.kv"))
|
||||
screen_manager.add_widget(Builder.load_file('./ui/showcase.kv'))
|
||||
return screen_manager
|
||||
|
||||
MusicPlayerShowcaseScreen().run()
|
||||
|
||||
MusicPlayerShowcaseScreen().run()
|
||||
|
||||
16
showcaseScreen/ui/connectionPU.kv
Normal file
16
showcaseScreen/ui/connectionPU.kv
Normal file
@@ -0,0 +1,16 @@
|
||||
<ConnectionPU>:
|
||||
title: "Connecting..."
|
||||
font_size: 30
|
||||
size_hint: 0.5, 0.4
|
||||
auto_dismiss: False
|
||||
GridLayout:
|
||||
cols: 1
|
||||
Label:
|
||||
text: "Invalid entry. Please ensure that you only type the IP!"
|
||||
font_size: 20
|
||||
GridLayout:
|
||||
cols: 2
|
||||
Button:
|
||||
text: "Ok"
|
||||
on_release:
|
||||
root.dismiss()
|
||||
@@ -7,11 +7,14 @@ LoginWindow:
|
||||
text: "Welcome to the MusicPlayer Showcase Screen!"
|
||||
font_size: 27
|
||||
color: (0, 0, 0, 1)
|
||||
Label:
|
||||
text: "Server is currently not running! Please start it by clicking start server!"
|
||||
id: statusbar
|
||||
color: (0, 0, 0, 1)
|
||||
FloatLayout
|
||||
TextInput:
|
||||
text: ""
|
||||
hint_text: "Type Server IP here..."
|
||||
pos_hint: {'x': 0.25, 'y': 0.5}
|
||||
size_hint: 0.5, 0.2
|
||||
id: url
|
||||
Button:
|
||||
text: "Start Server"
|
||||
on_release:
|
||||
root.startserver()
|
||||
text: "connect"
|
||||
on_release:
|
||||
root.connect()
|
||||
@@ -0,0 +1,58 @@
|
||||
ShowcaseScreen:
|
||||
name: "ShowcaseScreen"
|
||||
md_bg_color: (0, 0, 0, 1)
|
||||
FloatLayout:
|
||||
Label:
|
||||
text: "Currently Playing"
|
||||
id: titleinfo
|
||||
bold: True
|
||||
italic: True
|
||||
pos_hint: {"y": 0.35}
|
||||
font_size: 60
|
||||
color: app.theme_cls.primary_color
|
||||
MDProgressBar:
|
||||
orientation: "horizontal"
|
||||
value: 100
|
||||
pos_hint: {"y": 0.3}
|
||||
color: (1, 1, 1, 0.5)
|
||||
MDProgressBar:
|
||||
id: progressbars
|
||||
orientation: "horizontal"
|
||||
value: 0
|
||||
pos_hint: {"y": 0.3}
|
||||
color: app.theme_cls.primary_dark
|
||||
Label:
|
||||
id: current_song
|
||||
text: "Currently playing Song will appear here"
|
||||
pos_hint: {"y": 0.22}
|
||||
font_size: 45
|
||||
color: app.theme_cls.primary_color
|
||||
shorten: False
|
||||
halign: "center"
|
||||
Label:
|
||||
id: upcoming_ind
|
||||
text: "upcoming"
|
||||
bold: True
|
||||
italic: True
|
||||
font_size: 35
|
||||
pos_hint: {"y": -0.05}
|
||||
color: app.theme_cls.primary_color
|
||||
Label:
|
||||
id: upcoming_songs
|
||||
text: "Upcoming Songs will appear here"
|
||||
pos_hint: {"y": -0.25}
|
||||
font_size: 30
|
||||
color: app.theme_cls.primary_color
|
||||
shorten: False
|
||||
halign: "center"
|
||||
Button:
|
||||
text: "back"
|
||||
font_size: 10
|
||||
size_hint: 0.05, 0.05
|
||||
background_color: app.theme_cls.accent_light
|
||||
on_release:
|
||||
root.leave_screen()
|
||||
Label:
|
||||
text: "Designed and developed by Janis Hutz"
|
||||
font_size: 7
|
||||
pos_hint: {"y": -0.48}
|
||||
Reference in New Issue
Block a user