#!/usr/bin/env python #Copyright (C) 2005-2006 Scott Shawcroft # Jason Kivlighn # #This program is free software; you can redistribute it and/or #modify it under the terms of the GNU General Public License #as published by the Free Software Foundation; either version 2 #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 General Public License for more details. # #You should have received a copy of the GNU General Public License #along with this program; if not, write to the Free Software #Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. def load_m3u( filename ): try: handle = file(filename, 'r') except: print "Unable to open",filename,"for reading" return playlist = [] counter = 0 for line in handle: if line == "#EXTM3U\n": continue if counter == 0: info = line.split(',') else: filename = line.strip('\n ') print "found file:",filename #TODO: return the file length/title info which is a part of m3u playlist.append((0,filename)) counter = not counter return playlist def save_m3u( filename, playlist ): try: handle = file(filename, 'w') except: print "Unable to open",filename,"for writing" return handle.write('#EXTM3U\n') for filename in playlist: handle.write("#EXTINF:0,"+filename+'\n') handle.write(filename+'\n')