一级嵌套m3u8文件制作

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#include<fcntl.h>
#include<stdio.h>
#include<string.h>


#define M3U8_CFG         "./m3u8.cfg"
#define M3U8_HEADER      "#EXTM3U\n#EXT-X-VERSION:3\n"
#define M3U8_LINE_HEADER "#EXT-X-STREAM-INF:PROGRAM-ID=1, %s"

int main()
{
  FILE* fWd = NULL;
  char line[1024] = { 0 };
  memset( &line,0,sizeof(line) );
  char* path = M3U8_CFG;
  FILE* fRd =fopen( path,"r" );
  if( NULL ==  fRd )
    return 0;
  
  fgets( line,sizeof( line ), fRd );
  if( '$' == line[ 0 ] )
    {	
      char* pWPath = line + 1;
      int nLast = strlen( pWPath );
      pWPath[ nLast-1 ] = '\0';
      fWd = fopen( pWPath, "w+" );
      if( NULL != fWd )   
	{
 	  char* pheader = M3U8_HEADER; 
	  fputs( pheader,fWd );
	
	  while( fgets( line,sizeof( line ), fRd ) )
	    {
	      if( '#' == line[ 0 ] )
		{
		  char msg[1024] = {0};
		  memset(&msg,0,sizeof(msg));
		  char* tempLine = line + 1;
		  snprintf(msg, sizeof(msg),M3U8_LINE_HEADER, tempLine );
		  int nLast = strlen ( msg );
		  msg[ nLast ] = '\0';
		  fputs( msg,fWd );	  
		}
	      else  if( '^' == line[0] )
		{
		  char* tempLine = line + 1;
		  fputs(tempLine,fWd );
		}
	    }
	}
    }
  
  if( NULL != fRd )
    {
      fclose( fRd );
      fRd = NULL;
    }
  if( NULL != fWd )
    {
      fclose( fWd );
      fWd = NULL;
    }
  return 0;
}