From fbb35c94ae876b8803b4edc50a740a3b4a3805fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=88=9A=28noham=29=C2=B2?= Date: Thu, 29 Feb 2024 22:13:19 +0100 Subject: [PATCH] server + music player --- html.html | 50 +++++++++++++++++ server.py | 2 +- style.css | 139 +++++++++++++++++++++++++++++++++++++++++++++++ test.applescript | 2 +- test.py | 69 ++++++++++++----------- 5 files changed, 227 insertions(+), 35 deletions(-) create mode 100644 html.html create mode 100644 style.css diff --git a/html.html b/html.html new file mode 100644 index 0000000..0baa38e --- /dev/null +++ b/html.html @@ -0,0 +1,50 @@ + + + + + + + + + + + Music Player + + + + +
+
+
+ +
+ + LogoMusicImage + +
+

Tired of a Bewildered Heart

+

Elijah Lee & Casiio

+
+ +
+ +
+
+
+
2:12
+
00:50
+
+
+ + +
+
+
+ + + + + + + \ No newline at end of file diff --git a/server.py b/server.py index 0b5af28..ab03772 100644 --- a/server.py +++ b/server.py @@ -13,4 +13,4 @@ def display_content(): return jsonify(cache) if __name__ == '__main__': - app.run(debug=True) + app.run(debug=True) \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..ce4cbb3 --- /dev/null +++ b/style.css @@ -0,0 +1,139 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +body { + background-repeat: no-repeat; + background-size: cover; + +} + +body * { + font-family: 'Roboto', sans-serif; +} + +#boxes * { + border: 1px solid transparent; +} + +#boxes { + display: grid; + grid-template-columns: max-content max-content; + grid-template-areas: + 'A B' + 'A C'; + gap: 32px; + place-content: center; + height: 100vh; +} + +#player { + grid-area: B; + height: fit-content; +} + +#player .controls { + display: flex; + justify-content: space-around; +} + +.player { + background-color: #080747; + padding: 28px; + border-radius: 20px; +} + +.player img { + width: 84px; + height: 84px; + object-fit: cover; + border-radius: 10px; +} + + +.info { + color: #E1E1E6; +} + +.info p { + opacity: 0.68; + font-size: 19px; +} + +.info-wrapper { + display: flex; + align-items: center; + gap: 30px; +} + +.player h1 { + font-size: 27px; + color: #E1E1E6; + padding-bottom: 7px; +} + + +.controls { + display: flex; + justify-content: space-between; + padding-top: 20px; +} + +.track { + padding-top: 28px; + position: relative; + +} + +.track::before { + content: ''; + height: 6px; + width: 100%; + display: block; + background: #D9D9D9; + opacity: 0.3; + border-radius: 10px; + position: absolute; +} + +.track::after { + content: ''; + height: 6px; + width: 85%; + display: block; + background: #D9D9D9; + border-radius: 10px; + + +} + +.time { + opacity: 0.7; + font-size: 14px; + color: gainsboro; + + display: flex; + justify-content: space-between; + padding-top: 9.6px; +} + +@media (max-width: 670px) { + #boxes { + display: flex; + flex-direction: column; + + max-width: 270px; + margin: auto; + + + height: auto; + padding-block: 60px; + } + + + +} \ No newline at end of file diff --git a/test.applescript b/test.applescript index 6abb653..c9dda90 100644 --- a/test.applescript +++ b/test.applescript @@ -46,7 +46,7 @@ tell application "Music" -- set trackInfo to "{'''name''': '''" & name of cTrack & "''', '''time''': '''" & time of cTrack & "''', '''duration''': '''" & duration of cTrack & "''', '''artist''': '''" & artist of cTrack & "''', '''album artist''': '''" & album artist of cTrack & "''', '''composer''': '''" & composer of cTrack & "''', '''album''': '''" & album of cTrack & "''', '''genre''': '''" & genre of cTrack & "''', '''played count''': '''" & played count of cTrack & "''' , '''pState''' = '''" & pState & "''', '''pPosition''' = '''" & pPosition & "'''}" - set trackInfo to "{'''status''': '''playing''', '''name''': '''" & name of cTrack & "''', '''time''': '''" & time of cTrack & "''', '''duration''': '''" & duration of cTrack & "''', '''artist''': '''" & artist of cTrack & "''', '''album artist''': '''" & album artist of cTrack & "''', '''composer''': '''" & composer of cTrack & "''', '''album''': '''" & album of cTrack & "''', '''genre''': '''" & genre of cTrack & "''', '''played count''': '''" & played count of cTrack & "''', '''pState''' : '''" & pState & "''', '''pPosition''' : '''" & pPosition & "''' }" + set trackInfo to "{'''status''': '''playing''', '''persistent ID''': '''" & persistent ID of cTrack & "''', '''name''': '''" & name of cTrack & "''', '''time''': '''" & time of cTrack & "''', '''duration''': '''" & duration of cTrack & "''', '''artist''': '''" & artist of cTrack & "''', '''album artist''': '''" & album artist of cTrack & "''', '''composer''': '''" & composer of cTrack & "''', '''album''': '''" & album of cTrack & "''', '''genre''': '''" & genre of cTrack & "''', '''played count''': '''" & played count of cTrack & "''', '''pState''' : '''" & pState & "''', '''pPosition''' : '''" & pPosition & "''' }" return trackInfo else return "{'''status''' : '''not playing'''}" diff --git a/test.py b/test.py index fd8de6c..0b956ba 100644 --- a/test.py +++ b/test.py @@ -13,13 +13,12 @@ def get_track_extras(song, artist, album): r = requests.get("https://itunes.apple.com/search", params=params) json_data = r.json() - # print('json_data: ', json_data) if json_data["resultCount"] == 1: result = json_data["results"][0] elif json_data["resultCount"] > 1: - pass + result = json_data["results"][0] else : - pass + result = '' artwork_url = result["artworkUrl100"] if result else None itunes_url = result["trackViewUrl"] if result else None @@ -27,41 +26,45 @@ def get_track_extras(song, artist, album): return (artwork_url, itunes_url, artist_url) -url = "http://127.0.0.1:5000" -headers = {'Content-Type': 'application/json'} - def post(currentsong): data = json.dumps(currentsong) r = requests.post(url+'/music/set', data=data, headers=headers) + if r.status_code != 200: + return r.status_code + else : + return 'Sent' - r = requests.get(url+'/music/display') - print(r.text) +url = "http://127.0.0.1:5000" +headers = {'Content-Type': 'application/json'} -currentsong = json.loads(str(get_current_song()).replace("'''", '"')) +def main(): + persistendId = '' + prevstatus = '' + while True: + print('getting data..') + currentsong = json.loads(str(get_current_song()).replace("'''", '"')) -if currentsong['status'] == 'playing': - (artwork_url, itunes_url, artist_url) = get_track_extras(currentsong['name'], currentsong['artist'], currentsong['album']) - currentsong['artwork_url'] = artwork_url - currentsong['itunes_url'] = itunes_url - currentsong['artist_url'] = artist_url - post(currentsong) -elif currentsong['status'] == 'not playing': - print('not playing') - post({'status' : 'not playing'}) -elif currentsong['status'] == 'not running': - print('not running') - post({'status' : 'not running'}) -else: - pass + if currentsong['status'] == 'playing': + if currentsong['persistent ID'] != persistendId: + persistendId = currentsong['persistent ID'] + (currentsong['artwork_url'], currentsong['itunes_url'], currentsong['artist_url']) = get_track_extras(currentsong['name'], currentsong['artist'], currentsong['album']) + print(post(currentsong)) + timets = float(currentsong['duration'].replace(",", "."))-float(currentsong['pPosition'].replace(",", ".")) + 3 + prevstatus = 'playing' + elif currentsong['status'] == 'not playing' and prevstatus != 'not playing': + prevstatus = 'not playing' + print('not playing') + print(post({'status' : 'not playing'})) + timets = 5*60 + elif currentsong['status'] == 'not running' and prevstatus != 'not running': + prevstatus = 'not running' + print('not running') + print(post({'status' : 'not running'})) + timets = 5*60 + else: + timets = 5*60 -# def main(): -# while True: -# current_song = get_current_song() -# if current_song: -# print("Currently listening to:", current_song) -# else: -# print("No music is playing.") -# time.sleep(5) # Check every 5 seconds + time.sleep(timets) -# if __name__ == "__main__": -# main() +if __name__ == "__main__": + main() \ No newline at end of file