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(copyright):
20 p = re.compile("(.*): (.*)")
21 m = p.match(copyright)
24 name = name.replace("Creative Commons", "CC")
25 name = name.replace("Attribution", "BY")
26 name = name.replace("NonCommercial", "NC")
27 name = name.replace("NoDerivatives", "ND")
28 name = name.replace("ShareAlike", "SA")
29 return "<a href=\"" + m.group(2) + "\">" + name + "</a>"
33 if len(sys.argv) != 2:
34 sys.stderr.write("Usage: mp3tohtml.py <mp3_dir>\n")
37 header_path = os.path.dirname(sys.argv[0]) + "/header.tpl"
38 header = open(header_path, "r")
40 sys.stdout.write(line)
42 files = glob.glob(sys.argv[1] + "/**/*mp3")
52 artist = tag.getArtist()
53 print "\t\t<td>" + artist + "</td>"
54 except UnicodeEncodeError:
58 print "\t\t<td>" + tag.getAlbum() + "</td>"
59 except UnicodeEncodeError:
63 print "\t\t<td>" + tag.getTitle() + "</td>"
64 except UnicodeEncodeError:
68 comments = tag.getComments()
71 strComments += c.comment
73 p = re.compile("URL: (.*)\r\nComments: (.*)\r\nCurators?: (.*)\r\nCopyright: (.*)")
74 m = p.match(strComments)
81 if m.group(2) == "http://freemusicarchive.org/":
83 url = "<a href=\"" + m.group(1) + "\">FMA</a>"
85 strComments = m.group(2)
86 url = "<a href=\"" + m.group(1) + "\">source</a>"
90 copyright = fma_copyright_to_html(m.group(4))
92 print "\t\t<td>" + url + "</td>"
93 print "\t\t<td>" + curator + "</td>"
94 print "\t\t<td>" + copyright + "</td>"
95 print "\t\t<td>" + strComments + "</td>"
102 print " <li><a href=\"mailto:proxyradio@wpitchoune.net\">Contact</a></li>"
105 print "</body></html>"