annotate playtreeparser.c @ 6524:05cd2cf758e4

if09 support
author alex
date Sun, 23 Jun 2002 15:03:54 +0000
parents 0f5f626e5151
children dc61b6b159e4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
1
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4043
diff changeset
2 #include "config.h"
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
3 #include <stdlib.h>
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
4 #include <stdio.h>
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
5 #include <string.h>
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4043
diff changeset
6 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
7 #include <assert.h>
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4043
diff changeset
8 #endif
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
9 #include <errno.h>
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
10 #include <sys/types.h>
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
11 #include <sys/stat.h>
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
12 #include <fcntl.h>
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
13 #include <unistd.h>
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
14 #include "playtree.h"
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
15 #include "playtreeparser.h"
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
16 #include "libmpdemux/stream.h"
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
17 #include "mp_msg.h"
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
18
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
19 extern play_tree_t*
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
20 asx_parser_build_tree(char* buffer, int ref);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
21
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
22 #define BUF_STEP 1024
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
23
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
24 #define WHITES " \n\r\t"
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
25
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
26 static void
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
27 strstrip(char* str) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
28 char* i;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
29
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
30 for(i = str ; i[0] != '\0' && strchr(WHITES,i[0]) != NULL; i++)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
31 /* NOTHING */;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
32 if(i[0] != '\0') {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
33 memmove(str,i,strlen(i));
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
34 for(i = str + strlen(str) ; strchr(WHITES,i[0]) != NULL; i--)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
35 /* NOTHING */;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
36 i[1] = '\0';
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
37 } else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
38 str[0] = '\0';
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
39 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
40
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
41 static char*
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
42 play_tree_parser_get_line(play_tree_parser_t* p) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
43 char *end,*line_end;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
44 int r,resize = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
45
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
46 if(p->buffer == NULL) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
47 p->buffer = (char*)malloc(BUF_STEP);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
48 p->buffer_size = BUF_STEP;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
49 p->iter = p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
50 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
51
5802
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
52 if(p->stream->eof && (p->buffer_end == 0 || p->iter[0] == '\0'))
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
53 return NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
54
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
55 while(1) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
56
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
57 if(resize) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
58 r = p->iter - p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
59 p->buffer = (char*)realloc(p->buffer,p->buffer_size+BUF_STEP);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
60 p->iter = p->buffer + r;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
61 p->buffer_size += BUF_STEP;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
62 resize = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
63 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
64
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
65 if(p->buffer_size - p->buffer_end > 1 && ! p->stream->eof) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
66 r = stream_read(p->stream,p->buffer + p->buffer_end,p->buffer_size - p->buffer_end - 1);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
67 if(r > 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
68 p->buffer_end += r;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
69 p->buffer[p->buffer_end] = '\0';
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
70 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
71 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
72
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
73 end = strchr(p->iter,'\n');
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
74 if(!end) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
75 if(p->stream->eof) {
4857
f3f94fb55398 Small bugfix with getting playlist last line.
albeu
parents: 4782
diff changeset
76 end = p->buffer + p->buffer_end;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
77 break;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
78 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
79 resize = 1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
80 continue;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
81 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
82 break;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
83 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
84
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
85 line_end = ((*(end-1)) == '\r') ? end-1 : end;
5802
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
86 if(line_end - p->iter >= 0)
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
87 p->line = (char*)realloc(p->line,line_end - p->iter+1);
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
88 else
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
89 return NULL;
5802
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
90 if(line_end - p->iter > 0)
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
91 strncpy(p->line,p->iter,line_end - p->iter);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
92 p->line[line_end - p->iter] = '\0';
5802
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
93 if(end[0] != '\0')
4857
f3f94fb55398 Small bugfix with getting playlist last line.
albeu
parents: 4782
diff changeset
94 end++;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
95
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
96 if(!p->keep) {
4857
f3f94fb55398 Small bugfix with getting playlist last line.
albeu
parents: 4782
diff changeset
97 if(end[0] != '\0') {
5788
8bd1c1e319fb Fix a bug produced when line are terminated with \r\n and not a single
albeu
parents: 4857
diff changeset
98 p->buffer_end -= end-p->iter;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
99 memmove(p->buffer,end,p->buffer_end);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
100 } else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
101 p->buffer_end = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
102 p->iter = p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
103 } else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
104 p->iter = end;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
105
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
106 return p->line;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
107 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
108
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
109 static void
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
110 play_tree_parser_reset(play_tree_parser_t* p) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
111 p->iter = p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
112 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
113
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
114 static void
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
115 play_tree_parser_stop_keeping(play_tree_parser_t* p) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
116 p->keep = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
117 if(p->iter && p->iter != p->buffer) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
118 p->buffer_end -= p->iter -p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
119 if(p->buffer_end)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
120 memmove(p->buffer,p->iter,p->buffer_end);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
121 p->iter = p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
122 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
123 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
124
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
125
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
126 play_tree_t*
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
127 parse_asx(play_tree_parser_t* p) {
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
128 int comments = 0,get_line = 1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
129 char* line = NULL;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
130
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
131 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying asx...\n");
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
132
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
133 while(1) {
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
134 if(get_line) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
135 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
136 if(!line)
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
137 return NULL;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
138 strstrip(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
139 if(line[0] == '\0')
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
140 continue;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
141 }
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
142 if(!comments) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
143 if(line[0] != '<') {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
144 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"First char isn't '<' but '%c'\n",line[0]);
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
145 mp_msg(MSGT_PLAYTREE,MSGL_DBG3,"Buffer = [%s]\n",p->buffer);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
146 return NULL;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
147 } else if(strncmp(line,"<!--",4) == 0) { // Comments
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
148 comments = 1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
149 line += 4;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
150 if(line[0] != '\0' && strlen(line) > 0)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
151 get_line = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
152 } else if(strncasecmp(line,"<ASX",4) == 0) // We got an asx element
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
153 break;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
154 else // We don't get an asx
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
155 return NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
156 } else { // Comments
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
157 char* c;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
158 c = strchr(line,'-');
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
159 if(c) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
160 if (strncmp(c,"--!>",4) == 0) { // End of comments
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
161 comments = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
162 line = c+4;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
163 if(line[0] != '\0') // There is some more data on this line : keep it
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
164 get_line = 0;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
165
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
166 } else {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
167 line = c+1; // Jump the -
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
168 if(line[0] != '\0') // Some more data
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
169 get_line = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
170 else // End of line
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
171 get_line = 1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
172 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
173 } else // No - on this line (or rest of line) : get next one
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
174 get_line = 1;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
175 }
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
176 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
177
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
178 mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected asx format\n");
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
179
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
180 // We have an asx : load it in memory and parse
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
181
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
182 while((line = play_tree_parser_get_line(p)) != NULL)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
183 /* NOTHING */;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
184
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
185 mp_msg(MSGT_PLAYTREE,MSGL_DBG3,"Parsing asx file : [%s]\n",p->buffer);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
186 return asx_parser_build_tree(p->buffer,p->deep);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
187 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
188
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
189 static char*
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
190 pls_entry_get_value(char* line) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
191 char* i;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
192
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
193 i = strchr(line,'=');
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
194 if(!i || i[1] == '\0')
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
195 return NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
196 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
197 return i+1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
198 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
199
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
200 typedef struct pls_entry {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
201 char* file;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
202 char* title;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
203 char* length;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
204 } pls_entry_t;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
205
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
206 static int
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
207 pls_read_entry(char* line,pls_entry_t** _e,int* _max_entry,char** val) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
208 int num,max_entry = (*_max_entry);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
209 pls_entry_t* e = (*_e);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
210 char* v;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
211
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
212 v = pls_entry_get_value(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
213 if(!v) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
214 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
215 return 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
216 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
217
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
218 num = atoi(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
219 if(num < 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
220 num = max_entry+1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
221 mp_msg(MSGT_PLAYTREE,MSGL_WARN,"No entry index in entry %s\nAssuming %d\n",line,num);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
222 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
223 if(num > max_entry) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
224 e = (pls_entry_t*)realloc(e,num*sizeof(pls_entry_t));
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
225 memset(&e[max_entry],0,(num-max_entry)*sizeof(pls_entry_t));
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
226 max_entry = num;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
227 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
228 (*_e) = e;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
229 (*_max_entry) = max_entry;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
230 (*val) = v;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
231
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
232 return num;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
233 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
234
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
235
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
236 play_tree_t*
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
237 parse_pls(play_tree_parser_t* p) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
238 char *line,*v;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
239 pls_entry_t* entries = NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
240 int n_entries = 0,max_entry=0,num;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
241 play_tree_t *list = NULL, *entry = NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
242
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
243 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying winamp playlist...\n");
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
244 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
245 strstrip(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
246 if(strcasecmp(line,"[playlist]"))
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
247 return NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
248 mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected winamp playlist format\n");
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
249 play_tree_parser_stop_keeping(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
250 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
251 if(!line)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
252 return NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
253 strstrip(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
254 if(strncasecmp(line,"NumberOfEntries",15) == 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
255 v = pls_entry_get_value(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
256 n_entries = atoi(v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
257 if(n_entries < 0)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
258 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Invalid number of entries : very funny !!!\n");
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
259 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
260 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Playlist claim to have %d entries. Let's see.\n",n_entries);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
261 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
262 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
263
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
264 while(line) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
265 strstrip(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
266 if(line[0] == '\0') {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
267 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
268 continue;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
269 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
270 if(strncasecmp(line,"File",4) == 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
271 num = pls_read_entry(line+4,&entries,&max_entry,&v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
272 if(num < 0)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
273 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
274 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
275 entries[num-1].file = strdup(v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
276 } else if(strncasecmp(line,"Title",5) == 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
277 num = pls_read_entry(line+5,&entries,&max_entry,&v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
278 if(num < 0)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
279 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
280 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
281 entries[num-1].title = strdup(v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
282 } else if(strncasecmp(line,"Length",6) == 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
283 num = pls_read_entry(line+6,&entries,&max_entry,&v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
284 if(num < 0)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
285 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
286 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
287 entries[num-1].length = strdup(v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
288 } else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
289 mp_msg(MSGT_PLAYTREE,MSGL_WARN,"Unknow entry type %s\n",line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
290 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
291 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
292
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
293 for(num = 0; num < max_entry ; num++) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
294 if(entries[num].file == NULL)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
295 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Entry %d don't have a file !!!!\n",num+1);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
296 else {
5866
0f5f626e5151 Handle winamp playlist as sublist.
albeu
parents: 5802
diff changeset
297 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Adding entry %s\n",entries[num].file);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
298 entry = play_tree_new();
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
299 play_tree_add_file(entry,entries[num].file);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
300 free(entries[num].file);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
301 if(list)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
302 play_tree_append_entry(list,entry);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
303 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
304 list = entry;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
305 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
306 if(entries[num].title) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
307 // When we have info in playtree we add this info
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
308 free(entries[num].title);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
309 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
310 if(entries[num].length) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
311 // When we have info in playtree we add this info
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
312 free(entries[num].length);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
313 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
314 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
315
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
316 free(entries);
5866
0f5f626e5151 Handle winamp playlist as sublist.
albeu
parents: 5802
diff changeset
317
0f5f626e5151 Handle winamp playlist as sublist.
albeu
parents: 5802
diff changeset
318 entry = play_tree_new();
0f5f626e5151 Handle winamp playlist as sublist.
albeu
parents: 5802
diff changeset
319 play_tree_set_child(entry,list);
0f5f626e5151 Handle winamp playlist as sublist.
albeu
parents: 5802
diff changeset
320 return entry;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
321 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
322
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
323 play_tree_t*
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
324 parse_textplain(play_tree_parser_t* p) {
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
325 char* line;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
326 play_tree_t *list = NULL, *entry = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
327
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
328 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying plaintext...\n");
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
329 play_tree_parser_stop_keeping(p);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
330
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
331 while((line = play_tree_parser_get_line(p)) != NULL) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
332 strstrip(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
333 if(line[0] == '\0')
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
334 continue;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
335 entry = play_tree_new();
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
336 play_tree_add_file(entry,line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
337 if(!list)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
338 list = entry;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
339 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
340 play_tree_append_entry(list,entry);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
341 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
342
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
343 if(!list) return NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
344 entry = play_tree_new();
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
345 play_tree_set_child(entry,list);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
346 return entry;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
347 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
348
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
349 play_tree_t*
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
350 parse_playtree(stream_t *stream) {
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
351 play_tree_parser_t* p;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
352 play_tree_t* ret;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
353
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4043
diff changeset
354 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
355 assert(stream != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
356 assert(stream->type == STREAMTYPE_PLAYLIST);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
357 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
358
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
359 p = play_tree_parser_new(stream,0);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
360 if(!p)
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
361 return NULL;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
362
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
363 ret = play_tree_parser_get_play_tree(p);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
364 play_tree_parser_free(p);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
365
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
366 return ret;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
367 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
368
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
369 play_tree_t*
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
370 parse_playlist_file(char* file) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
371 stream_t *stream;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
372 play_tree_t* ret;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
373 int fd;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
374
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
375 if(!strcmp(file,"-"))
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
376 fd = 0;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
377 else
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
378 fd = open(file,O_RDONLY);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
379
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
380 if(fd < 0) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
381 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Error while opening playlist file %s : %s\n",file,strerror(errno));
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
382 return NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
383 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
384
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
385 mp_msg(MSGT_PLAYTREE,MSGL_V,"Parsing playlist file %s...\n",file);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
386
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
387 stream = new_stream(fd,STREAMTYPE_PLAYLIST);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
388 ret = parse_playtree(stream);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
389 if(close(fd) < 0)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
390 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Warning error while closing playlist file %s : %s\n",file,strerror(errno));
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
391 free_stream(stream);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
392
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
393 return ret;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
394
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
395 }
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
396
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
397
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
398 play_tree_parser_t*
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
399 play_tree_parser_new(stream_t* stream,int deep) {
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
400 play_tree_parser_t* p;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
401
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
402 p = (play_tree_parser_t*)calloc(1,sizeof(play_tree_parser_t));
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
403 if(!p)
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
404 return NULL;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
405 p->stream = stream;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
406 p->deep = deep;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
407 p->keep = 1;
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
408
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
409 return p;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
410
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
411 }
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
412
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
413 void
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
414 play_tree_parser_free(play_tree_parser_t* p) {
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
415
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
416 #ifdef MP_DEBUG
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
417 assert(p != NULL);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
418 #endif
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
419
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
420 if(p->buffer) free(p->buffer);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
421 if(p->line) free(p->line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
422 free(p);
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
423 }
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
424
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
425 play_tree_t*
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
426 play_tree_parser_get_play_tree(play_tree_parser_t* p) {
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
427 play_tree_t* tree = NULL;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
428
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
429 #ifdef MP_DEBUG
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
430 assert(p != NULL);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
431 #endif
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
432
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
433
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
434 while(play_tree_parser_get_line(p) != NULL) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
435 play_tree_parser_reset(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
436
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
437 tree = parse_asx(p);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
438 if(tree) break;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
439 play_tree_parser_reset(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
440
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
441 tree = parse_pls(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
442 if(tree) break;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
443 play_tree_parser_reset(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
444
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
445 // Here come the others formats ( textplain must stay the last one )
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
446 tree = parse_textplain(p);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
447 if(tree) break;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
448 break;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
449 }
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
450
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
451 if(tree)
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
452 mp_msg(MSGT_PLAYTREE,MSGL_V,"Playlist succefully parsed\n");
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
453 else mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Error while parsing playlist\n");
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
454
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
455 if(tree)
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
456 tree = play_tree_cleanup(tree);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
457
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
458 if(!tree) mp_msg(MSGT_PLAYTREE,MSGL_WARN,"Warning empty playlist\n");
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
459
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
460 return tree;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
461 }