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"
54 header = open(header_path, "r")
56 sys.stdout.write(line)
59 sys.stderr.write("Failed to read header file "
61 + ": " + e.strerror + "\n")
64 def copy_footer(path):
65 footer_path = path + "/footer.tpl"
67 footer = open(footer_path, "r")
69 sys.stdout.write(line)
72 sys.stderr.write("Failed to read footer file "
74 + ": " + e.strerror + "\n")
77 parser = argparse.ArgumentParser(description='Generate an HTML containing information about the MP3 files.')
78 parser.add_argument('dir', help='The directory containing the MP3 files')
79 parser.add_argument("--config", help="The directory containing the configuration")
81 args = parser.parse_args()
83 if (args.config is None):
84 cfg_dir = os.path.dirname(sys.argv[0])
91 for root, dirnames, filenames in os.walk(args.dir):
92 for filename in fnmatch.filter(filenames, '*.mp3'):
93 files.append(os.path.join(root, filename))
102 print("\t\t<td>" + tag.getArtist().encode("UTF8") + "</td>\n")
103 print("\t\t<td>" + tag.getAlbum().encode("UTF-8") + "</td>")
104 print("\t\t<td>" + tag.getTitle().encode("UTF-8") + "</td>")
106 comments = tag.getComments()
109 strComments += c.comment
111 p = re.compile("URL: (.*)\r\nComments: (.*)\r\nCurators?: (.*)\r\nCopyright: (.*)")
112 m = p.match(strComments)
119 if m.group(2) == "http://freemusicarchive.org/":
121 url = "<a href=\"" + m.group(1) + "\">FMA</a>"
123 strComments = m.group(2)
124 url = "<a href=\"" + m.group(1) + "\">source</a>"
128 copyright = fma_copyright_to_html(f, m.group(4))
130 print("\t\t<td>" + url + "</td>")
131 print("\t\t<td>" + curator + "</td>")
132 print("\t\t<td>" + copyright + "</td>")
133 print("\t\t<td>" + strComments + "</td>")