forked from emesene/emesene-supported-plugins
/
base_windows_handler.py
85 lines (73 loc) · 3.1 KB
/
base_windows_handler.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
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
# This file is part of emesene.
#
# Emesene is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# emesene is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with emesene; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import os
import ctypes
user = ctypes.windll.user32
import songretriever
class WindowsPlayerHandler( songretriever.BaseMusicHandler ):
'''This is the base for most Windows players'''
'''It takes the title of the window as shown by windows's window manager and strip
the title from there, too hacky, but the only way for most players'''
NAME = 'WindowsHandler'
DESCRIPTION = 'Handler for basic windows music player (NOT! Windows Media Player)'
AUTHOR = 'Ariel Juodziukynas'
WEBSITE = 'www.emesene.org'
def __init__(self, main_window = None):
songretriever.BaseMusicHandler.__init__( self, main_window )
self.window = None
self.windowClass = None
self.currentSong = None
self.isRunning()
self.shellUser = user
def splitStr(self, string):
'''Split the title, remove the unneeded part of the string and leave only the song'''
raise NotImplementedError("Not implemented")
def isPlaying( self ):
'''Some windows accept commands, other only change it's title, implement that
according to the player'''
raise NotImplementedError("Not implemented")
def getWindowTitle( self ):
'''Returns the title of the window'''
if self.window is not None:
st = ctypes.create_unicode_buffer(100)
user.GetWindowTextW(self.window, st, 100)
return st.value
else:
return ""
def isRunning( self ):
'''Check for a window with the specified title'''
try:
winampClassName = ctypes.c_wchar_p(self.windowClass)
self.window = user.FindWindowW(winampClassName, None)
return self.window != 0
except:
return False
def get_current_song(self):
'''returns the current song or None if no song is playing'''
if not self.isRunning():
self.currentSong = None
return self.currentSong
if self.isPlaying():
st = ctypes.create_unicode_buffer(100)
user.GetWindowTextW(self.window, st, 100)
newCurrentSong = self.splitStr(st.value)
else:
newCurrentSong = None
if self.currentSong != newCurrentSong:
self.currentSong = newCurrentSong
return self.currentSong
return self.currentSong