3 # Generate an HTML page containing information about MP3s in a
6 # Usage: mp3tohtml.py <mp3_dir>
8 # Last version of this tool can be get from the GIT repository:
9 # http://git.wpitchoune.net/radio.git
11 # (c) 2016 Jean-Philippe Orsini <jeanfi@gmail.com>
19 def fma_copyright_to_html(path, copyright):
21 sys.stderr.write(path + ": no FMA copyright.\n")
24 p = re.compile("(.*): (.*)")
25 m = p.match(copyright)
28 name = name.replace("Creative Commons", "CC")
29 name = name.replace("Attribution", "BY")
30 name = name.replace("NonCommercial", "NC")
31 name = name.replace("Noncommercial", "NC")
32 name = name.replace("NoDerivatives", "ND")
33 name = name.replace("ShareAlike", "SA")
34 name = name.replace("Share Alike", "SA")
35 name = name.replace("United States", "US")
36 return "<a href=\"" + m.group(2) + "\">" + name + "</a>"
38 sys.stderr.write(path + ": invalid FMA copyright: "
42 if len(sys.argv) != 2:
43 sys.stderr.write("Usage: mp3tohtml.py <mp3_dir>\n")
46 header_path = os.path.dirname(sys.argv[0]) + "/header.tpl"
47 header = open(header_path, "r")
49 sys.stdout.write(line)
51 files = glob.glob(sys.argv[1] + "/**/*mp3")
60 print "\t\t<td>" + tag.getArtist().encode("UTF8") + "</td>\n"
61 print "\t\t<td>" + tag.getAlbum().encode("UTF-8") + "</td>"
62 print "\t\t<td>" + tag.getTitle().encode("UTF-8") + "</td>"
64 comments = tag.getComments()
67 strComments += c.comment
69 p = re.compile("URL: (.*)\r\nComments: (.*)\r\nCurators?: (.*)\r\nCopyright: (.*)")
70 m = p.match(strComments)
77 if m.group(2) == "http://freemusicarchive.org/":
79 url = "<a href=\"" + m.group(1) + "\">FMA</a>"
81 strComments = m.group(2)
82 url = "<a href=\"" + m.group(1) + "\">source</a>"
86 copyright = fma_copyright_to_html(f, m.group(4))
88 print "\t\t<td>" + url + "</td>"
89 print "\t\t<td>" + curator + "</td>"
90 print "\t\t<td>" + copyright + "</td>"
91 print "\t\t<td>" + strComments + "</td>"
98 print " <li><a href=\"mailto:proxyradio@wpitchoune.net\">Contact</a></li>"
101 print "</body></html>"