[Mplayer-cvslog] CVS: main playtreeparser.c,1.24,1.25
Roberto Togni CVS
syncmail at mplayerhq.hu
Fri Apr 2 00:11:30 CEST 2004
CVS change done by Roberto Togni CVS
Update of /cvsroot/mplayer/main
In directory mail:/var2/tmp/cvs-serv24602
Modified Files:
playtreeparser.c
Log Message:
Support for smil playlist, both standalone and embedded into other
playlists.
Pathc by adland
Index: playtreeparser.c
===================================================================
RCS file: /cvsroot/mplayer/main/playtreeparser.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- playtreeparser.c 25 Aug 2003 15:29:55 -0000 1.24
+++ playtreeparser.c 1 Apr 2004 22:11:28 -0000 1.25
@@ -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)
{
More information about the MPlayer-cvslog
mailing list