File: xspf.awk

package info (click to toggle)
plait 1.6.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 276 kB
  • sloc: sh: 2,010; awk: 709; makefile: 10
file content (106 lines) | stat: -rwxr-xr-x 2,766 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#
# Copyright (C) 2005, 2006 Stephen Jungels
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.  
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# See COPYING for the full text of the license.


BEGIN {
  title = toupper (substr (title, 1, 1)) substr (title, 2);
  print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
  print "<playlist version=\"0\" xmlns = \"http://xspf.org/ns/0/\">";
  print "  <title>" title "</title>";
  print "  <trackList>";
}


function myurlencode(str)
{
  gsub (" ", "%20", str);
  gsub ("'", "%27", str);
  gsub ("&", "and", str);
  gsub (";", "%3b", str);
  gsub ("/", "%2f", str);
  gsub ("\\?", "%3f", str);
  gsub (":", "%3a", str);
  gsub ("@", "%40", str);
  gsub ("=", "%3d", str);
  return str;
}

{
  p2 = plait "/art.url";
  s = $0;
  sub (d "/", "", s);
  split (s, fields, sep);
  artist = fields[ar];
  album = fields[al];
  song = fields[so];
  split (song, f2, "[.]");
  song = f2[1];
  gsub ("_", " ", song);
  sub ("[0-9][0-9]? ?- ?", "", song);
  song = toupper (substr (song, 1, 1)) substr (song, 2);
  album = toupper (substr (album, 1, 1)) substr (album, 2);
  artist = toupper (substr (artist, 1, 1)) substr (artist, 2);

  if (index(s, "http://") != 1)
    {
      print "    <track>";
      print "      <creator>" artist "</creator>";
      print "      <album>" album "</album>";
      print "      <title>" song "</title>";
      print "      <location>" url s "</location>";
      if (art==1)
	{
	  ar2 = myurlencode(artist);
	  al2 = myurlencode(album);
	  url2 = "http://ws.audioscrobbler.com/1.0/album/" ar2 "/" al2 "/info.xml";
	  if (url2 in images)
	    {
	      image = images[url2];
	    }
	  else
	    {
	      if (mustdelay==1)
		{
		  system ("sleep 1");
		}
	      system ("wget > /dev/null 2>&1 -O \"$HOME/.plait/art.xml\" " url2);
	      mustdelay = 1;
	      system ("awk -f " coverprog " \"$HOME/.plait/art.xml\" > \"$HOME/.plait/art.url\"");
	      close (p2);
	      getline image < p2;
	      images[url2] = image;
	    }

	  if (image != "No art available")
	    {
	      print "      <image>" image "</image>";
	    }
	}
      print "    </track>";
    }
  else
    {
      print "    <track>";
      print "      <annotation>" s "</annotation>";
      print "      <location>" s "</location>";
      print "    </track>";
    }
}


END {
  print "  </trackList>";
  print "</playlist>";
}