HTML.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /** (c) Nullsoft, Inc. C O N F I D E N T I A L
  2. ** Filename:
  3. ** Project:
  4. ** Description: HTML generation from playlist
  5. ** Author:
  6. ** Created:
  7. **/
  8. #include "main.h"
  9. #include <stdio.h>
  10. #include "../nu/AutoChar.h"
  11. #include "resource.h"
  12. void doHtmlPlaylist(void)
  13. {
  14. FILE *fp = 0;
  15. wchar_t filename[MAX_PATH] = {0}, tp[MAX_PATH] = {0};
  16. if (!GetTempPathW(MAX_PATH,tp)) StringCchCopyW(tp, MAX_PATH, L".");
  17. if (GetTempFileNameW(tp, L"WHT", 0, filename)){
  18. DeleteFileW(filename);
  19. StringCchCatW(filename, MAX_PATH, L".html");
  20. }
  21. else StringCchCopyW(filename, MAX_PATH, L"wahtml_tmp.html");
  22. fp = _wfopen(filename, L"wt");
  23. if (!fp)
  24. {
  25. LPMessageBox(hPLWindow, IDS_HTML_ERROR_WRITE, IDS_ERROR, MB_OK | MB_ICONWARNING);
  26. return;
  27. }
  28. fprintf(fp, "<!DOCTYPE html>\n"
  29. "<html lang=\"en\"><head>\n"
  30. "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">\n"
  31. "<meta name=\"generator\" content=\"Winamp 5.9\">\n"
  32. "<style>body{background:#000040;font-family:arial,helvetica;font-size:9pt;font-weight:normal;}"
  33. ".name{margin-top:-1em;margin-left:15px;font-size:40pt;color:#004080;text-align:left;font-weight:900;}"
  34. ".name-small{margin-top:-3em;margin-left:140px;font-size:22pt;color:#E1E1E1;text-align:left;}"
  35. "table{font-size:9pt;color:#004080;text-align:left;border-width:0px;padding:0px;letter-spacing:normal;}"
  36. "hr{border:0;background-color:#FFBF00;height:1px;}"
  37. "ol{color:#FFFFFF;font-size:11pt;}"
  38. "table{margin-left:15px;color:#409FFF;border-width:0px;}"
  39. ".val{color:#FFBF00;}"
  40. ".header{color:#FFBF00;font-size:14pt;}"
  41. "</style>\n"
  42. "<title>Winamp Generated PlayList</title></head>\n"
  43. "<body>"
  44. "<div>"
  45. "<div class=\"name\"><p>WINAMP</p></div>"
  46. "<div class=\"name-small\"><p>playlist</p></div>"
  47. "</div>"
  48. "<hr><div>\n"
  49. "<table><tr><td>\n");
  50. int x, t = PlayList_getlength(), t_in_pl = 0, n_un = 0;
  51. for (x = 0; x < t; x ++)
  52. {
  53. int a = PlayList_getsonglength(x);
  54. if (a >= 0) t_in_pl += a;
  55. else n_un++;
  56. }
  57. if (t != n_un)
  58. {
  59. int old_t_in_pl=t_in_pl;
  60. t_in_pl += (n_un * t_in_pl) / (t - n_un);
  61. fprintf(fp, "<span class=\"val\">%d</span> track%s in playlist, ", t, t == 1 ? "" : "s");
  62. fprintf(fp, "average track length: <span class=\"val\">%d:%02d",
  63. old_t_in_pl / (t-n_un) / 60, (old_t_in_pl / (t - n_un)) % 60);
  64. fprintf(fp, "</span><br>%slaylist length: ",
  65. n_un ? "Estimated p" : "P");
  66. if (t_in_pl / 3600)
  67. {
  68. fprintf(fp, "<span class=\"val\">%d</span> hour%s ",
  69. t_in_pl / 3600, t_in_pl / 3600 == 1 ? "" : "s");
  70. t_in_pl %= 3600;
  71. }
  72. if (t_in_pl / 60)
  73. {
  74. fprintf(fp, "<span class=\"val\">%d</span> minute%s ",
  75. t_in_pl / 60, t_in_pl / 60 == 1 ? "" : "s");
  76. t_in_pl %= 60;
  77. }
  78. fprintf(fp, "<span class=\"val\">%d</span> second%s %s",
  79. t_in_pl, t_in_pl == 1 ? "" : "s", n_un ? "<br>(" : "");
  80. if (n_un) fprintf(fp, "<span class=\"val\">%d</span> track%s of unknown length)",
  81. n_un, n_un == 1 ? "" : "s");
  82. fprintf(fp,
  83. "<br>Right-click <a href=\"file://%s\">here</a> to save this HTML file."
  84. "</td></tr>",
  85. (char *)AutoChar(filename, CP_UTF8));
  86. }
  87. else
  88. {
  89. fprintf(fp, "There are no tracks in the current playlist.<br>");
  90. }
  91. fprintf(fp, "</table></div>\n");
  92. if (t > 0)
  93. {
  94. fprintf(fp,
  95. "<blockquote><span class=\"header\">Playlist files:</span><ol>\n");
  96. for (x = 0; x < t; x++)
  97. {
  98. wchar_t fn[FILENAME_SIZE] = {0}, ft[FILETITLE_SIZE] = {0};
  99. int l;
  100. PlayList_getitem2W(x, fn, ft);
  101. AutoChar narrowFt(ft, CP_UTF8);
  102. char *p = narrowFt;
  103. l = PlayList_getsonglength(x);
  104. fprintf(fp, "<li>");
  105. while (p && *p)
  106. {
  107. if (*p == '&') fprintf(fp, "&amp;");
  108. else if (*p == '<') fprintf(fp, "&lt;");
  109. else if (*p == '>') fprintf(fp, "&gt;");
  110. else if (*p == '\'') fprintf(fp, "&#39;");
  111. else if (*p == '"') fprintf(fp, "&quot;");
  112. else fputc(*p, fp);
  113. p++;
  114. }
  115. if(l > 0) fprintf(fp, " (%d:%02d) \n", l / 60, l % 60);
  116. else fprintf(fp, " \n");
  117. }
  118. fprintf(fp, "</ol></blockquote>\n");
  119. }
  120. fprintf(fp, "<hr><br></body></html>");
  121. fclose(fp);
  122. myOpenURL(hPLWindow, filename);
  123. }