pcremote-client-n8x0 -> client sources
[remotepc] / pcremote-server-desktop-60 / debian / pcremote-server / usr / share / pcremote-server / players / .svn / text-base / playlist.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 #  Package      : players
26 #  Description  : Playlist
27 #  ============================================================================
28
29 import plistparser
30 import pydcop
31
32 class Playlist():
33
34     """ Playlist
35     make the interpreter and manipulation
36     of the player playlist, creates a composite
37     with any player class. 
38     """
39
40     # some importants variables
41     # analyze if file is a playlist
42     def __init__(self, file):
43         if self.isPlaylist(file):
44             self.file = file
45             self.songs = self.load()
46             self.currentSong = 0
47             self.fix()
48         else:
49             raise("Argument is not a playlist file")
50
51     # analyzes the file
52     def isPlaylist(self, file):
53         if not file:
54             return False
55         else:
56             return True
57
58     # make a list of dicts songs
59     def load(self):
60         self.songs = plistparser._request(self.file)    
61         return self.songs
62
63     # get the length of the current playlist
64     def length(self):
65         return len(self.songs)
66
67     # update the current song in songs list and return a song dict
68     def update(self, track, title, artist, path, ext):
69         self.currentSong = track
70         if self.songs[self.currentSong - 1]['title'] == 'Unknown Title':
71             self.songs[self.currentSong - 1]['title'] = title
72         if self.songs[self.currentSong - 1]['artist'] == 'Unknown Artist':
73             self.songs[self.currentSong - 1]['artist'] = artist
74         self.songs[self.currentSong - 1]['path'] = path
75         self.songs[self.currentSong - 1]['extension'] = ext
76         print self.songs[self.currentSong - 1]
77
78
79     # show the current song
80     def show_playing_now(self):
81         return ('TITLE: %s' % self.songs[self.currentSong - 1]['title'],  \
82                 'ARTIST: %s' % self.songs[self.currentSong - 1]['artist'],\
83                 'TRACK: %s' % self.songs[self.currentSong - 1]['track']
84                 )
85
86     # get the current song filename if index is None
87     def song_filename(self, index=None):
88         if index == None:
89             return self.songs[self.currentSong-1]['title'] +" - "+\
90                    self.songs[self.currentSong-1]['artist'] +     \
91                    self.songs[self.currentSong-1]['extension']
92
93         else:
94             return self.songs[index-1]['title'] +" - "+\
95                    self.songs[index-1]['artist'] +     \
96                    self.songs[index-1]['extension']
97         
98     # get thr current song filesize if index is None
99     def song_size(self, index=None):
100         if index == None:
101             return int(self.songs[self.currentSong-1]['filesize'])
102         else:
103             return int(self.songs[index-1]['filesize'])
104
105     # show all songs of the playlist
106     def show(self):
107         for i in range(self.length()):
108             print self.songs[i]['track'], " - ", \
109                   self.songs[i]['title'], " | ", \
110                   self.songs[i]['artist'],       \
111                   "\n"
112
113     # fix some problems of musics tags
114     def fix(self):
115         for i in range(self.length()):
116             if self.songs[i]['title'] == None:
117                self.songs[i]['title'] = 'Unknown Title'
118             elif self.songs[i]['artist'] == None:
119                 self.songs[i]['artist'] = 'Unknown Artist'
120                 
121
122     # get the porperties of any song of ther playlist   
123     def song_properties(self, index=None, track=False, title=False,\
124                         artist=False, ext=False, filesize=False, \
125                         duration=False, path=False):
126         props = {}
127         if index == None:
128             if track:
129                 props['track'] = self.songs[self.currentSong-1]['track']
130             if title:
131                 props['title'] = self.songs[self.currentSong-1]['title']
132             if artist:
133                 props['artist'] = self.songs[self.currentSong-1]['artist']
134             if ext:
135                 props['ext'] = self.songs[self.currentSong-1]['extension']
136             if filesize:
137                 props['filesize'] = self.songs[self.currentSong-1]['filesize']
138             if duration:
139                 props['duration'] = self.songs[self.currentSong-1]['duration']
140             if path:
141                 props['path'] = self.songs[self.currentSong-1]['path']
142                         
143             return props
144         else:
145             if track:
146                 props['track'] = self.songs[index-1]['track']
147             if title:
148                 props['title'] = self.songs[index-1]['title']
149             if artist:
150                 props['artist'] = self.songs[index-1]['artist']
151             if ext:
152                 props['ext'] = self.songs[index-1]['extension']
153             if filesize:
154                 props['filesize'] = self.songs[index-1]['filesize']
155             if duration:
156                 props['duration'] = self.songs[index-1]['duration']
157             if path:
158                 props['path'] = self.songs[index-1]['path']
159
160             return props
161