1 /* m3u.c
2 * Copyright (C) 2005 Sylvain Cresto <scresto@gmail.com>
3 *
4 * This file is part of graveman!
5 *
6 * graveman! is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or
9 * (at your option) any later version.
10 *
11 * graveman! is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with program; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19 * MA 02111-1307, USA.
20 *
21 * URL: http://www.nongnu.org/graveman/
22 *
23 */
24
25 #include "graveman.h"
26
27 #define EXT_M3U "#EXTM3U"
28 #define EXT_INF "#EXTINF;"
29 #define HTTP "http://"
30
31 /* import d'un fichier */
m3u_import(gchar * Afilename,Tgrave * Ag,gboolean Anew,GError ** Aerror)32 gboolean m3u_import(gchar *Afilename, Tgrave *Ag, gboolean Anew, GError **Aerror)
33 {
34 FILE *Lfic;
35 gchar *s;
36 gchar Lbuf[_BUF_SIZE];
37 gchar Ltmp[MAXPATHLEN];
38 gchar *Lrepertoire;
39 GtkTreeModel *Ltreemodel = gtk_tree_view_get_model(GTK_TREE_VIEW(sc_grave_get_widget(Ag, "LISTEAUDIO")));
40
41 if (!(Lfic = fopen(Afilename, "r"))) {
42 s = g_strdup_printf(_("Cannot import %s: %s"), Afilename, g_strerror(errno));
43 g_set_error(Aerror, G_FILE_ERROR, g_file_error_from_errno(errno), s, g_strerror(errno));
44 g_free(s);
45 return FALSE;
46 }
47
48 if (Anew) clear_list_audio(Ag);
49
50 Lrepertoire = g_path_get_dirname(Afilename);
51
52 while (fgets(Lbuf, _BUF_SIZE-1, Lfic)) {
53 Lbuf[_BUF_SIZE-1] = 0;
54
55 sc_chomp(Lbuf);
56
57 if (*Lbuf == 0) continue;
58 if (*Lbuf == '#') {
59 /* commentaire */
60 continue;
61 } else {
62 /* fichier chemin local ou non */
63 if (!strncmp(Lbuf, HTTP, strlen(HTTP)))
64 continue; /* on ignore les http pour le moment .. */
65
66 if (strchr(Lbuf, '/')) {
67 g_strlcpy(Ltmp, Lbuf, MAXPATHLEN-1);
68 } else {
69 g_snprintf(Ltmp, MAXPATHLEN-1, "%s/%s", Lrepertoire, Lbuf);
70 }
71 if (g_file_test(Lbuf, G_FILE_TEST_EXISTS)) {
72 _add_a_piste(Lbuf, GTK_LIST_STORE(Ltreemodel), Ag);
73 }
74 }
75 }
76
77 fclose(Lfic);
78
79 g_free(Lrepertoire);
80
81 return TRUE;
82 }
83
84 /*
85 * vim:et:ts=8:sts=2:sw=2
86 */
87