M3u.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /** (c) Nullsoft, Inc. C O N F I D E N T I A L
  2. ** Filename:
  3. ** Project:
  4. ** Description:
  5. ** Author:
  6. ** Created:
  7. **/
  8. #include "Main.h"
  9. #include "strutil.h"
  10. #include "api.h"
  11. #include "WinampPlaylist.h"
  12. #include "../nu/AUtoWide.h"
  13. #include "../nu/AUtoChar.h"
  14. #include "../WAT/WAT.h"
  15. int savem3ufn(const wchar_t *filename, int rel, int useBase)
  16. {
  17. UINT conv=CP_ACP;
  18. if (!lstrcmpiW(PathFindExtensionW(filename), L".m3u8"))
  19. conv=CP_UTF8;
  20. FILE *fp = 0;
  21. int ext = 1;
  22. int pos = PlayList_getPosition();
  23. fp = _wfopen(filename, L"wt");
  24. if (!fp) return -1;
  25. if (conv==CP_UTF8)
  26. fputs("\xEF\xBB\xBF", fp); // write UTF-8 BOM
  27. if (ext) fprintf(fp, "#EXTM3U\n");
  28. PlayList_setposition(0);
  29. if (PlayList_getlength()) for (;;)
  30. {
  31. if ( !PlayList_gethidden(PlayList_getPosition())
  32. && !PlayList_hasanycurtain(PlayList_getPosition())
  33. )
  34. {
  35. wchar_t fnbuf[FILENAME_SIZE] = {0};
  36. wchar_t ftbuf[FILETITLE_SIZE] = {0};
  37. PlayList_getitem2W(PlayList_getPosition(), fnbuf, ftbuf);
  38. int len = PlayList_getcurrentlength();
  39. if (rel)
  40. {
  41. PlayList_makerelative(filename, fnbuf, useBase);
  42. if (fnbuf[0]=='#') // woops, can't start a line with #
  43. PlayList_getitem2W(PlayList_getPosition(), fnbuf, 0); // retrieve file name again
  44. }
  45. if ( ext && PlayList_getcached( PlayList_getPosition() ) )
  46. {
  47. const char *l_ext_inf = PlayList_getExtInf( PlayList_getPosition() );
  48. wa::strings::wa_string l_filename( fnbuf );
  49. if ( ext && l_ext_inf && *l_ext_inf && l_filename.contains( "://" ) )
  50. {
  51. fprintf( fp, "#EXTINF:%d%s,%s\n%s\n", len, l_ext_inf, (char *)AutoChar( ftbuf, conv ), (char *)AutoChar( fnbuf, conv ) );
  52. delete( l_ext_inf );
  53. }
  54. else
  55. fprintf( fp, "#EXTINF:%d,%s\n%s\n", len, (char *)AutoChar( ftbuf, conv ), (char *)AutoChar( fnbuf, conv ) );
  56. }
  57. else
  58. fprintf(fp, "%s\n", (char *)AutoChar(fnbuf, conv));
  59. }
  60. if (PlayList_advance(1) < 0)
  61. break;
  62. }
  63. fclose(fp);
  64. PlayList_setposition(pos);
  65. return 0;
  66. }