📄 m3u.c
字号:
/*****************************************************************************
*
* This program 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.
*
* This program 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
*
* $Id: m3u.c 201 2005-01-15 08:42:20Z picard $
*
* BetaPlayer
* Copyright (c) 2004 Gabor Kovacs
*
****************************************************************************/
#include "../stdafx.h"
#include "m3u.h"
typedef struct m3u
{
format p;
stream* Input;
merge Buffer;
int No;
} m3u;
static int Enum( m3u* p, int No, datadef* Param )
{
return NodeEnumType(&No,Param,NodeParams,FormatParams,FormatPlayListParams,NULL);
}
static int Get( m3u* p, int No, void* Data, int Size )
{
int Result = ERR_INVALID_PARAM;
switch (No)
{
case NODE_ID: GETVALUE(M3U_ID,int); break;
case FORMAT_EXTS: GETSTRING(T("m3u:P")); break;
case FORMAT_INPUT: GETVALUE(p->Input,stream*); break;
}
return Result;
}
static int Init( m3u* p )
{
p->No = -1;
MergeDone(&p->Buffer);
if (p->Input)
{
MergeInit(&p->Buffer);
MergeAlloc(&p->Buffer,4096,1);
}
return ERR_NONE;
}
static int Set( m3u* p, int No, const void* Data, int Size )
{
int Result = ERR_INVALID_PARAM;
switch (No)
{
case FORMAT_INPUT: SETVALUE(p->Input,stream*,Init(p)); break;
}
return Result;
}
static int ReadList( m3u* p,tchar_t* Path,int PathLen,tchar_t* DispName,int DispNameLen,tick_t* Length)
{
tchar_t s[MAXLINE];
DispName[0] = 0;
*Length = -1;
while (ReadLine(&p->Buffer,p->Input,s,sizeof(s)))
{
if (s[0]=='#')
{
UpperUntil(s,':');
if (Scanf(s,T("#EXTINF: %d ,"),Length)==1)
{
tchar_t* p = tcschr(s,',');
if (p++)
{
while (*p==' ') ++p;
TcsNCpy(DispName,p,DispNameLen);
}
if (*Length >= 0)
*Length *= TICKSPERSEC;
}
}
else
if (s[0])
{
TcsNCpy(Path,s,PathLen);
return ERR_NONE;
}
}
return ERR_END_OF_FILE;
}
static int WriteList( m3u* p, const tchar_t* Path,const tchar_t* DispName,tick_t Length)
{
if (Path)
{
if (p->No++<0)
StreamPrintf(p->Input,T("#EXTM3U\n"));
if (Length >= 0 || DispName[0])
StreamPrintf(p->Input,T("#EXTINF:%d,%s\n"),Length/TICKSPERSEC,DispName);
StreamPrintf(p->Input,T("%s\n"),Path);
}
return ERR_NONE;
}
static m3u M3U;
void M3U_Init()
{
NodeFill((node*)&M3U.p,sizeof(m3u),(nodeenum)Enum,(nodeget)Get,(nodeset)Set);
M3U.p.ReadList = (fmtreadlist)ReadList;
M3U.p.WriteList = (fmtwritelist)WriteList;
NodeRegister((node*)&M3U.p,PRI_DEFAULT);
}
void M3U_Done()
{
NodeUnRegister((node*)&M3U.p);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -