-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwmp.py
79 lines (68 loc) · 2.32 KB
/
wmp.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import win32file
import win32con
from xml.dom import minidom
global now_playing_xmldoc
def init():
global now_playing_xmldoc
ACTIONS = {
1 : "Created",
2 : "Deleted",
3 : "Updated",
4 : "Renamed from something",
5 : "Renamed to something"
}
# Thanks to Claudio Grondi for the correct set of numbers
FILE_LIST_DIRECTORY = 0x0001
path_to_watch = "D:\\"
hDir = win32file.CreateFile (
path_to_watch,
FILE_LIST_DIRECTORY,
win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE | win32con.FILE_SHARE_DELETE,
None,
win32con.OPEN_EXISTING,
win32con.FILE_FLAG_BACKUP_SEMANTICS,
None
)
#
# ReadDirectoryChangesW takes a previously-created
# handle to a directory, a buffer size for results,
# a flag to indicate whether to watch subtrees and
# a filter of what changes to notify.
#
# NB Tim Juchcinski reports that he needed to up
# the buffer size to be sure of picking up all
# events when a large number of files were
# deleted at once.
#
results = win32file.ReadDirectoryChangesW (
hDir,
1024,
False,
win32con.FILE_NOTIFY_CHANGE_LAST_WRITE,
None,
None
)
for action, file in results:
full_filename = os.path.join (path_to_watch, file)
if(file == "now_playing_track.xml"):
now_playing_xmldoc = minidom.parse(full_filename)
def get_title():
title = now_playing_xmldoc.getElementsByTagName('title')[0].childNodes[0].data
return title
def get_artist():
artist = ''
if(len(now_playing_xmldoc.getElementsByTagName('artist')[0].childNodes) > 0):
artist = now_playing_xmldoc.getElementsByTagName('artist')[0].childNodes[0].data
return artist
def get_album():
album = ''
if(len(now_playing_xmldoc.getElementsByTagName('album')[0].childNodes) > 0):
album = now_playing_xmldoc.getElementsByTagName('album')[0].childNodes[0].data
return album
def get_player_state():
player_state = now_playing_xmldoc.getElementsByTagName('player_state')[0].childNodes[0].data
return player_state
def get_track_duration():
track_duration = now_playing_xmldoc.getElementsByTagName('duration')[0].childNodes[0].data
return track_duration