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>
21 def fma_copyright_to_html(path, copyright):
23 sys.stderr.write(path + ": no FMA copyright.\n")
26 p = re.compile("(.*): (.*)")
27 m = p.match(copyright)
30 name = name.replace("Creative Commons", "CC")
31 name = name.replace("Attribution", "BY")
32 name = name.replace("NonCommercial", "NC")
33 name = name.replace("Noncommercial", "NC")
34 name = name.replace("NoDerivatives", "ND")
35 name = name.replace("ShareAlike", "SA")
36 name = name.replace("Share Alike", "SA")
37 name = name.replace("United States", "US")
38 return "<a href=\"" + m.group(2) + "\">" + name + "</a>"
40 sys.stderr.write(path + ": invalid FMA copyright: "
44 def copy_header(path):
45 header_path = path + "/header.tpl"
46 header = open(header_path, "r")
48 sys.stdout.write(line)
50 def copy_footer(path):
51 footer_path = path + "/footer.tpl"
52 footer = open(footer_path, "r")
54 sys.stdout.write(line)
56 parser = argparse.ArgumentParser(description='Generate an HTML containing information about the MP3 files.')
57 parser.add_argument('dir', help='The directory containing the MP3 files')
58 parser.add_argument("--config", help="The directory containing the configuration")
60 args = parser.parse_args()
62 if (args.config is None):
63 cfg_dir = os.path.dirname(sys.argv[0])
70 for root, dirnames, filenames in os.walk(args.dir):
71 for filename in fnmatch.filter(filenames, '*.mp3'):
72 files.append(os.path.join(root, filename))
81 print("\t\t<td>" + tag.getArtist().encode("UTF8") + "</td>\n")
82 print("\t\t<td>" + tag.getAlbum().encode("UTF-8") + "</td>")
83 print("\t\t<td>" + tag.getTitle().encode("UTF-8") + "</td>")
85 comments = tag.getComments()
88 strComments += c.comment
90 p = re.compile("URL: (.*)\r\nComments: (.*)\r\nCurators?: (.*)\r\nCopyright: (.*)")
91 m = p.match(strComments)
98 if m.group(2) == "http://freemusicarchive.org/":
100 url = "<a href=\"" + m.group(1) + "\">FMA</a>"
102 strComments = m.group(2)
103 url = "<a href=\"" + m.group(1) + "\">source</a>"
107 copyright = fma_copyright_to_html(f, m.group(4))
109 print("\t\t<td>" + url + "</td>")
110 print("\t\t<td>" + curator + "</td>")
111 print("\t\t<td>" + copyright + "</td>")
112 print("\t\t<td>" + strComments + "</td>")