📄 m3u.c
字号:
while( *psz_bol && strncasecmp( psz_bol, "filename", sizeof("filename") - 1 ) ) psz_bol++; if( !*psz_bol ) return 0; while( *psz_bol && strncasecmp( psz_bol, "http://", sizeof("http://") - 1 ) ) psz_bol++; if( !*psz_bol ) return 0; psz_eol = strchr( psz_bol, '"'); if( !psz_eol ) return 0; *psz_eol = '\0'; } else if( p_m3u->i_type == TYPE_B4S ) { char *psz_eol; msg_Dbg( p_demux, "b4s line=%s", psz_line ); /* We are dealing with a B4S file from Winamp 3 */ /* First, search for name * * <Name>Blabla</Name> */ if( strstr ( psz_bol, "<Name>" ) ) { /* We have a name */ while ( *psz_bol && strncasecmp( psz_bol,"Name",sizeof("Name") -1 ) ) psz_bol++; if( !*psz_bol ) return 0; psz_bol = psz_bol + 5 ; /* We are now at the beginning of the name */ if( !psz_bol ) return 0; psz_eol = strchr(psz_bol, '<' ); if( !psz_eol) return 0; *psz_eol='\0'; XMLSpecialChars( psz_bol ); strcpy( psz_data, psz_bol ); return 2; } else if( strstr( psz_bol, "</entry>" ) || strstr( psz_bol, "</Entry>" )) { *pb_done = VLC_TRUE; return 0; } /* We are looking for <entry Playstring="blabla"> */ while( *psz_bol && strncasecmp( psz_bol,"Playstring",sizeof("Playstring") -1 ) ) psz_bol++; if( !*psz_bol ) return 0; psz_bol = strchr( psz_bol, '=' ); if ( !psz_bol ) return 0; psz_bol += 2; psz_eol= strchr(psz_bol, '"'); if( !psz_eol ) return 0; *psz_eol= '\0'; /* Handle the XML special characters */ XMLSpecialChars( psz_bol ); } else if( p_m3u->i_type == TYPE_RTSP ) { /* We are dealing with rtsptext reference files * Ignore anthying that doesn't start with rtsp://..." */ if( strncasecmp( psz_bol, "rtsp://", sizeof("rtsp://") - 1 ) ) /* ignore */ return 0; } else { msg_Warn( p_demux, "unknown file type" ); return 0; } /* empty line */ if ( !*psz_bol ) return 0; /* * From now on, we know we've got a meaningful line */ /* check for a protocol name */ /* for URL, we should look for "://" * for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]), * we should look for ":" * so we end up looking simply for ":"*/ /* PB: on some file systems, ':' are valid characters though*/ psz_name = psz_bol; while( *psz_name && *psz_name!=':' ) { psz_name++; }#ifdef WIN32 if ( *psz_name && ( psz_name == psz_bol + 1 ) ) { /* if it is not an URL, * as it is unlikely to be an MRL (PB: if it is ?) * it should be an absolute file name with the drive letter */ if ( *(psz_name+1) == '/' )/* "*:/" */ { if ( *(psz_name+2) != '/' )/* not "*://" */ while ( *psz_name ) *psz_name++;/* so now (*psz_name==0) */ } else while ( *psz_name ) *psz_name++;/* "*:*"*/ }#endif /* if the line doesn't specify a protocol name, * check if the line has an absolute or relative path */#ifndef WIN32 if( !*psz_name && *psz_bol != '/' ) /* If this line doesn't begin with a '/' */#else if( !*psz_name && *psz_bol!='/' && *psz_bol!='\\' && *(psz_bol+1)!=':' ) /* if this line doesn't begin with * "/" or "\" or "*:" or "*:\" or "*:/" or "\\" */#endif { /* assume the path is relative to the path of the m3u file. */ char *psz_path = strdup( p_demux->psz_path );#ifndef WIN32 psz_name = strrchr( psz_path, '/' );#else psz_name = strrchr( psz_path, '\\' ); if ( ! psz_name ) psz_name = strrchr( psz_path, '/' );#endif if( psz_name ) *psz_name = '\0'; else *psz_path = '\0';#ifndef WIN32 psz_name = malloc( strlen(psz_path) + strlen(psz_bol) + 2 ); sprintf( psz_name, "%s/%s", psz_path, psz_bol );#else if ( *psz_path != '\0' ) { psz_name = malloc( strlen(psz_path) + strlen(psz_bol) + 2 ); sprintf( psz_name, "%s\\%s", psz_path, psz_bol ); } else psz_name = strdup( psz_bol );#endif free( psz_path ); } else { psz_name = strdup( psz_bol ); } strcpy(psz_data, psz_name ) ; free( psz_name ); if( p_m3u->i_type != TYPE_B4S ) { *pb_done = VLC_TRUE; } return 1;}static void ProcessLine ( demux_t *p_demux, playlist_t *p_playlist, playlist_item_t *p_parent, char *psz_line, char **ppsz_uri, char **ppsz_name, int *pi_options, char ***pppsz_options, vlc_bool_t b_flush ){ char psz_data[MAX_LINE]; vlc_bool_t b_done; switch( ParseLine( p_demux, psz_line, psz_data, &b_done ) ) { case 1: if( *ppsz_uri ) free( *ppsz_uri ); *ppsz_uri = strdup( psz_data ); break; case 2: if( *ppsz_name ) free( *ppsz_name ); *ppsz_name = strdup( psz_data ); break; case 3: (*pi_options)++; *pppsz_options = realloc( *pppsz_options, sizeof(char *) * *pi_options ); (*pppsz_options)[*pi_options - 1] = strdup( psz_data ); break; case 0: default: break; } if( (b_done || b_flush) && *ppsz_uri ) { playlist_item_t *p_item = playlist_ItemNew( p_playlist, *ppsz_uri, *ppsz_name ); int i; for( i = 0; i < *pi_options; i++ ) { playlist_ItemAddOption( p_item, *pppsz_options[i] ); } playlist_NodeAddItem( p_playlist, p_item, p_parent->pp_parents[0]->i_view, p_parent, PLAYLIST_APPEND, PLAYLIST_END ); /* We need to declare the parents of the node as the * same of the parent's ones */ playlist_CopyParents( p_parent, p_item ); vlc_input_item_CopyOptions( &p_parent->input, &p_item->input ); if( *ppsz_name ) free( *ppsz_name ); *ppsz_name = NULL; free( *ppsz_uri ); *ppsz_uri = NULL; for( ; *pi_options; (*pi_options)-- ) { free( (*pppsz_options)[*pi_options - 1] ); if( *pi_options == 1 ) free( *pppsz_options ); } *pppsz_options = NULL; }}static vlc_bool_t FindItem( demux_t *p_demux, playlist_t *p_playlist, playlist_item_t **pp_item ){ vlc_bool_t b_play; if( &p_playlist->status.p_item->input == ((input_thread_t *)p_demux->p_parent)->input.p_item ) { msg_Dbg( p_playlist, "starting playlist playback" ); *pp_item = p_playlist->status.p_item; b_play = VLC_TRUE; } else { input_item_t *p_current = ((input_thread_t*)p_demux->p_parent)->input.p_item; *pp_item = playlist_LockItemGetByInput( p_playlist, p_current ); if( !*pp_item ) msg_Dbg( p_playlist, "unable to find item in playlist"); b_play = VLC_FALSE; } return b_play;}/***************************************************************************** * Demux: reads and demuxes data packets ***************************************************************************** * Returns -1 in case of error, 0 in case of EOF, 1 otherwise *****************************************************************************/static int Demux( demux_t *p_demux ){ demux_sys_t *p_m3u = p_demux->p_sys; char psz_line[MAX_LINE]; char p_buf[MAX_LINE], eol_tok; int i_size, i_bufpos, i_linepos = 0; vlc_bool_t b_discard = VLC_FALSE; char *psz_name = NULL; char *psz_uri = NULL; int i_options = 0; char **ppsz_options = NULL; playlist_t *p_playlist; playlist_item_t *p_parent; vlc_bool_t b_play; p_playlist = (playlist_t *) vlc_object_find( p_demux, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( !p_playlist ) { msg_Err( p_demux, "can't find playlist" ); return -1; } b_play = FindItem( p_demux, p_playlist, &p_parent ); playlist_ItemToNode( p_playlist, p_parent ); p_parent->input.i_type = ITEM_TYPE_PLAYLIST; /* Depending on wether we are dealing with an m3u/asf file, the end of * line token will be different */ if( p_m3u->i_type == TYPE_ASX || p_m3u->i_type == TYPE_HTML ) eol_tok = '>'; else eol_tok = '\n'; while( ( i_size = stream_Read( p_demux->s, p_buf, MAX_LINE ) ) ) { i_bufpos = 0; while( i_size ) { /* Build a line < MAX_LINE */ while( p_buf[i_bufpos] != eol_tok && i_size ) { if( i_linepos == MAX_LINE || b_discard == VLC_TRUE ) { /* line is bigger than MAX_LINE, discard it */ i_linepos = 0; b_discard = VLC_TRUE; } else { if ( eol_tok != '\n' || p_buf[i_bufpos] != '\r' ) { psz_line[i_linepos] = p_buf[i_bufpos]; i_linepos++; } } i_size--; i_bufpos++; } /* Check if we need more data */ if( !i_size ) continue; i_size--; i_bufpos++; b_discard = VLC_FALSE; /* Check for empty line */ if( !i_linepos ) continue; psz_line[i_linepos] = '\0'; i_linepos = 0; ProcessLine( p_demux, p_playlist, p_parent, psz_line, &psz_uri, &psz_name, &i_options, &ppsz_options, VLC_FALSE ); } } if( i_linepos && b_discard != VLC_TRUE && eol_tok == '\n' ) { psz_line[i_linepos] = '\0'; ProcessLine( p_demux, p_playlist, p_parent, psz_line, &psz_uri, &psz_name, &i_options, &ppsz_options, VLC_TRUE ); } if( psz_uri ) free( psz_uri ); if( psz_name ) free( psz_name ); for( ; i_options; i_options-- ) { free( ppsz_options[i_options - 1] ); if( i_options == 1 ) free( ppsz_options ); } /* Go back and play the playlist */ if( b_play ) { playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, p_playlist->status.i_view, p_playlist->status.p_item, NULL ); } vlc_object_release( p_playlist ); return 0;}static int Control( demux_t *p_demux, int i_query, va_list args ){ return VLC_EGENERIC;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -