# -*- coding: utf-8 -*- # **************************************************************************** # Copyright (c) 2008 INdT/Fucapi. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program 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 Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . # # ============================================================================ # Project Name : PC Remote # Author : Jonatas Isvi # Email : jonatas.nona@gmail.com # Reviewer : # Email : # Version : 1.0 # Package : players # Description : Playlist # ============================================================================ import plistparser import pydcop class Playlist(): """ Playlist make the interpreter and manipulation of the player playlist, creates a composite with any player class. """ # some importants variables # analyze if file is a playlist def __init__(self, file): if self.isPlaylist(file): self.file = file self.songs = self.load() self.currentSong = 0 self.fix() else: raise("Argument is not a playlist file") # analyzes the file def isPlaylist(self, file): if not file: return False else: return True # make a list of dicts songs def load(self): self.songs = plistparser._request(self.file) return self.songs # get the length of the current playlist def length(self): return len(self.songs) # update the current song in songs list and return a song dict def update(self, track, title, artist, path, ext): self.currentSong = track if self.songs[self.currentSong - 1]['title'] == 'Unknown Title': self.songs[self.currentSong - 1]['title'] = title if self.songs[self.currentSong - 1]['artist'] == 'Unknown Artist': self.songs[self.currentSong - 1]['artist'] = artist self.songs[self.currentSong - 1]['path'] = path self.songs[self.currentSong - 1]['extension'] = ext print self.songs[self.currentSong - 1] # show the current song def show_playing_now(self): return ('TITLE: %s' % self.songs[self.currentSong - 1]['title'], \ 'ARTIST: %s' % self.songs[self.currentSong - 1]['artist'],\ 'TRACK: %s' % self.songs[self.currentSong - 1]['track'] ) # get the current song filename if index is None def song_filename(self, index=None): if index == None: return self.songs[self.currentSong-1]['title'] +" - "+\ self.songs[self.currentSong-1]['artist'] + \ self.songs[self.currentSong-1]['extension'] else: return self.songs[index-1]['title'] +" - "+\ self.songs[index-1]['artist'] + \ self.songs[index-1]['extension'] # get thr current song filesize if index is None def song_size(self, index=None): if index == None: return int(self.songs[self.currentSong-1]['filesize']) else: return int(self.songs[index-1]['filesize']) # show all songs of the playlist def show(self): for i in range(self.length()): print self.songs[i]['track'], " - ", \ self.songs[i]['title'], " | ", \ self.songs[i]['artist'], \ "\n" # fix some problems of musics tags def fix(self): for i in range(self.length()): if self.songs[i]['title'] == None: self.songs[i]['title'] = 'Unknown Title' elif self.songs[i]['artist'] == None: self.songs[i]['artist'] = 'Unknown Artist' # get the porperties of any song of ther playlist def song_properties(self, index=None, track=False, title=False,\ artist=False, ext=False, filesize=False, \ duration=False, path=False): props = {} if index == None: if track: props['track'] = self.songs[self.currentSong-1]['track'] if title: props['title'] = self.songs[self.currentSong-1]['title'] if artist: props['artist'] = self.songs[self.currentSong-1]['artist'] if ext: props['ext'] = self.songs[self.currentSong-1]['extension'] if filesize: props['filesize'] = self.songs[self.currentSong-1]['filesize'] if duration: props['duration'] = self.songs[self.currentSong-1]['duration'] if path: props['path'] = self.songs[self.currentSong-1]['path'] return props else: if track: props['track'] = self.songs[index-1]['track'] if title: props['title'] = self.songs[index-1]['title'] if artist: props['artist'] = self.songs[index-1]['artist'] if ext: props['ext'] = self.songs[index-1]['extension'] if filesize: props['filesize'] = self.songs[index-1]['filesize'] if duration: props['duration'] = self.songs[index-1]['duration'] if path: props['path'] = self.songs[index-1]['path'] return props