pcremote-client-n8x0 -> client sources
[remotepc] / pcremote-server-desktop / debian / pcremote-server / usr / share / pcremote-server / players / .svn / text-base / amarok.py.svn-base
1 # -*- coding: utf-8 -*-
2
3 #  ****************************************************************************
4 #  Copyright (c) 2008 INdT/Fucapi.
5 #  This program is free software: you can redistribute it and/or modify
6 #  it under the terms of the GNU Lesser General Public License as published by
7 #  the Free Software Foundation, either version 3 of the License, or
8 #  (at your option) any later version.
9 #
10 #  This program 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 Lesser General Public License for more details.
14 #
15 #  You should have received a copy of the GNU Lesser General Public License
16 #  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 #
18 #  ============================================================================
19 #  Project Name : PC Remote
20 #  Author       : Jonatas Isvi
21 #  Email        : jonatas.nona@gmail.com
22 #  Reviewer     :
23 #  Email        : 
24 #  Version      : 1.0
25 #  Packge       : players
26 #  Description  : Amarok Player
27 #  ============================================================================
28
29 import os
30 import commands
31 import random
32 from playlist import Playlist
33 import pydcop
34
35 # command line
36 def shell(command):
37     return commands.getoutput(command)
38
39 # starts the amarok player application
40 def start():
41     os.popen('amarok')
42
43 # close the amarok player application
44 def shutdown():
45     shell('dcop amarok player stop')
46     pid = shell('pidof amarokapp')
47     shell('kill -9 %s' % pid)
48
49 # verifies if the amarok is running 
50 def isRunning():
51     pid = shell('pidof amarokapp')
52     if pid > 0:
53         return True
54     else:
55         return False
56
57 class AmarokPlayer():
58
59     """ Amarok
60     Define all states and functions of amarok player.
61     This class will build to support PCRemote Player,
62     receiving messages from any devices with a bluetooth 
63     connection.
64     """
65         
66     # some importants variables 
67     def __init__(self):
68         self.amarok = pydcop.anyAppCalled("amarok")
69         self.playlist = Playlist(self.amarok.playlist.saveCurrentPlaylist())
70         self.isPlaying()
71
72     # refresh playlist, accessing the Playlist class instance
73     def refresh_playlist(self):
74         self.playlist = Playlist(self.amarok.playlist.saveCurrentPlaylist())
75         self.isPlaying()
76
77     # get all songs of playlist
78     def song_list(self):
79         self.playlist.show()
80
81     # show current song, acessing the Playlist class instance
82     def current_song(self):
83         self.isPlaying()
84
85     # verifies if this amarok app is running
86     def isRunning(self):
87         aux = pydcop.anyAppCalled("amarok")
88         if aux:
89             return aux
90         else:
91             return None
92
93     # verifies if this amarok app is playing and update the 
94     # Playlist with current song
95     def isPlaying(self):
96         if not self.amarok.player.isPlaying() == 'true':
97             self.playlist.update(self.amarok.playlist.getActiveIndex() + 1,\
98                                  self.amarok.player.title(),               \
99                                  self.amarok.player.artist(),              \
100                                  self.amarok.player.path(),                \
101                                  "." + self.amarok.player.type(),          \
102                                 )
103             return True
104         else:
105             return False        
106
107     # get the players name
108     def getName(self):
109         return "Amarok"
110
111     # send audio files to the N810 device
112     def audio_file_properties(self, index=None):
113         audiofile = (self.playlist.song_filename(index),\
114                      self.playlist.song_size(index))
115         return audiofile
116
117     # next button and sets current song
118     def next(self):
119         self.amarok.player.next()
120         self.playlist.update(self.amarok.playlist.getActiveIndex() + 1,\
121                              self.amarok.player.title(),               \
122                              self.amarok.player.artist(),              \
123                              self.amarok.player.path(),                \
124                              "." + self.amarok.player.type(),          \
125                              )
126         
127     # prev button and sets current song
128     def prev(self):
129         self.amarok.player.prev()               
130         self.playlist.update(self.amarok.playlist.getActiveIndex() + 1,\
131                              self.amarok.player.title(),               \
132                              self.amarok.player.artist(),              \
133                              self.amarok.player.path(),                \
134                              "." + self.amarok.player.type(),          \
135                              )
136         
137     # play button and sets current song
138     def play(self):
139         self.amarok.player.play()
140         self.playlist.update(self.amarok.playlist.getActiveIndex() + 1,\
141                              self.amarok.player.title(),               \
142                              self.amarok.player.artist(),              \
143                              self.amarok.player.path(),                \
144                              "." + self.amarok.player.type(),          \
145                              )
146         
147     # play button with index song and sets current song
148     def play_track(self, index):
149         self.amarok.playlist.playByIndex(index-1)       
150         self.playlist.update(index,                          \
151                              self.amarok.player.title(),     \
152                              self.amarok.player.artist(),    \
153                              self.amarok.player.path(),      \
154                              "." + self.amarok.player.type(),\
155                              )
156
157     # random play songs
158     def play_random(self):
159         index = random.randint(0, self.playlist.length() - 1)
160         self.amarok.playlist.playByIndex(index)
161         self.playlist.update(index+1,                        \
162                              self.amarok.player.title(),     \
163                              self.amarok.player.artist(),    \
164                              self.amarok.player.path(),      \
165                              "." + self.amarok.player.type(),\
166                              )
167                 
168     # pause button
169     def pause(self):
170         self.amarok.player.pause()
171
172     # mute button
173     def mute(self):
174         self.amarok.player.mute()
175
176     # stop button
177     def stop(self):
178         self.amarok.player.stop()
179
180     # get the current volume value
181     def get_volume(self):
182         return self.amarok.player.getVolume()
183
184     # set up volume
185     def volume_up(self, increase=1):
186         if (self.get_volume() + increase) <= 100:
187             up = self.get_volume() + increase
188             self.amarok.player.setVolume(up)
189         else:
190             print "erro!"
191
192     # set down volume
193     def volume_down(self, decrement=1):
194         if (self.get_volume() - decrement) >= 0:
195             down = self.get_volume() - decrement
196             self.amarok.player.setVolume(down)
197         else:
198             print "erro!"
199         
200     # set seek value 
201     def seek(self, value):
202         self.amarok.player.seek(value)