3 # usage: mp3tohtml.py [-h] [--config CONFIG] dir
5 # Generate an HTML containing information about the MP3 files.
7 # positional arguments:
8 # dir The directory containing the MP3 files
11 # -h, --help show this help message and exit
12 # --config CONFIG The directory containing the configuration
14 # Last version of this tool can be get from the GIT repository:
15 # http://wpitchoune.net/mp3tohtml
17 # Released under the terms of the GPLv2 license.
18 # (c) 2016 Jean-Philippe Orsini <jeanfi@gmail.com>
28 def fma_copyright_to_html(path, copyright):
30 sys.stderr.write(path + ": no FMA copyright.\n")
33 p = re.compile("(.*): (.*)")
34 m = p.match(copyright)
37 name = name.replace("Creative Commons", "CC")
38 name = name.replace("Attribution", "BY")
39 name = name.replace("NonCommercial", "NC")
40 name = name.replace("Noncommercial", "NC")
41 name = name.replace("NoDerivatives", "ND")
42 name = name.replace("ShareAlike", "SA")
43 name = name.replace("Share Alike", "SA")
44 name = name.replace("United States", "US")
45 return "<a href=\"" + m.group(2) + "\">" + name + "</a>"
47 sys.stderr.write(path + ": invalid FMA copyright: "
51 def copy_header(path):
52 header_path = path + "/header.tpl"
53 header = open(header_path, "r")
55 sys.stdout.write(line)
57 def copy_footer(path):
58 footer_path = path + "/footer.tpl"
59 footer = open(footer_path, "r")
61 sys.stdout.write(line)
63 parser = argparse.ArgumentParser(description='Generate an HTML containing information about the MP3 files.')
64 parser.add_argument('dir', help='The directory containing the MP3 files')
65 parser.add_argument("--config", help="The directory containing the configuration")
67 args = parser.parse_args()
69 if (args.config is None):
70 cfg_dir = os.path.dirname(sys.argv[0])
77 for root, dirnames, filenames in os.walk(args.dir):
78 for filename in fnmatch.filter(filenames, '*.mp3'):
79 files.append(os.path.join(root, filename))
88 print("\t\t<td>" + tag.getArtist().encode("UTF8") + "</td>\n")
89 print("\t\t<td>" + tag.getAlbum().encode("UTF-8") + "</td>")
90 print("\t\t<td>" + tag.getTitle().encode("UTF-8") + "</td>")
92 comments = tag.getComments()
95 strComments += c.comment
97 p = re.compile("URL: (.*)\r\nComments: (.*)\r\nCurators?: (.*)\r\nCopyright: (.*)")
98 m = p.match(strComments)
105 if m.group(2) == "http://freemusicarchive.org/":
107 url = "<a href=\"" + m.group(1) + "\">FMA</a>"
109 strComments = m.group(2)
110 url = "<a href=\"" + m.group(1) + "\">source</a>"
114 copyright = fma_copyright_to_html(f, m.group(4))
116 print("\t\t<td>" + url + "</td>")
117 print("\t\t<td>" + curator + "</td>")
118 print("\t\t<td>" + copyright + "</td>")
119 print("\t\t<td>" + strComments + "</td>")