xspf.awk 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #
  2. # Copyright (C) 2005, 2006 Stephen Jungels
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # General Public License for more details.
  13. #
  14. # See COPYING for the full text of the license.
  15. BEGIN {
  16. title = toupper (substr (title, 1, 1)) substr (title, 2);
  17. print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
  18. print "<playlist version=\"0\" xmlns = \"http://xspf.org/ns/0/\">";
  19. print " <title>" title "</title>";
  20. print " <trackList>";
  21. }
  22. function myurlencode(str)
  23. {
  24. gsub (" ", "%20", str);
  25. gsub ("'", "%27", str);
  26. gsub ("&", "and", str);
  27. gsub (";", "%3b", str);
  28. gsub ("/", "%2f", str);
  29. gsub ("\\?", "%3f", str);
  30. gsub (":", "%3a", str);
  31. gsub ("@", "%40", str);
  32. gsub ("=", "%3d", str);
  33. return str;
  34. }
  35. {
  36. p2 = plait "/art.url";
  37. s = $0;
  38. sub (d "/", "", s);
  39. split (s, fields, sep);
  40. artist = fields[ar];
  41. album = fields[al];
  42. song = fields[so];
  43. split (song, f2, "[.]");
  44. song = f2[1];
  45. gsub ("_", " ", song);
  46. sub ("[0-9][0-9]? ?- ?", "", song);
  47. song = toupper (substr (song, 1, 1)) substr (song, 2);
  48. album = toupper (substr (album, 1, 1)) substr (album, 2);
  49. artist = toupper (substr (artist, 1, 1)) substr (artist, 2);
  50. if (index(s, "http://") != 1)
  51. {
  52. print " <track>";
  53. print " <creator>" artist "</creator>";
  54. print " <album>" album "</album>";
  55. print " <title>" song "</title>";
  56. print " <location>" url s "</location>";
  57. if (art==1)
  58. {
  59. ar2 = myurlencode(artist);
  60. al2 = myurlencode(album);
  61. url2 = "http://ws.audioscrobbler.com/1.0/album/" ar2 "/" al2 "/info.xml";
  62. if (url2 in images)
  63. {
  64. image = images[url2];
  65. }
  66. else
  67. {
  68. if (mustdelay==1)
  69. {
  70. system ("sleep 1");
  71. }
  72. system ("wget > /dev/null 2>&1 -O \"$HOME/.plait/art.xml\" " url2);
  73. mustdelay = 1;
  74. system ("awk -f " coverprog " \"$HOME/.plait/art.xml\" > \"$HOME/.plait/art.url\"");
  75. close (p2);
  76. getline image < p2;
  77. images[url2] = image;
  78. }
  79. if (image != "No art available")
  80. {
  81. print " <image>" image "</image>";
  82. }
  83. }
  84. print " </track>";
  85. }
  86. else
  87. {
  88. print " <track>";
  89. print " <annotation>" s "</annotation>";
  90. print " <location>" s "</location>";
  91. print " </track>";
  92. }
  93. }
  94. END {
  95. print " </trackList>";
  96. print "</playlist>";
  97. }