Diff of /src/playlist.c [000000] .. [567293]  Maximize  Restore

  Switch to side-by-side view

--- a
+++ b/src/playlist.c
@@ -0,0 +1,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;
+}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks