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>
20 def fma_copyright_to_html(path, copyright):
22 sys.stderr.write(path + ": no FMA copyright.\n")
25 p = re.compile("(.*): (.*)")
26 m = p.match(copyright)
29 name = name.replace("Creative Commons", "CC")
30 name = name.replace("Attribution", "BY")
31 name = name.replace("NonCommercial", "NC")
32 name = name.replace("Noncommercial", "NC")
33 name = name.replace("NoDerivatives", "ND")
34 name = name.replace("ShareAlike", "SA")
35 name = name.replace("Share Alike", "SA")
36 name = name.replace("United States", "US")
37 return "<a href=\"" + m.group(2) + "\">" + name + "</a>"
39 sys.stderr.write(path + ": invalid FMA copyright: "
43 def copy_header(path):
44 header_path = os.path.dirname(path) + "/header.tpl"
45 header = open(header_path, "r")
47 sys.stdout.write(line)
49 parser = argparse.ArgumentParser(description='Generate an HTLM containing information about the MP3 files.')
50 parser.add_argument('dir', help='The directory containing the MP3 files')
52 args = parser.parse_args()
54 copy_header(sys.argv[0])
56 files = glob.iglob(args.dir + "/**/*mp3")
65 print("\t\t<td>" + tag.getArtist().encode("UTF8") + "</td>\n")
66 print("\t\t<td>" + tag.getAlbum().encode("UTF-8") + "</td>")
67 print("\t\t<td>" + tag.getTitle().encode("UTF-8") + "</td>")
69 comments = tag.getComments()
72 strComments += c.comment
74 p = re.compile("URL: (.*)\r\nComments: (.*)\r\nCurators?: (.*)\r\nCopyright: (.*)")
75 m = p.match(strComments)
82 if m.group(2) == "http://freemusicarchive.org/":
84 url = "<a href=\"" + m.group(1) + "\">FMA</a>"
86 strComments = m.group(2)
87 url = "<a href=\"" + m.group(1) + "\">source</a>"
91 copyright = fma_copyright_to_html(f, m.group(4))
93 print("\t\t<td>" + url + "</td>")
94 print("\t\t<td>" + curator + "</td>")
95 print("\t\t<td>" + copyright + "</td>")
96 print("\t\t<td>" + strComments + "</td>")
103 print (" <li><a href=\"mailto:proxyradio@wpitchoune.net\">Contact</a></li>")
106 print( "</body></html>")