-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendMusicWindows.py
More file actions
36 lines (29 loc) · 1.39 KB
/
Copy pathsendMusicWindows.py
File metadata and controls
36 lines (29 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import asyncio, requests, time
from winrt.windows.media.control import \
GlobalSystemMediaTransportControlsSessionManager as MediaManager
async def get_media_info():
sessions = await MediaManager.request_async()
current_session = sessions.get_current_session()
if current_session: # there needs to be a media session running
info = await current_session.try_get_media_properties_async()
# song_attr[0] != '_' ignores system attributes
info_dict = {song_attr: info.__getattribute__(song_attr) for song_attr in dir(info) if song_attr[0] != '_'}
# converts winrt vector to list
info_dict['genres'] = list(info_dict['genres'])
return info_dict
if __name__ == '__main__':
while True:
current_media_info = asyncio.run(get_media_info())
text = str(current_media_info['title'] + ' - ' + current_media_info['artist'])
try:
# This request is for sending data to an Awtrix compatible clock.
# For more info see https://github.com/Blueforcer/awtrix-light
requests.post('http://IP.OF.YOUR.CLOCK/api/custom?name=Music', json={
"text": text,
"rainbow": False,
"duration": 10,
"icon": "EQ"
})
except requests.exceptions.RequestException as e:
print(e)
time.sleep(10)