changeset 12097:cb0cdaa0bddf

Support for smil playlist, both standalone and embedded into other playlists. Pathc by adland
author rtognimp
date Thu, 01 Apr 2004 22:11:28 +0000
parents 54514e4733a1
children 73ee9bd3b537
files playtreeparser.c
diffstat 1 files changed, 136 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/playtreeparser.c	Thu Apr 01 20:59:07 2004 +0000
+++ b/playtreeparser.c	Thu Apr 01 22:11:28 2004 +0000
@@ -428,8 +428,123 @@
 }
 
 play_tree_t*
+parse_smil(play_tree_parser_t* p) {
+  int entrymode=0;
+  char* line,source[512],*pos,*s_start,*s_end;
+  play_tree_t *list = NULL, *entry = NULL, *last_entry = NULL;
+
+  mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying smil playlist...\n");
+
+  // Check if smil
+  while((line = play_tree_parser_get_line(p)) != NULL) {
+    strstrip(line);
+    if(line[0] == '\0') // Ignore empties
+      continue;
+    if (strncasecmp(line,"<smil",5)==0)
+      break; // smil header found
+    else
+      return NULL; //line not smil exit
+  }
+
+  mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected smil playlist format\n");
+  play_tree_parser_stop_keeping(p);
+
+
+  //Get entries from smil 
+  while((line = play_tree_parser_get_line(p)) != NULL) {
+    strstrip(line);
+    if (line[0]=='\0')
+      continue;
+    if (!entrymode) { // all entries filled so far 
+      if (strncasecmp(line,"<video",6)==0  || strncasecmp(line,"<audio",6)==0) {
+        pos=strstr(line,"src=");   // Is source present on this line
+        if (pos !=NULL) {
+          s_start=pos+5;
+          s_end=strchr(s_start,'"');
+            if (s_end == NULL) {
+              mp_msg(MSGT_PLAYTREE,MSGL_V,"Error parsing this source line %s\n",line);
+              continue;   
+            }
+          if (s_end-s_start> 511) {
+            mp_msg(MSGT_PLAYTREE,MSGL_V,"Cannot store such a large source %s\n",line);
+            continue;
+          }
+          strncpy(source,s_start,s_end-s_start);
+          source[(s_end-s_start)]='\0'; // Null terminate
+          entry = play_tree_new();
+          play_tree_add_file(entry,source);
+          if(!list)  //Insert new entry
+            list = entry;
+          else
+            play_tree_append_entry(last_entry,entry);
+          last_entry = entry;
+        } else {
+          entrymode=1;
+        }
+      }
+    } else { //Entry found but not yet filled
+      pos = strstr(line,"src=");   // Is source present on this line
+      if (pos != NULL) {
+        entrymode=0;
+        s_start=pos+5;
+        s_end=strchr(s_start,'"');
+        if (s_end == NULL) {
+          mp_msg(MSGT_PLAYTREE,MSGL_V,"Error parsing this source line %s\n",line);
+          continue;
+        }
+        if (s_end-s_start> 511) {
+          mp_msg(MSGT_PLAYTREE,MSGL_V,"Cannot store such a large source %s\n",line);
+          continue;
+        }
+        strncpy(source,s_start,s_end-s_start);
+        source[(s_end-s_start)]='\0'; // Null terminate
+        entry = play_tree_new();
+        play_tree_add_file(entry,source);
+        if(!list)  //Insert new entry
+          list = entry;
+        else
+          play_tree_append_entry(last_entry,entry);
+        last_entry = entry;
+      }
+    }
+  }
+
+  if(!list) return NULL; // Nothing found
+
+  entry = play_tree_new();
+  play_tree_set_child(entry,list);
+  return entry;
+}
+
+play_tree_t*
+embedded_playlist_parse(char *line) {
+  int f;
+  stream_t* stream;
+  play_tree_parser_t* ptp;
+  play_tree_t* entry;
+
+  // Get stream opened to link
+  stream=open_stream(line,0,&f);
+  if(!stream) {
+    mp_msg(MSGT_PLAYTREE,MSGL_WARN,"Can't open playlist %s\n",line);
+    return NULL;
+  }
+
+  //add new playtree
+  mp_msg(MSGT_PLAYTREE,MSGL_V,"Adding playlist %s to element entryref\n",line);
+
+  ptp = play_tree_parser_new(stream,1);
+  entry = play_tree_parser_get_play_tree(ptp, 1);
+  play_tree_parser_free(ptp);
+  free_stream(stream);
+
+  return entry;
+}
+
+play_tree_t*
 parse_textplain(play_tree_parser_t* p) {
   char* line;
+  int reflen;
   play_tree_t *list = NULL, *entry = NULL, *last_entry = NULL;
 
   mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying plaintext playlist...\n");
@@ -439,13 +554,23 @@
     strstrip(line);
     if(line[0] == '\0')
       continue;
-    entry = play_tree_new();
-    play_tree_add_file(entry,line);
-    if(!list)
-      list = entry;
-    else
-      play_tree_append_entry(last_entry,entry);
-    last_entry = entry;
+
+    //Special check for smil refernce in file
+    reflen=strlen(line);
+    if ( (reflen>5) && (strncasecmp(line+(reflen-5),".smil",5)==0) ) { //embedded playlist link
+      entry=embedded_playlist_parse(line);
+    } else {      //regular file link
+      entry = play_tree_new();
+      play_tree_add_file(entry,line);
+    }
+
+    if (entry != NULL) {
+      if(!list)
+        list = entry;
+      else
+        play_tree_append_entry(last_entry,entry);
+      last_entry = entry;
+    }
   }
    
   if(!list) return NULL;
@@ -597,6 +722,10 @@
     if(tree) break;
     play_tree_parser_reset(p);
 
+    tree = parse_smil(p);
+    if(tree) break;
+    play_tree_parser_reset(p);
+     
     // Here come the others formats ( textplain must stay the last one )
     if (forced)
     {