1
0

M3U8Writer.cpp 943 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "M3U8Writer.h"
  2. #include "../nu/AutoChar.h"
  3. #include <bfc/platform/types.h>
  4. M3U8Writer::M3U8Writer() : fp(0)
  5. {
  6. }
  7. int M3U8Writer::Open(const wchar_t *filename)
  8. {
  9. fp = _wfopen(filename, L"wt");
  10. if (!fp)
  11. return 0;
  12. fputs( "\xEF\xBB\xBF", fp );
  13. fprintf(fp,"#EXTM3U\n");
  14. return 1;
  15. }
  16. void M3U8Writer::Write(const wchar_t *filename)
  17. {
  18. fwprintf(fp,L"%s\n", filename);
  19. }
  20. void M3U8Writer::Write(const wchar_t *filename, const wchar_t *title, int length)
  21. {
  22. fprintf( fp, "#EXTINF:%d,%s\n%s\n", length, (char *) AutoChar( title, CP_UTF8 ), (char *) AutoChar( filename, CP_UTF8 ) );
  23. }
  24. void M3U8Writer::Write( const wchar_t *p_filename, const wchar_t *p_title, const wchar_t *p_extended_infos, int p_length )
  25. {
  26. fprintf( fp, "#EXTINF:%d %s,%s\n%s\n", p_length, (char *)AutoChar( p_extended_infos, CP_UTF8 ), (char *)AutoChar( p_title, CP_UTF8 ), (char *)AutoChar( p_filename, CP_UTF8 ) );
  27. }
  28. void M3U8Writer::Close()
  29. {
  30. fclose(fp);
  31. }