Plugins: m3u.py

File m3u.py, 1.5 kB (added by i_am_very_pissed_off@hotmail.com, 1 year ago)

just a little plugin to export selected files as an m3u list. Based on HTML export plugin

Line 
1 # Copyright 2005 Eduardo Gonzalez
2 # Modified 2006 Liam Brown from Export to HTML
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License version 2 as
5 # published by the Free Software Foundation
6 #
7 # $Id$
8
9 import os
10 import re
11 import gtk
12 import config
13
14 from util import tag, escape
15 from plugins.songsmenu import SongsMenuPlugin
16
17 class ExportToHTML(SongsMenuPlugin):
18     PLUGIN_ID = "Export to M3U"
19     PLUGIN_NAME = _("Export to M3U")
20     PLUGIN_DESC = _("Export the selected song list to an M3U playlist")
21     PLUGIN_ICON = gtk.STOCK_CONVERT
22     PLUGIN_VERSION = "0.02"
23
24     def plugin_songs(self, songs):
25         if not songs: return
26
27         chooser = gtk.FileChooserDialog(
28             title="Export to M3U",
29             action=gtk.FILE_CHOOSER_ACTION_SAVE,
30             buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
31                      gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
32         chooser.set_default_response(gtk.RESPONSE_ACCEPT)
33         resp = chooser.run()
34         if resp != gtk.RESPONSE_ACCEPT:
35             chooser.destroy()
36             return
37
38         fn = chooser.get_filename()
39         chooser.destroy()
40
41         songs_s = ''
42         s = '#EXTM3U\n'
43         for song in songs:
44             s += '#EXTINF:%s,'% (song.comma("~#length"))
45             s += '%s\n' % (song.comma("~title~version"))
46             s += '%s\n' % (song.comma("~filename").encode('utf-8'))
47         songs_s += s
48
49         f = open(fn, 'wU')
50         f.write(( '%s'% (songs_s)))
51         f.close()