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>
22 def fma_copyright_to_html(path, copyright):
24 sys.stderr.write(path + ": no FMA copyright.\n")
27 p = re.compile("(.*): (.*)")
28 m = p.match(copyright)
31 name = name.replace("Creative Commons", "CC")
32 name = name.replace("Attribution", "BY")
33 name = name.replace("NonCommercial", "NC")
34 name = name.replace("Noncommercial", "NC")
35 name = name.replace("NoDerivatives", "ND")
36 name = name.replace("ShareAlike", "SA")
37 name = name.replace("Share Alike", "SA")
38 name = name.replace("United States", "US")
39 return "<a href=\"" + m.group(2) + "\">" + name + "</a>"
41 sys.stderr.write(path + ": invalid FMA copyright: "
45 def copy_header(path):
46 header_path = os.path.dirname(path) + "/header.tpl"
47 header = open(header_path, "r")
49 sys.stdout.write(line)
51 def copy_footer(path):
52 footer_path = os.path.dirname(path) + "/footer.tpl"
53 footer = open(footer_path, "r")
55 sys.stdout.write(line)
57 parser = argparse.ArgumentParser(description='Generate an HTML containing information about the MP3 files.')
58 parser.add_argument('dir', help='The directory containing the MP3 files')
60 args = parser.parse_args()
67 for root, dirnames, filenames in os.walk(args.dir):
68 for filename in fnmatch.filter(filenames, '*.mp3'):
69 files.append(os.path.join(root, filename))
78 print("\t\t<td>" + tag.getArtist().encode("UTF8") + "</td>\n")
79 print("\t\t<td>" + tag.getAlbum().encode("UTF-8") + "</td>")
80 print("\t\t<td>" + tag.getTitle().encode("UTF-8") + "</td>")
82 comments = tag.getComments()
85 strComments += c.comment
87 p = re.compile("URL: (.*)\r\nComments: (.*)\r\nCurators?: (.*)\r\nCopyright: (.*)")
88 m = p.match(strComments)
95 if m.group(2) == "http://freemusicarchive.org/":
97 url = "<a href=\"" + m.group(1) + "\">FMA</a>"
99 strComments = m.group(2)
100 url = "<a href=\"" + m.group(1) + "\">source</a>"
104 copyright = fma_copyright_to_html(f, m.group(4))
106 print("\t\t<td>" + url + "</td>")
107 print("\t\t<td>" + curator + "</td>")
108 print("\t\t<td>" + copyright + "</td>")
109 print("\t\t<td>" + strComments + "</td>")