annotate playtreeparser.c @ 12143:da228f2485d9

SSE support under OpenBSD, patch by Bjorn Sandell
author alex
date Tue, 06 Apr 2004 17:08:02 +0000
parents cb0cdaa0bddf
children e7c8200ffdc5
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>
9749
58e5880f4788 Use new config headers
albeu
parents: 9301
diff changeset
14 #include "m_config.h"
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
15 #include "playtree.h"
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
16 #include "playtreeparser.h"
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
17 #include "libmpdemux/stream.h"
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
18 #include "mp_msg.h"
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
19
6662
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
20
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
21 #if defined(__CYGWIN__) || defined(__OS2__)
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
22 #define PATH_SEP '\\'
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
23 #else
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
24 #define PATH_SEP '/'
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
25 #endif
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
26
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
27 extern play_tree_t*
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
28 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
29
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
30 #define BUF_STEP 1024
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
31
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
32 #define WHITES " \n\r\t"
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
33
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
34 static void
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
35 strstrip(char* str) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
36 char* i;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
37
8907
e82149e697a7 bunkus: Another nice off-by-one :)
mosu
parents: 8897
diff changeset
38 if (str==NULL)
e82149e697a7 bunkus: Another nice off-by-one :)
mosu
parents: 8897
diff changeset
39 return;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
40 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
41 /* NOTHING */;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
42 if(i[0] != '\0') {
8907
e82149e697a7 bunkus: Another nice off-by-one :)
mosu
parents: 8897
diff changeset
43 memmove(str,i,strlen(i) + 1);
e82149e697a7 bunkus: Another nice off-by-one :)
mosu
parents: 8897
diff changeset
44 for(i = str + strlen(str) - 1 ; strchr(WHITES,i[0]) != NULL; i--)
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
45 /* NOTHING */;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
46 i[1] = '\0';
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
47 } else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
48 str[0] = '\0';
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
49 }
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 static char*
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
52 play_tree_parser_get_line(play_tree_parser_t* p) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
53 char *end,*line_end;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
54 int r,resize = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
55
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
56 if(p->buffer == NULL) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
57 p->buffer = (char*)malloc(BUF_STEP);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
58 p->buffer_size = BUF_STEP;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
59 p->iter = p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
60 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
61
5802
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
62 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
63 return NULL;
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 while(1) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
66
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
67 if(resize) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
68 r = p->iter - p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
69 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
70 p->iter = p->buffer + r;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
71 p->buffer_size += BUF_STEP;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
72 resize = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
73 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
74
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
75 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
76 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
77 if(r > 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
78 p->buffer_end += r;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
79 p->buffer[p->buffer_end] = '\0';
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
80 }
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
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
83 end = strchr(p->iter,'\n');
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
84 if(!end) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
85 if(p->stream->eof) {
4857
f3f94fb55398 Small bugfix with getting playlist last line.
albeu
parents: 4782
diff changeset
86 end = p->buffer + p->buffer_end;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
87 break;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
88 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
89 resize = 1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
90 continue;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
91 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
92 break;
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
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
95 line_end = ((*(end-1)) == '\r') ? end-1 : end;
5802
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
96 if(line_end - p->iter >= 0)
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
97 p->line = (char*)realloc(p->line,line_end - p->iter+1);
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
98 else
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
99 return NULL;
5802
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
100 if(line_end - p->iter > 0)
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
101 strncpy(p->line,p->iter,line_end - p->iter);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
102 p->line[line_end - p->iter] = '\0';
5802
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
103 if(end[0] != '\0')
4857
f3f94fb55398 Small bugfix with getting playlist last line.
albeu
parents: 4782
diff changeset
104 end++;
4782
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 if(!p->keep) {
4857
f3f94fb55398 Small bugfix with getting playlist last line.
albeu
parents: 4782
diff changeset
107 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
108 p->buffer_end -= end-p->iter;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
109 memmove(p->buffer,end,p->buffer_end);
10694
5eb539aa5250 Fix the bug found by Martin Wulffeld
albeu
parents: 10487
diff changeset
110 p->buffer[p->buffer_end] = '\0';
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
111 } else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
112 p->buffer_end = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
113 p->iter = p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
114 } else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
115 p->iter = end;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
116
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
117 return p->line;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
118 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
119
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
120 static void
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
121 play_tree_parser_reset(play_tree_parser_t* p) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
122 p->iter = p->buffer;
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
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
125 static void
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
126 play_tree_parser_stop_keeping(play_tree_parser_t* p) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
127 p->keep = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
128 if(p->iter && p->iter != p->buffer) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
129 p->buffer_end -= p->iter -p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
130 if(p->buffer_end)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
131 memmove(p->buffer,p->iter,p->buffer_end);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
132 p->iter = p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
133 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
134 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
135
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
136
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
137 play_tree_t*
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
138 parse_asx(play_tree_parser_t* p) {
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
139 int comments = 0,get_line = 1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
140 char* line = NULL;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
141
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
142 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
143
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
144 while(1) {
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
145 if(get_line) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
146 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
147 if(!line)
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
148 return NULL;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
149 strstrip(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
150 if(line[0] == '\0')
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
151 continue;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
152 }
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
153 if(!comments) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
154 if(line[0] != '<') {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
155 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
156 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
157 return NULL;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
158 } else if(strncmp(line,"<!--",4) == 0) { // Comments
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
159 comments = 1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
160 line += 4;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
161 if(line[0] != '\0' && strlen(line) > 0)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
162 get_line = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
163 } 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
164 break;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
165 else // We don't get an asx
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
166 return NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
167 } else { // Comments
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
168 char* c;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
169 c = strchr(line,'-');
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
170 if(c) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
171 if (strncmp(c,"--!>",4) == 0) { // End of comments
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
172 comments = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
173 line = c+4;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
174 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
175 get_line = 0;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
176
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
177 } else {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
178 line = c+1; // Jump the -
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
179 if(line[0] != '\0') // Some more data
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
180 get_line = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
181 else // End of line
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
182 get_line = 1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
183 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
184 } 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
185 get_line = 1;
4043
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 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
188
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
189 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
190
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
191 // 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
192
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
193 while((line = play_tree_parser_get_line(p)) != NULL)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
194 /* NOTHING */;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
195
10487
11ec7586a0fe Typos fixed, based on patch sent by Alex.
diego
parents: 10397
diff changeset
196 mp_msg(MSGT_PLAYTREE,MSGL_DBG3,"Parsing asx file: [%s]\n",p->buffer);
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
197 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
198 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
199
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
200 static char*
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
201 pls_entry_get_value(char* line) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
202 char* i;
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 i = strchr(line,'=');
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
205 if(!i || i[1] == '\0')
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
206 return NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
207 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
208 return i+1;
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
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
211 typedef struct pls_entry {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
212 char* file;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
213 char* title;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
214 char* length;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
215 } pls_entry_t;
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 static int
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
218 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
219 int num,max_entry = (*_max_entry);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
220 pls_entry_t* e = (*_e);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
221 char* v;
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 v = pls_entry_get_value(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
224 if(!v) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
225 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
226 return 0;
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
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
229 num = atoi(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
230 if(num < 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
231 num = max_entry+1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
232 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
233 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
234 if(num > max_entry) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
235 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
236 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
237 max_entry = num;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
238 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
239 (*_e) = e;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
240 (*_max_entry) = max_entry;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
241 (*val) = v;
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 return num;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
244 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
245
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
246
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
247 play_tree_t*
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
248 parse_pls(play_tree_parser_t* p) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
249 char *line,*v;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
250 pls_entry_t* entries = NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
251 int n_entries = 0,max_entry=0,num;
9789
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
252 play_tree_t *list = NULL, *entry = NULL, *last_entry = NULL;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
253
10487
11ec7586a0fe Typos fixed, based on patch sent by Alex.
diego
parents: 10397
diff changeset
254 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying Winamp playlist...\n");
8925
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
255 if (!(line = play_tree_parser_get_line(p)))
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
256 return NULL;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
257 strstrip(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
258 if(strcasecmp(line,"[playlist]"))
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
259 return NULL;
10487
11ec7586a0fe Typos fixed, based on patch sent by Alex.
diego
parents: 10397
diff changeset
260 mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected Winamp playlist format\n");
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
261 play_tree_parser_stop_keeping(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
262 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
263 if(!line)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
264 return NULL;
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(strncasecmp(line,"NumberOfEntries",15) == 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
267 v = pls_entry_get_value(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
268 n_entries = atoi(v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
269 if(n_entries < 0)
10487
11ec7586a0fe Typos fixed, based on patch sent by Alex.
diego
parents: 10397
diff changeset
270 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Invalid number of entries: very funny!!!\n");
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
271 else
10487
11ec7586a0fe Typos fixed, based on patch sent by Alex.
diego
parents: 10397
diff changeset
272 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Playlist claims to have %d entries. Let's see.\n",n_entries);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
273 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
274 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
275
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
276 while(line) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
277 strstrip(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
278 if(line[0] == '\0') {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
279 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
280 continue;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
281 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
282 if(strncasecmp(line,"File",4) == 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
283 num = pls_read_entry(line+4,&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].file = strdup(v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
288 } else if(strncasecmp(line,"Title",5) == 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
289 num = pls_read_entry(line+5,&entries,&max_entry,&v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
290 if(num < 0)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
291 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
292 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
293 entries[num-1].title = strdup(v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
294 } else if(strncasecmp(line,"Length",6) == 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
295 num = pls_read_entry(line+6,&entries,&max_entry,&v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
296 if(num < 0)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
297 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
298 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
299 entries[num-1].length = strdup(v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
300 } else
10397
6180d7558f75 output typo fixes: unknow --> unknown
diego
parents: 9789
diff changeset
301 mp_msg(MSGT_PLAYTREE,MSGL_WARN,"Unknown entry type %s\n",line);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
302 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
303 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
304
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
305 for(num = 0; num < max_entry ; num++) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
306 if(entries[num].file == NULL)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
307 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
308 else {
5866
0f5f626e5151 Handle winamp playlist as sublist.
albeu
parents: 5802
diff changeset
309 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
310 entry = play_tree_new();
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
311 play_tree_add_file(entry,entries[num].file);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
312 free(entries[num].file);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
313 if(list)
9789
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
314 play_tree_append_entry(last_entry,entry);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
315 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
316 list = entry;
9789
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
317 last_entry = entry;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
318 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
319 if(entries[num].title) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
320 // When we have info in playtree we add this info
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
321 free(entries[num].title);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
322 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
323 if(entries[num].length) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
324 // When we have info in playtree we add this info
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
325 free(entries[num].length);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
326 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
327 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
328
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
329 free(entries);
5866
0f5f626e5151 Handle winamp playlist as sublist.
albeu
parents: 5802
diff changeset
330
0f5f626e5151 Handle winamp playlist as sublist.
albeu
parents: 5802
diff changeset
331 entry = play_tree_new();
0f5f626e5151 Handle winamp playlist as sublist.
albeu
parents: 5802
diff changeset
332 play_tree_set_child(entry,list);
0f5f626e5151 Handle winamp playlist as sublist.
albeu
parents: 5802
diff changeset
333 return entry;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
334 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
335
8897
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
336 /*
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
337 Reference Ini-Format: Each entry is assumed a reference
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
338 */
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
339 play_tree_t*
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
340 parse_ref_ini(play_tree_parser_t* p) {
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
341 char *line,*v;
9789
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
342 play_tree_t *list = NULL, *entry = NULL, *last_entry = NULL;
8897
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
343
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
344 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying reference-ini playlist...\n");
8925
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
345 if (!(line = play_tree_parser_get_line(p)))
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
346 return NULL;
8897
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
347 strstrip(line);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
348 if(strcasecmp(line,"[Reference]"))
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
349 return NULL;
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
350 mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected reference-ini playlist format\n");
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
351 play_tree_parser_stop_keeping(p);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
352 line = play_tree_parser_get_line(p);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
353 if(!line)
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
354 return NULL;
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
355 while(line) {
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
356 strstrip(line);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
357 if(strncasecmp(line,"Ref",3) == 0) {
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
358 v = pls_entry_get_value(line+3);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
359 if(!v)
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
360 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
361 else
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
362 {
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
363 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Adding entry %s\n",v);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
364 entry = play_tree_new();
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
365 play_tree_add_file(entry,v);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
366 if(list)
9789
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
367 play_tree_append_entry(last_entry,entry);
8897
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
368 else
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
369 list = entry;
9789
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
370 last_entry = entry;
8897
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
371 }
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
372 }
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
373 line = play_tree_parser_get_line(p);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
374 }
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
375
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
376 if(!list) return NULL;
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
377 entry = play_tree_new();
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
378 play_tree_set_child(entry,list);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
379 return entry;
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
380 }
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
381
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
382 play_tree_t*
6661
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
383 parse_m3u(play_tree_parser_t* p) {
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
384 char* line;
9789
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
385 play_tree_t *list = NULL, *entry = NULL, *last_entry = NULL;
6661
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
386
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
387 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying extended m3u playlist...\n");
8925
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
388 if (!(line = play_tree_parser_get_line(p)))
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
389 return NULL;
6661
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
390 strstrip(line);
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
391 if(strcasecmp(line,"#EXTM3U"))
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
392 return NULL;
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
393 mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected extended m3u playlist format\n");
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
394 play_tree_parser_stop_keeping(p);
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
395
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
396 while((line = play_tree_parser_get_line(p)) != NULL) {
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
397 strstrip(line);
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
398 if(line[0] == '\0')
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
399 continue;
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
400 /* EXTM3U files contain such lines:
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
401 * #EXTINF:<seconds>, <title>
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
402 * followed by a line with the filename
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
403 * for now we have no place to put that
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
404 * so we just skip that extra-info ::atmos
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
405 */
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
406 if(line[0] == '#') {
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
407 #if 0 /* code functional */
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
408 if(strncasecmp(line,"#EXTINF:",8) == 0) {
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
409 mp_msg(MSGT_PLAYTREE,MSGL_INFO,"[M3U] Duration: %dsec Title: %s\n",
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
410 strtol(line+8,&line,10), line+2);
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
411 }
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
412 #endif
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
413 continue;
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
414 }
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
415 entry = play_tree_new();
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
416 play_tree_add_file(entry,line);
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
417 if(!list)
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
418 list = entry;
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
419 else
9789
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
420 play_tree_append_entry(last_entry,entry);
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
421 last_entry = entry;
6661
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
422 }
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
423
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
424 if(!list) return NULL;
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
425 entry = play_tree_new();
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
426 play_tree_set_child(entry,list);
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
427 return entry;
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
428 }
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
429
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
430 play_tree_t*
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
431 parse_smil(play_tree_parser_t* p) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
432 int entrymode=0;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
433 char* line,source[512],*pos,*s_start,*s_end;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
434 play_tree_t *list = NULL, *entry = NULL, *last_entry = NULL;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
435
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
436 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying smil playlist...\n");
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
437
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
438 // Check if smil
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
439 while((line = play_tree_parser_get_line(p)) != NULL) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
440 strstrip(line);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
441 if(line[0] == '\0') // Ignore empties
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
442 continue;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
443 if (strncasecmp(line,"<smil",5)==0)
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
444 break; // smil header found
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
445 else
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
446 return NULL; //line not smil exit
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
447 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
448
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
449 mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected smil playlist format\n");
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
450 play_tree_parser_stop_keeping(p);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
451
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
452
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
453 //Get entries from smil
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
454 while((line = play_tree_parser_get_line(p)) != NULL) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
455 strstrip(line);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
456 if (line[0]=='\0')
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
457 continue;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
458 if (!entrymode) { // all entries filled so far
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
459 if (strncasecmp(line,"<video",6)==0 || strncasecmp(line,"<audio",6)==0) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
460 pos=strstr(line,"src="); // Is source present on this line
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
461 if (pos !=NULL) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
462 s_start=pos+5;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
463 s_end=strchr(s_start,'"');
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
464 if (s_end == NULL) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
465 mp_msg(MSGT_PLAYTREE,MSGL_V,"Error parsing this source line %s\n",line);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
466 continue;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
467 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
468 if (s_end-s_start> 511) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
469 mp_msg(MSGT_PLAYTREE,MSGL_V,"Cannot store such a large source %s\n",line);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
470 continue;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
471 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
472 strncpy(source,s_start,s_end-s_start);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
473 source[(s_end-s_start)]='\0'; // Null terminate
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
474 entry = play_tree_new();
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
475 play_tree_add_file(entry,source);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
476 if(!list) //Insert new entry
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
477 list = entry;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
478 else
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
479 play_tree_append_entry(last_entry,entry);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
480 last_entry = entry;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
481 } else {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
482 entrymode=1;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
483 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
484 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
485 } else { //Entry found but not yet filled
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
486 pos = strstr(line,"src="); // Is source present on this line
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
487 if (pos != NULL) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
488 entrymode=0;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
489 s_start=pos+5;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
490 s_end=strchr(s_start,'"');
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
491 if (s_end == NULL) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
492 mp_msg(MSGT_PLAYTREE,MSGL_V,"Error parsing this source line %s\n",line);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
493 continue;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
494 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
495 if (s_end-s_start> 511) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
496 mp_msg(MSGT_PLAYTREE,MSGL_V,"Cannot store such a large source %s\n",line);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
497 continue;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
498 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
499 strncpy(source,s_start,s_end-s_start);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
500 source[(s_end-s_start)]='\0'; // Null terminate
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
501 entry = play_tree_new();
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
502 play_tree_add_file(entry,source);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
503 if(!list) //Insert new entry
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
504 list = entry;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
505 else
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
506 play_tree_append_entry(last_entry,entry);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
507 last_entry = entry;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
508 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
509 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
510 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
511
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
512 if(!list) return NULL; // Nothing found
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
513
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
514 entry = play_tree_new();
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
515 play_tree_set_child(entry,list);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
516 return entry;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
517 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
518
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
519 play_tree_t*
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
520 embedded_playlist_parse(char *line) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
521 int f;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
522 stream_t* stream;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
523 play_tree_parser_t* ptp;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
524 play_tree_t* entry;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
525
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
526 // Get stream opened to link
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
527 stream=open_stream(line,0,&f);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
528 if(!stream) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
529 mp_msg(MSGT_PLAYTREE,MSGL_WARN,"Can't open playlist %s\n",line);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
530 return NULL;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
531 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
532
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
533 //add new playtree
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
534 mp_msg(MSGT_PLAYTREE,MSGL_V,"Adding playlist %s to element entryref\n",line);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
535
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
536 ptp = play_tree_parser_new(stream,1);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
537 entry = play_tree_parser_get_play_tree(ptp, 1);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
538 play_tree_parser_free(ptp);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
539 free_stream(stream);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
540
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
541 return entry;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
542 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
543
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
544 play_tree_t*
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
545 parse_textplain(play_tree_parser_t* p) {
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
546 char* line;
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
547 int reflen;
9789
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
548 play_tree_t *list = NULL, *entry = NULL, *last_entry = NULL;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
549
6661
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
550 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying plaintext playlist...\n");
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
551 play_tree_parser_stop_keeping(p);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
552
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
553 while((line = play_tree_parser_get_line(p)) != NULL) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
554 strstrip(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
555 if(line[0] == '\0')
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
556 continue;
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
557
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
558 //Special check for smil refernce in file
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
559 reflen=strlen(line);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
560 if ( (reflen>5) && (strncasecmp(line+(reflen-5),".smil",5)==0) ) { //embedded playlist link
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
561 entry=embedded_playlist_parse(line);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
562 } else { //regular file link
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
563 entry = play_tree_new();
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
564 play_tree_add_file(entry,line);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
565 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
566
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
567 if (entry != NULL) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
568 if(!list)
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
569 list = entry;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
570 else
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
571 play_tree_append_entry(last_entry,entry);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
572 last_entry = entry;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
573 }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
574 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
575
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
576 if(!list) return NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
577 entry = play_tree_new();
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
578 play_tree_set_child(entry,list);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
579 return entry;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
580 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
581
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
582 play_tree_t*
8925
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
583 parse_playtree(stream_t *stream, int forced) {
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
584 play_tree_parser_t* p;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
585 play_tree_t* ret;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
586
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4043
diff changeset
587 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
588 assert(stream != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
589 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
590
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
591 p = play_tree_parser_new(stream,0);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
592 if(!p)
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
593 return NULL;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
594
8925
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
595 ret = play_tree_parser_get_play_tree(p, forced);
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
596 play_tree_parser_free(p);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
597
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
598 return ret;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
599 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
600
6662
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
601 static void
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
602 play_tree_add_basepath(play_tree_t* pt, char* bp) {
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
603 int i,bl = strlen(bp),fl;
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
604
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
605 if(pt->child) {
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
606 play_tree_t* i;
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
607 for(i = pt->child ; i != NULL ; i = i->next)
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
608 play_tree_add_basepath(i,bp);
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
609 return;
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
610 }
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
611
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
612 if(!pt->files)
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
613 return;
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
614
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
615 for(i = 0 ; pt->files[i] != NULL ; i++) {
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
616 fl = strlen(pt->files[i]);
6663
5790a2576505 10L don't add a base path to the urls
albeu
parents: 6662
diff changeset
617 if(fl <= 0 || pt->files[i][0] == PATH_SEP || strstr(pt->files[i],"://"))
6662
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
618 continue;
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
619 pt->files[i] = (char*)realloc(pt->files[i],bl+fl+1);
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
620 memmove(pt->files[i] + bl,pt->files[i],fl+1);
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
621 memcpy(pt->files[i],bp,bl);
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
622 }
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
623 }
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
624
9301
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
625 // Wrapper for play_tree_add_basepath (add base path from file)
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
626 void play_tree_add_bpf(play_tree_t* pt, char* filename)
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
627 {
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
628 char *ls, *file;
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
629
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
630 if (pt && filename)
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
631 {
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
632 file = strdup(filename);
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
633 if (file)
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
634 {
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
635 ls = strrchr(file,PATH_SEP);
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
636 if(ls) {
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
637 ls[1] = '\0';
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
638 play_tree_add_basepath(pt,file);
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
639 }
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
640 free(file);
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
641 }
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
642 }
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
643 }
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
644
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
645 play_tree_t*
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
646 parse_playlist_file(char* file) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
647 stream_t *stream;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
648 play_tree_t* ret;
9749
58e5880f4788 Use new config headers
albeu
parents: 9301
diff changeset
649 int f;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
650
9749
58e5880f4788 Use new config headers
albeu
parents: 9301
diff changeset
651 stream = open_stream(file,0,&f);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
652
9749
58e5880f4788 Use new config headers
albeu
parents: 9301
diff changeset
653 if(!stream) {
10487
11ec7586a0fe Typos fixed, based on patch sent by Alex.
diego
parents: 10397
diff changeset
654 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Error while opening playlist file %s: %s\n",file,strerror(errno));
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
655 return NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
656 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
657
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
658 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
659
8925
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
660 ret = parse_playtree(stream,1);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
661 free_stream(stream);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
662
9301
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
663 play_tree_add_bpf(ret, file);
6662
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
664
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
665 return ret;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
666
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
667 }
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
668
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
669
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
670 play_tree_parser_t*
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
671 play_tree_parser_new(stream_t* stream,int deep) {
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
672 play_tree_parser_t* p;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
673
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
674 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
675 if(!p)
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
676 return NULL;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
677 p->stream = stream;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
678 p->deep = deep;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
679 p->keep = 1;
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
680
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
681 return p;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
682
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
683 }
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
684
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
685 void
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
686 play_tree_parser_free(play_tree_parser_t* p) {
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
687
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
688 #ifdef MP_DEBUG
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
689 assert(p != NULL);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
690 #endif
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
691
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
692 if(p->buffer) free(p->buffer);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
693 if(p->line) free(p->line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
694 free(p);
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
695 }
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
696
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
697 play_tree_t*
8925
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
698 play_tree_parser_get_play_tree(play_tree_parser_t* p, int forced) {
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
699 play_tree_t* tree = NULL;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
700
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
701 #ifdef MP_DEBUG
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
702 assert(p != NULL);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
703 #endif
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
704
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
705
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
706 while(play_tree_parser_get_line(p) != NULL) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
707 play_tree_parser_reset(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
708
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
709 tree = parse_asx(p);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
710 if(tree) break;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
711 play_tree_parser_reset(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
712
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
713 tree = parse_pls(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
714 if(tree) break;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
715 play_tree_parser_reset(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
716
6661
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
717 tree = parse_m3u(p);
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
718 if(tree) break;
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
719 play_tree_parser_reset(p);
8897
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
720
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
721 tree = parse_ref_ini(p);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
722 if(tree) break;
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
723 play_tree_parser_reset(p);
6661
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
724
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
725 tree = parse_smil(p);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
726 if(tree) break;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
727 play_tree_parser_reset(p);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
728
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
729 // Here come the others formats ( textplain must stay the last one )
8925
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
730 if (forced)
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
731 {
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
732 tree = parse_textplain(p);
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
733 if(tree) break;
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
734 }
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
735 break;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
736 }
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
737
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
738 if(tree)
10487
11ec7586a0fe Typos fixed, based on patch sent by Alex.
diego
parents: 10397
diff changeset
739 mp_msg(MSGT_PLAYTREE,MSGL_V,"Playlist successfully parsed\n");
8925
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
740 else
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
741 mp_msg(MSGT_PLAYTREE,((forced==1)?MSGL_ERR:MSGL_V),"Error while parsing playlist\n");
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
742
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
743 if(tree)
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
744 tree = play_tree_cleanup(tree);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
745
10487
11ec7586a0fe Typos fixed, based on patch sent by Alex.
diego
parents: 10397
diff changeset
746 if(!tree) mp_msg(MSGT_PLAYTREE,((forced==1)?MSGL_WARN:MSGL_V),"Warning: empty playlist\n");
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
747
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
748 return tree;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
749 }