[567293]: src / playlist.c  Maximize  Restore  History

Download this file

221 lines (180 with data), 4.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
* Copyright (C) 2000-2006 the xine project
*
* This file is part of xine, a free video player.
*
* xine is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* xine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
*
* Xine plugin for Mozilla/Firefox
* written by Claudio Ciccani <klan@users.sf.net>
*
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "playlist.h"
/******************************************************************************/
static inline char *trim (char *s) {
char *e;
for (; isspace(*s); s++);
e = s + strlen(s) - 1;
for (; e > s && isspace(*e); *e-- = '\0');
return s;
}
static char *getline (FILE *fp, char *buf, int size) {
if (fgets (buf, size, fp) == NULL)
return NULL;
return trim (buf);
}
static char *gettag (FILE *fp, char *buf, int size) {
int c, i = 0;
do {
c = getc (fp);
if (c < 0)
return NULL;
} while (c != '<');
do {
c = getc (fp);
if (c < 0)
return NULL;
buf[i++] = c;
} while (i < size && c != '>');
buf[i - 1] = '\0';
if (i > 1 && buf[i-2] == '/')
buf[i-2] = '\0';
return buf;
}
static char *getprop (char *tag, const char *prop, const int prop_len) {
char *p, *e;
while ((p = strstr (tag, prop))) {
p += prop_len;
if (isspace (*p))
p++;
if (*p == '=') {
p = trim (++p);
if (*p == '"') {
e = strchr (++p, '"');
if (e) {
*e = '\0';
return p;
}
} else {
return p;
}
}
tag = p;
}
return NULL;
}
/******************************************************************************/
static char *m3u_playlist_parse (FILE *fp, char *buf, int size) {
char *line;
while ((line = getline (fp, buf, size))) {
if (*line == '\0' || *line == '#')
continue;
return line;
}
return NULL;
}
static char *pls_playlist_parse (FILE *fp, char *buf, int size) {
char *line, *src;
while ((line = getline (fp, buf, size))) {
if (!strncmp (line, "File1=", 6)) {
src = line + 6;
if (*src)
return src;
}
}
return NULL;
}
static char *asx_playlist_parse (FILE *fp, char *buf, int size) {
char *tag, *src;
while ((tag = gettag (fp, buf, size))) {
if (!strncasecmp (tag, "ref ", 4)) {
src = getprop (tag + 4, "href", 4);
if (!src)
src = getprop (tag + 4, "HREF", 4);
if (src && *src)
return src;
}
}
return NULL;
}
static char *smil_playlist_parse (FILE *fp, char *buf, int size) {
char *tag, *src;
while ((tag = gettag (fp, buf, size))) {
if (!strncasecmp (tag, "audio ", 6) || !strncasecmp (tag, "video ", 6)) {
src = getprop (tag + 6, "src", 3);
if (!src)
src = getprop (tag + 6, "SRC", 3);
if (src && *src)
return src;
}
}
return NULL;
}
/******************************************************************************/
int playlist_type (const char *filename) {
char *ext;
ext = strrchr (filename, '.');
if (ext) {
if (!strcasecmp (ext, ".m3u"))
return XINE_PLT_M3U;
if (!strcasecmp (ext, ".ram") ||
!strcasecmp (ext, ".rpm"))
return XINE_PLT_RAM;
if (!strcasecmp (ext, ".pls"))
return XINE_PLT_PLS;
if (!strcasecmp (ext, ".asx") ||
!strcasecmp (ext, ".wax") ||
!strcasecmp (ext, ".wvx"))
return XINE_PLT_ASX;
if (!strcasecmp (ext, ".smi") ||
!strcasecmp (ext, ".smil"))
return XINE_PLT_SMI;
}
return XINE_PLT_NONE;
}
char *playlist_parse (int type, const char *filename, char *buf, int size) {
FILE *fp;
char *mrl = NULL;
fp = fopen (filename, "r");
if (!fp)
return NULL;
switch (type) {
case XINE_PLT_M3U:
case XINE_PLT_RAM:
mrl = m3u_playlist_parse (fp, buf, size);
break;
case XINE_PLT_PLS:
mrl = pls_playlist_parse (fp, buf, size);
break;
case XINE_PLT_ASX:
mrl = asx_playlist_parse (fp, buf, size);
break;
case XINE_PLT_SMI:
mrl = smil_playlist_parse (fp, buf, size);
break;
default:
break;
}
fclose (fp);
return mrl;
}