1 # -*- coding: utf-8 -*-
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.
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.
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/>.
18 # ============================================================================
19 # Project Name : PC Remote
20 # Author : Jonatas Isvi
21 # Email : jonatas.nona@gmail.com
26 # Description : Playlist
27 # ============================================================================
35 make the interpreter and manipulation
36 of the player playlist, creates a composite
37 with any player class.
40 # some importants variables
41 # analyze if file is a playlist
42 def __init__(self, file):
43 if self.isPlaylist(file):
45 self.songs = self.load()
49 raise("Argument is not a playlist file")
52 def isPlaylist(self, file):
58 # make a list of dicts songs
60 self.songs = plistparser._request(self.file)
63 # get the length of the current playlist
65 return len(self.songs)
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]['title'] == 'Unknown Title':
71 self.songs[self.currentSong]['title'] = title
72 if self.songs[self.currentSong]['artist'] == 'Unknown Artist':
73 self.songs[self.currentSong]['artist'] = artist
74 self.songs[self.currentSong]['path'] = path
75 self.songs[self.currentSong]['extension'] = ext
76 print self.songs[self.currentSong]
79 # show the current song
80 def show_playing_now(self):
81 return ('TITLE: %s' % self.songs[self.currentSong]['title'], \
82 'ARTIST: %s' % self.songs[self.currentSong]['artist'],\
83 'TRACK: %s' % self.songs[self.currentSong]['track']
86 # get the current song filename if index is None
87 def song_filename(self, index=None):
89 return self.songs[self.currentSong]['title'] +" - "+\
90 self.songs[self.currentSong]['artist'] + \
91 self.songs[self.currentSong]['extension']
94 return self.songs[index]['title'] +" - "+\
95 self.songs[index]['artist'] + \
96 self.songs[index]['extension']
98 # get thr current song filesize if index is None
99 def song_size(self, index=None):
101 return int(self.songs[self.currentSong]['filesize'])
103 return int(self.songs[index]['filesize'])
105 # show all songs of the playlist
107 for i in range(self.length()):
108 print self.songs[i]['track'], " - ", \
109 self.songs[i]['title'], " | ", \
110 self.songs[i]['artist'], \
113 # fix some problems of musics tags
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'
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):
129 props['track'] = self.songs[self.currentSong]['track']
131 props['title'] = self.songs[self.currentSong]['title']
133 props['artist'] = self.songs[self.currentSong]['artist']
135 props['ext'] = self.songs[self.currentSong]['extension']
137 props['filesize'] = self.songs[self.currentSong]['filesize']
139 props['duration'] = self.songs[self.currentSong]['duration']
141 props['path'] = self.songs[self.currentSong]['path']
146 props['track'] = self.songs[index]['track']
148 props['title'] = self.songs[index]['title']
150 props['artist'] = self.songs[index]['artist']
152 props['ext'] = self.songs[index]['extension']
154 props['filesize'] = self.songs[index]['filesize']
156 props['duration'] = self.songs[index]['duration']
158 props['path'] = self.songs[index]['path']