annotate playtreeparser.c @ 5718:82af351fff02

more tajpo
author gabucino
date Sat, 20 Apr 2002 06:25:49 +0000
parents f3f94fb55398
children 8bd1c1e319fb
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
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
52 if(p->stream->eof && p->buffer_end == 0)
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;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
86 p->line = (char*)realloc(p->line,line_end - p->iter+1);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
87 if(!p->line)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
88 return NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
89 strncpy(p->line,p->iter,line_end - p->iter);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
90 p->line[line_end - p->iter] = '\0';
4857
f3f94fb55398 Small bugfix with getting playlist last line.
albeu
parents: 4782
diff changeset
91 if(end != '\0')
f3f94fb55398 Small bugfix with getting playlist last line.
albeu
parents: 4782
diff changeset
92 end++;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
93
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
94 if(!p->keep) {
4857
f3f94fb55398 Small bugfix with getting playlist last line.
albeu
parents: 4782
diff changeset
95 if(end[0] != '\0') {
f3f94fb55398 Small bugfix with getting playlist last line.
albeu
parents: 4782
diff changeset
96 p->buffer_end -= strlen(p->line)+1;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
97 memmove(p->buffer,end,p->buffer_end);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
98 } else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
99 p->buffer_end = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
100 p->iter = p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
101 } else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
102 p->iter = end;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
103
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
104 return p->line;
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
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
107 static void
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
108 play_tree_parser_reset(play_tree_parser_t* p) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
109 p->iter = p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
110 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
111
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
112 static void
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
113 play_tree_parser_stop_keeping(play_tree_parser_t* p) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
114 p->keep = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
115 if(p->iter && p->iter != p->buffer) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
116 p->buffer_end -= p->iter -p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
117 if(p->buffer_end)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
118 memmove(p->buffer,p->iter,p->buffer_end);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
119 p->iter = p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
120 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
121 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
122
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
123
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
124 play_tree_t*
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
125 parse_asx(play_tree_parser_t* p) {
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
126 int comments = 0,get_line = 1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
127 char* line = NULL;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
128
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
129 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
130
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
131 while(1) {
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
132 if(get_line) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
133 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
134 if(!line)
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
135 return NULL;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
136 strstrip(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
137 if(line[0] == '\0')
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
138 continue;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
139 }
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
140 if(!comments) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
141 if(line[0] != '<') {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
142 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
143 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
144 return NULL;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
145 } else if(strncmp(line,"<!--",4) == 0) { // Comments
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
146 comments = 1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
147 line += 4;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
148 if(line[0] != '\0' && strlen(line) > 0)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
149 get_line = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
150 } 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
151 break;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
152 else // We don't get an asx
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
153 return NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
154 } else { // Comments
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
155 char* c;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
156 c = strchr(line,'-');
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
157 if(c) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
158 if (strncmp(c,"--!>",4) == 0) { // End of comments
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
159 comments = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
160 line = c+4;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
161 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
162 get_line = 0;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
163
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
164 } else {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
165 line = c+1; // Jump the -
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
166 if(line[0] != '\0') // Some more data
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
167 get_line = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
168 else // End of line
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
169 get_line = 1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
170 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
171 } 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
172 get_line = 1;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
173 }
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
174 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
175
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
176 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
177
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
178 // 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
179
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
180 while((line = play_tree_parser_get_line(p)) != NULL)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
181 /* NOTHING */;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
182
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
183 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
184 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
185 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
186
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
187 static char*
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
188 pls_entry_get_value(char* line) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
189 char* i;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
190
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
191 i = strchr(line,'=');
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
192 if(!i || i[1] == '\0')
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
193 return NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
194 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
195 return i+1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
196 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
197
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
198 typedef struct pls_entry {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
199 char* file;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
200 char* title;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
201 char* length;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
202 } pls_entry_t;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
203
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
204 static int
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
205 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
206 int num,max_entry = (*_max_entry);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
207 pls_entry_t* e = (*_e);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
208 char* v;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
209
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
210 v = pls_entry_get_value(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
211 if(!v) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
212 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
213 return 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
214 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
215
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
216 num = atoi(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
217 if(num < 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
218 num = max_entry+1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
219 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
220 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
221 if(num > max_entry) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
222 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
223 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
224 max_entry = num;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
225 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
226 (*_e) = e;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
227 (*_max_entry) = max_entry;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
228 (*val) = v;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
229
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
230 return num;
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
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 play_tree_t*
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
235 parse_pls(play_tree_parser_t* p) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
236 char *line,*v;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
237 pls_entry_t* entries = NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
238 int n_entries = 0,max_entry=0,num;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
239 play_tree_t *list = NULL, *entry = NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
240
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
241 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying winamp playlist...\n");
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
242 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
243 strstrip(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
244 if(strcasecmp(line,"[playlist]"))
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
245 return NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
246 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
247 play_tree_parser_stop_keeping(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
248 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
249 if(!line)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
250 return NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
251 strstrip(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
252 if(strncasecmp(line,"NumberOfEntries",15) == 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
253 v = pls_entry_get_value(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
254 n_entries = atoi(v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
255 if(n_entries < 0)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
256 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
257 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
258 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
259 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
260 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
261
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
262 while(line) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
263 strstrip(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
264 if(line[0] == '\0') {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
265 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
266 continue;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
267 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
268 if(strncasecmp(line,"File",4) == 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
269 num = pls_read_entry(line+4,&entries,&max_entry,&v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
270 if(num < 0)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
271 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
272 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
273 entries[num-1].file = strdup(v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
274 } else if(strncasecmp(line,"Title",5) == 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
275 num = pls_read_entry(line+5,&entries,&max_entry,&v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
276 if(num < 0)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
277 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
278 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
279 entries[num-1].title = strdup(v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
280 } else if(strncasecmp(line,"Length",6) == 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
281 num = pls_read_entry(line+6,&entries,&max_entry,&v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
282 if(num < 0)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
283 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
284 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
285 entries[num-1].length = strdup(v);
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 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
288 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
289 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
290
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
291 for(num = 0; num < max_entry ; num++) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
292 if(entries[num].file == NULL)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
293 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
294 else {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
295 entry = play_tree_new();
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
296 play_tree_add_file(entry,entries[num].file);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
297 free(entries[num].file);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
298 if(list)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
299 play_tree_append_entry(list,entry);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
300 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
301 list = entry;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
302 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
303 if(entries[num].title) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
304 // When we have info in playtree we add this info
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
305 free(entries[num].title);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
306 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
307 if(entries[num].length) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
308 // When we have info in playtree we add this info
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
309 free(entries[num].length);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
310 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
311 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
312
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
313 free(entries);
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 return list;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
316 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
317
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
318 play_tree_t*
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
319 parse_textplain(play_tree_parser_t* p) {
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
320 char* line;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
321 play_tree_t *list = NULL, *entry = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
322
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
323 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying plaintext...\n");
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
324 play_tree_parser_stop_keeping(p);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
325
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
326 while((line = play_tree_parser_get_line(p)) != NULL) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
327 strstrip(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
328 if(line[0] == '\0')
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
329 continue;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
330 entry = play_tree_new();
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
331 play_tree_add_file(entry,line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
332 if(!list)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
333 list = entry;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
334 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
335 play_tree_append_entry(list,entry);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
336 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
337
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
338 if(!list) return NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
339 entry = play_tree_new();
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
340 play_tree_set_child(entry,list);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
341 return entry;
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
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
344 play_tree_t*
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
345 parse_playtree(stream_t *stream) {
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
346 play_tree_parser_t* p;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
347 play_tree_t* ret;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
348
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4043
diff changeset
349 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
350 assert(stream != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
351 assert(stream->type == STREAMTYPE_PLAYLIST);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
352 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
353
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
354 p = play_tree_parser_new(stream,0);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
355 if(!p)
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
356 return NULL;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
357
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
358 ret = play_tree_parser_get_play_tree(p);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
359 play_tree_parser_free(p);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
360
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
361 return ret;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
362 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
363
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
364 play_tree_t*
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
365 parse_playlist_file(char* file) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
366 stream_t *stream;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
367 play_tree_t* ret;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
368 int fd;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
369
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
370 if(!strcmp(file,"-"))
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
371 fd = 0;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
372 else
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
373 fd = open(file,O_RDONLY);
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(fd < 0) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
376 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
377 return NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
378 }
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 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
381
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
382 stream = new_stream(fd,STREAMTYPE_PLAYLIST);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
383 ret = parse_playtree(stream);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
384 if(close(fd) < 0)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
385 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
386 free_stream(stream);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
387
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
388 return ret;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
389
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
390 }
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
391
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
392
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
393 play_tree_parser_t*
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
394 play_tree_parser_new(stream_t* stream,int deep) {
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
395 play_tree_parser_t* p;
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 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
398 if(!p)
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
399 return NULL;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
400 p->stream = stream;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
401 p->deep = deep;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
402 p->keep = 1;
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
403
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
404 return p;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
405
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
406 }
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
407
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
408 void
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
409 play_tree_parser_free(play_tree_parser_t* 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 #ifdef MP_DEBUG
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
412 assert(p != NULL);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
413 #endif
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
414
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
415 if(p->buffer) free(p->buffer);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
416 if(p->line) free(p->line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
417 free(p);
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
418 }
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 play_tree_t*
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
421 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
422 play_tree_t* tree = NULL;
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 #ifdef MP_DEBUG
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
425 assert(p != NULL);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
426 #endif
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
427
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
428
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
429 while(play_tree_parser_get_line(p) != NULL) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
430 play_tree_parser_reset(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
431
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
432 tree = parse_asx(p);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
433 if(tree) break;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
434 play_tree_parser_reset(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
435
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
436 tree = parse_pls(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
437 if(tree) break;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
438 play_tree_parser_reset(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
439
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
440 // 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
441 tree = parse_textplain(p);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
442 if(tree) break;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
443 break;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
444 }
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
445
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
446 if(tree)
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
447 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
448 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
449
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
450 if(tree)
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
451 tree = play_tree_cleanup(tree);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
452
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
453 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
454
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
455 return tree;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
456 }