Mercurial > audlegacy-plugins
annotate src/pls/pls.c @ 2057:cf4fa45ffd80
playlist API vtabling
| author | William Pitcock <nenolod@atheme.org> |
|---|---|
| date | Sat, 13 Oct 2007 23:09:40 -0500 |
| parents | 059bd21a0c80 |
| children | 70b1f1fc4804 |
| rev | line source |
|---|---|
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
1 /* |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
2 * Audacious: A cross-platform multimedia player |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
3 * Copyright (c) 2006 William Pitcock, Tony Vroon, George Averill, |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
4 * Giacomo Lozito, Derek Pomery and Yoshiki Yazawa. |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
5 * |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
6 * This program is free software; you can redistribute it and/or modify |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
8 * the Free Software Foundation; either version 2 of the License, or |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
9 * (at your option) any later version. |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
10 * |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
11 * This program is distributed in the hope that it will be useful, |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
14 * GNU General Public License for more details. |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
15 * |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
16 * You should have received a copy of the GNU General Public License |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
17 * along with this program; if not, write to the Free Software |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
19 */ |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
20 |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
21 #include <glib.h> |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
22 #include <string.h> |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
23 #include <glib.h> |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
24 #include <glib/gprintf.h> |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
25 #include <stdlib.h> |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
26 #include <string.h> |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
27 #include <time.h> |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
28 |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
29 #include <unistd.h> |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
30 #include <sys/types.h> |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
31 #include <sys/stat.h> |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
32 #include <sys/errno.h> |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
33 |
|
1950
2ebeb7816c5e
Change from "" to <>-style includes. With thanks to ccr for the correct sed voodoo.
chainsaw@localhost
parents:
1675
diff
changeset
|
34 #include <audacious/main.h> |
|
2ebeb7816c5e
Change from "" to <>-style includes. With thanks to ccr for the correct sed voodoo.
chainsaw@localhost
parents:
1675
diff
changeset
|
35 #include <audacious/util.h> |
|
2ebeb7816c5e
Change from "" to <>-style includes. With thanks to ccr for the correct sed voodoo.
chainsaw@localhost
parents:
1675
diff
changeset
|
36 #include <audacious/playlist.h> |
|
1952
17a6441c71b6
Some missed #include "" to <> changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1950
diff
changeset
|
37 #include <audacious/playlist_container.h> |
|
1950
2ebeb7816c5e
Change from "" to <>-style includes. With thanks to ccr for the correct sed voodoo.
chainsaw@localhost
parents:
1675
diff
changeset
|
38 #include <audacious/plugin.h> |
|
2ebeb7816c5e
Change from "" to <>-style includes. With thanks to ccr for the correct sed voodoo.
chainsaw@localhost
parents:
1675
diff
changeset
|
39 #include <audacious/strings.h> |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
40 |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
41 static void |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
42 playlist_load_pls(const gchar * filename, gint pos) |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
43 { |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
44 guint i, count, added_count = 0; |
| 359 | 45 gchar line_key[10], title_key[10]; |
| 46 gchar *line, *title; | |
|
2057
cf4fa45ffd80
playlist API vtabling
William Pitcock <nenolod@atheme.org>
parents:
2053
diff
changeset
|
47 Playlist *playlist = aud_playlist_get_active(); |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
48 |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
49 g_return_if_fail(filename != NULL); |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
50 |
|
2050
2ffc6a69fcd1
string API calls -> vtable
William Pitcock <nenolod@atheme.org>
parents:
1978
diff
changeset
|
51 if (!aud_str_has_suffix_nocase(filename, ".pls")) |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
52 return; |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
53 |
| 654 | 54 INIFile *inifile = open_ini_file(filename); |
| 55 if (!(line = read_ini_string(inifile, "playlist", "NumberOfEntries"))) | |
| 56 { | |
| 57 close_ini_file(inifile); | |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
58 return; |
| 654 | 59 } |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
60 |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
61 count = atoi(line); |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
62 g_free(line); |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
63 |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
64 for (i = 1; i <= count; i++) { |
| 359 | 65 g_snprintf(line_key, sizeof(line_key), "File%d", i); |
| 654 | 66 if ((line = read_ini_string(inifile, "playlist", line_key))) |
| 67 { | |
|
1398
13dd4f9bd4b4
pls: Write filename paths to disk, not URIs. Convert filename paths in PLS files to valid URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
68 gchar *uri = g_filename_to_uri(line, NULL, NULL); |
|
13dd4f9bd4b4
pls: Write filename paths to disk, not URIs. Convert filename paths in PLS files to valid URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
69 |
|
13dd4f9bd4b4
pls: Write filename paths to disk, not URIs. Convert filename paths in PLS files to valid URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
70 if (uri) |
|
13dd4f9bd4b4
pls: Write filename paths to disk, not URIs. Convert filename paths in PLS files to valid URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
71 g_free(line); |
|
13dd4f9bd4b4
pls: Write filename paths to disk, not URIs. Convert filename paths in PLS files to valid URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
72 else |
|
13dd4f9bd4b4
pls: Write filename paths to disk, not URIs. Convert filename paths in PLS files to valid URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
73 uri = line; |
|
13dd4f9bd4b4
pls: Write filename paths to disk, not URIs. Convert filename paths in PLS files to valid URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
74 |
| 654 | 75 if (cfg.use_pl_metadata) |
| 76 { | |
| 77 g_snprintf(title_key, sizeof(title_key), "Title%d", i); | |
| 359 | 78 |
| 654 | 79 if ((title = read_ini_string(inifile, "playlist", title_key))) |
|
2057
cf4fa45ffd80
playlist API vtabling
William Pitcock <nenolod@atheme.org>
parents:
2053
diff
changeset
|
80 aud_playlist_load_ins_file(playlist, uri, filename, pos, title, -1); |
| 654 | 81 else |
|
2057
cf4fa45ffd80
playlist API vtabling
William Pitcock <nenolod@atheme.org>
parents:
2053
diff
changeset
|
82 aud_playlist_load_ins_file(playlist, uri, filename, pos, NULL, -1); |
| 654 | 83 } |
| 84 else | |
|
2057
cf4fa45ffd80
playlist API vtabling
William Pitcock <nenolod@atheme.org>
parents:
2053
diff
changeset
|
85 aud_playlist_load_ins_file(playlist, uri, filename, pos, NULL, -1); |
| 359 | 86 |
|
1398
13dd4f9bd4b4
pls: Write filename paths to disk, not URIs. Convert filename paths in PLS files to valid URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
87 added_count++; |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
88 |
|
1398
13dd4f9bd4b4
pls: Write filename paths to disk, not URIs. Convert filename paths in PLS files to valid URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
89 if (pos >= 0) |
|
13dd4f9bd4b4
pls: Write filename paths to disk, not URIs. Convert filename paths in PLS files to valid URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
90 pos++; |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
91 |
|
1398
13dd4f9bd4b4
pls: Write filename paths to disk, not URIs. Convert filename paths in PLS files to valid URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
92 g_free(uri); |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
93 } |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
94 } |
| 654 | 95 |
| 96 close_ini_file(inifile); | |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
97 } |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
98 |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
99 static void |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
100 playlist_save_pls(const gchar *filename, gint pos) |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
101 { |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
102 GList *node; |
| 1978 | 103 VFSFile *file = aud_vfs_fopen(filename, "wb"); |
|
2057
cf4fa45ffd80
playlist API vtabling
William Pitcock <nenolod@atheme.org>
parents:
2053
diff
changeset
|
104 Playlist *playlist = aud_playlist_get_active(); |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
105 |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
106 g_return_if_fail(file != NULL); |
|
384
a91923634161
[svn] - don't use deprecated function playlist_get().
nenolod
parents:
361
diff
changeset
|
107 g_return_if_fail(playlist != NULL); |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
108 |
| 1978 | 109 aud_vfs_fprintf(file, "[playlist]\n"); |
|
2057
cf4fa45ffd80
playlist API vtabling
William Pitcock <nenolod@atheme.org>
parents:
2053
diff
changeset
|
110 aud_vfs_fprintf(file, "NumberOfEntries=%d\n", aud_playlist_get_length(playlist)); |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
111 |
|
1675
ae9b0327b620
Fix plugins to conform with PLAYLIST_{UN}LOCK() change.
Matti Hamalainen <ccr@tnsp.org>
parents:
1398
diff
changeset
|
112 PLAYLIST_LOCK(playlist); |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
113 |
|
386
de15b9e09d2d
[svn] - updated m3u.c, xspf.c, pls.c to use the playlist->mutex and no more playlist_get
giacomo
parents:
384
diff
changeset
|
114 for (node = playlist->entries; node; node = g_list_next(node)) { |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
115 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); |
|
1398
13dd4f9bd4b4
pls: Write filename paths to disk, not URIs. Convert filename paths in PLS files to valid URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
116 gchar *fn; |
|
13dd4f9bd4b4
pls: Write filename paths to disk, not URIs. Convert filename paths in PLS files to valid URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
117 |
| 1978 | 118 if (aud_vfs_is_remote(entry->filename)) |
|
1398
13dd4f9bd4b4
pls: Write filename paths to disk, not URIs. Convert filename paths in PLS files to valid URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
119 fn = g_strdup(entry->filename); |
|
13dd4f9bd4b4
pls: Write filename paths to disk, not URIs. Convert filename paths in PLS files to valid URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
120 else |
|
13dd4f9bd4b4
pls: Write filename paths to disk, not URIs. Convert filename paths in PLS files to valid URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
121 fn = g_filename_from_uri(entry->filename, NULL, NULL); |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
122 |
| 1978 | 123 aud_vfs_fprintf(file, "File%d=%s\n", g_list_position(playlist->entries, node) + 1, |
|
1398
13dd4f9bd4b4
pls: Write filename paths to disk, not URIs. Convert filename paths in PLS files to valid URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
124 fn); |
|
13dd4f9bd4b4
pls: Write filename paths to disk, not URIs. Convert filename paths in PLS files to valid URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
125 |
|
13dd4f9bd4b4
pls: Write filename paths to disk, not URIs. Convert filename paths in PLS files to valid URIs.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
126 g_free(fn); |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
127 } |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
128 |
|
1675
ae9b0327b620
Fix plugins to conform with PLAYLIST_{UN}LOCK() change.
Matti Hamalainen <ccr@tnsp.org>
parents:
1398
diff
changeset
|
129 PLAYLIST_UNLOCK(playlist); |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
130 |
| 1978 | 131 aud_vfs_fclose(file); |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
132 } |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
133 |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
134 PlaylistContainer plc_pls = { |
| 654 | 135 .name = "Winamp .pls Playlist Format", |
| 136 .ext = "pls", | |
| 137 .plc_read = playlist_load_pls, | |
| 138 .plc_write = playlist_save_pls, | |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
139 }; |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
140 |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
141 static void init(void) |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
142 { |
|
2053
059bd21a0c80
PlaylistContainer API updates
William Pitcock <nenolod@atheme.org>
parents:
2050
diff
changeset
|
143 aud_playlist_container_register(&plc_pls); |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
144 } |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
145 |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
146 static void cleanup(void) |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
147 { |
|
2053
059bd21a0c80
PlaylistContainer API updates
William Pitcock <nenolod@atheme.org>
parents:
2050
diff
changeset
|
148 aud_playlist_container_unregister(&plc_pls); |
|
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
149 } |
|
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
150 |
|
1395
761e17b23e0c
added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents:
1190
diff
changeset
|
151 DECLARE_PLUGIN(pls, init, cleanup, NULL, NULL, NULL, NULL, NULL, NULL); |
