~ubuntu-branches/ubuntu/oneiric/emesene/oneiric

« back to all changes in this revision

Viewing changes to plugins_base/currentSong/MediaPlayerClassic.py

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2010-07-18 04:13:52 UTC
  • mfrom: (5.2.8 sid)
  • Revision ID: james.westby@ubuntu.com-20100718041352-dsrfuyszjm7pnd3i
Tags: 1.6.3-1
* debian/control: add myself to Uploaders field.
* New upstream release.
* Add 21_svn2451_fix_avatar patch to fix avatars storage.
* Bump Standards-Version to 3.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
#   This file is part of emesene.
 
4
#
 
5
#    Emesene is free software; you can redistribute it and/or modify
 
6
#    it under the terms of the GNU General Public License as published by
 
7
#    the Free Software Foundation; either version 2 of the License, or
 
8
#    (at your option) any later version.
 
9
#
 
10
#    emesene is distributed in the hope that it will be useful,
 
11
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
#    GNU General Public License for more details.
 
14
#
 
15
#    You should have received a copy of the GNU General Public License
 
16
#    along with emesene; if not, write to the Free Software
 
17
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 
 
19
 
 
20
import os
 
21
import ctypes
 
22
user = ctypes.windll.user32
 
23
 
 
24
import CurrentSong
 
25
from emesenelib import *
 
26
 
 
27
class MediaPlayerClassic( CurrentSong.CurrentSong ):
 
28
 
 
29
    def __init__( self ):
 
30
        CurrentSong.CurrentSong.__init__( self )
 
31
        self.mplayerwindow = None
 
32
        self.isRunning()
 
33
        self.currentSong = ''
 
34
        self.template = "MPlayerClassic\\0Music\\01\\0{0}\\0%s\\0\\0"
 
35
        
 
36
    def isPlaying( self ):
 
37
        if self.mplayerwindow is not None:
 
38
            st = ctypes.create_unicode_buffer(100)
 
39
            user.GetWindowTextW(self.mplayerwindow, st, 100)
 
40
            return st.value != "Media Player Classic"
 
41
        else:
 
42
            return False
 
43
 
 
44
    def isRunning( self ):
 
45
        winampClassName = ctypes.c_wchar_p('MediaPlayerClassicW')
 
46
        self.mplayerwindow = user.FindWindowW(winampClassName, None)
 
47
        return self.mplayerwindow != 0
 
48
 
 
49
    def getCurrentSong( self ):
 
50
        return self.currentSong
 
51
 
 
52
    def check( self ):
 
53
        if not self.isRunning():
 
54
            self.currentSong = ""
 
55
            return True
 
56
        if self.isPlaying():
 
57
            st = ctypes.create_unicode_buffer(100)
 
58
            user.GetWindowTextW(self.mplayerwindow, st, 100)
 
59
            string = st.value.split(" - Media Player Classic")[0]
 
60
            newCurrentSong = self.template % string
 
61
        else:
 
62
            newCurrentSong = ''
 
63
 
 
64
        if self.currentSong != newCurrentSong:
 
65
            self.currentSong = newCurrentSong
 
66
            return True
 
67
            
 
68
        return False
 
69
    
 
70
    def getStatus( self ):
 
71
        '''
 
72
        check if everything is OK to start the plugin
 
73
        return a tuple whith a boolean and a message
 
74
        if OK -> ( True , 'some message' )
 
75
        else -> ( False , 'error message' )
 
76
        '''
 
77
        
 
78
        if os.name != 'nt':
 
79
            return ( False, 'This plugin only works on windows systems' )
 
80
        
 
81
        return ( True, 'Ok' )