songinfo.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #include <lib/std.mi>
  2. Function string tokenizeSongInfo(String tkn, String sinfo);
  3. Function getSonginfo(String SongInfoString);
  4. Function loadPlaylistArtWork();
  5. Global Group frameGroup;
  6. Global Layer channelDisplay;
  7. Global Text bitrateText, FrequencyText;
  8. Global Timer songInfoTimer;
  9. Global String SongInfoString;
  10. Global AlbumArtLayer waaa;
  11. Global Int waaaRetries = 0;
  12. System.onScriptLoaded(){
  13. frameGroup = getScriptGroup();
  14. bitrateText = frameGroup.findObject("Bitrate");
  15. frequencyText = frameGroup.findObject("Frequency");
  16. channelDisplay = frameGroup.findObject("channels");
  17. songInfoTimer = new Timer;
  18. songInfoTimer.setDelay(1000);
  19. if (getStatus() == STATUS_PLAYING) {
  20. String sit = getSongInfoText();
  21. waaaRetries = 0;
  22. if (sit != "") getSonginfo(sit);
  23. else songInfoTimer.setDelay(50); // goes to 1000 once info is available
  24. songInfoTimer.start();
  25. } else if (getStatus() == STATUS_PAUSED) {
  26. getSonginfo(getSongInfoText());
  27. }
  28. }
  29. loadPlaylistArtWork()
  30. {
  31. Container albumart = System.getContainer("winamp.albumart");
  32. if(albumart)
  33. {
  34. Layout aalayout = albumart.getLayout("normal");
  35. if(aalayout)
  36. {
  37. waaa = aalayout.findObject("waaa");
  38. }
  39. }
  40. }
  41. System.onScriptUnloading(){
  42. delete songInfoTimer;
  43. }
  44. System.onPlay(){
  45. String sit = getSongInfoText();
  46. waaaRetries = 0;
  47. if (sit != "") getSonginfo(sit);
  48. else songInfoTimer.setDelay(50); // goes to 1000 once info is available
  49. songInfoTimer.start();
  50. }
  51. System.onStop(){
  52. waaaRetries = 0;
  53. songInfoTimer.stop();
  54. frequencyText.setText("(__)");
  55. bitrateText.setText("(___)");
  56. channelDisplay.setXmlParam("image", "player.songinfo.none");
  57. }
  58. System.onResume(){
  59. String sit = getSongInfoText();
  60. if (sit != "") getSonginfo(sit);
  61. else songInfoTimer.setDelay(50); // goes to 1000 once info is available
  62. songInfoTimer.start();
  63. }
  64. System.onPause(){
  65. songInfoTimer.stop();
  66. }
  67. songInfoTimer.onTimer(){
  68. String sit = getSongInfoText();
  69. if (sit == "") return;
  70. songInfoTimer.setDelay(1000);
  71. getSonginfo(sit);
  72. if(!waaa) loadPlaylistArtWork();
  73. if(waaa)
  74. {
  75. if(waaa.isInvalid() && waaaRetries < 5)
  76. {
  77. waaaRetries += 1;
  78. waaa.refresh();
  79. waaa.show();
  80. }
  81. else if(!waaa.isInvalid())
  82. {
  83. waaaRetries = 0;
  84. }
  85. }
  86. }
  87. String tokenizeSongInfo(String tkn, String sinfo){
  88. int searchResult;
  89. String rtn;
  90. if (tkn=="Bitrate"){
  91. for (int i = 0; i < 5; i++) {
  92. rtn = getToken(sinfo, " ", i);
  93. searchResult = strsearch(rtn, "kbps");
  94. if (searchResult>0) return StrMid(rtn, 0, searchResult);
  95. }
  96. return "";
  97. }
  98. if (tkn=="Channels"){
  99. for (int i = 0; i < 5; i++) {
  100. rtn = getToken(sinfo, " ", i);
  101. searchResult = strsearch(rtn, "tereo");
  102. if (searchResult>0) return "stereo";
  103. searchResult = strsearch(rtn, "ono");
  104. if (searchResult>0) return "mono";
  105. // Martin: surround > 3, stereo = 2,3
  106. searchResult = strsearch(rtn, "annels");
  107. if (searchResult>0)
  108. {
  109. int pos = strsearch(getSongInfoText(), "annels");
  110. pos = stringToInteger(strmid(getSongInfoText(), pos - 4, 1));
  111. if (pos > 3) return "surround";
  112. if (pos > 1 && pos < 4) return "stereo";
  113. else return "mono";
  114. }
  115. }
  116. return "none";
  117. }
  118. if (tkn=="Frequency"){
  119. for (int i = 0; i < 5; i++) {
  120. rtn = getToken(sinfo, " ", i);
  121. searchResult = strsearch(strlower(rtn), "khz");
  122. if (searchResult>0) {
  123. String r = StrMid(rtn, 0, searchResult);
  124. int dot = StrSearch(r, ".");
  125. if (dot == -1) dot = StrSearch(r, ",");
  126. if (dot != -1) return StrMid(r, 0, dot);
  127. return r;
  128. }
  129. }
  130. return "";
  131. }
  132. else return "";
  133. }
  134. getSonginfo(String SongInfoString) {
  135. String tkn;
  136. tkn = tokenizeSongInfo("Bitrate", SongInfoString);
  137. if(tkn != "") {bitrateText.setText("["+tkn+"]");}
  138. tkn = tokenizeSongInfo("Channels", SongInfoString);
  139. channelDisplay.setXmlParam("image", "player.songinfo." + tkn);
  140. tkn = tokenizeSongInfo("Frequency", SongInfoString);
  141. if(tkn != "") {frequencyText.setText("["+tkn+"]");}
  142. }