mirror of
https://github.com/NohamR/AM-Exporter.git
synced 2026-05-25 04:07:11 +00:00
server + music player
This commit is contained in:
50
html.html
Normal file
50
html.html
Normal file
@@ -0,0 +1,50 @@
|
||||
<html lang="pt-br">
|
||||
|
||||
<head>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<title>Music Player</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="boxes">
|
||||
<div id="player" class="player horizontal">
|
||||
<div class="wrapper">
|
||||
|
||||
<div class="info-wrapper">
|
||||
|
||||
<img src="https://is1-ssl.mzstatic.com/image/thumb/Music116/v4/94/05/6d/94056dc6-ba11-0c4f-fb1d-ee586224445c/4a754a5f-724e-4400-a78f-06747b604d47.jpg/100x100bb.jpg"
|
||||
alt="LogoMusicImage">
|
||||
|
||||
<div class="info">
|
||||
<h1>Tired of a Bewildered Heart</h1>
|
||||
<p>Elijah Lee & Casiio</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="track-time">
|
||||
<div class="track"></div>
|
||||
<div class="time">
|
||||
<div class="total-time">2:12</div>
|
||||
<div class="last-time">00:50</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -13,4 +13,4 @@ def display_content():
|
||||
return jsonify(cache)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
app.run(debug=True)
|
||||
139
style.css
Normal file
139
style.css
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -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'''}"
|
||||
|
||||
69
test.py
69
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()
|
||||
Reference in New Issue
Block a user