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)
57 except IOError as err:
58 sys.stderr.write("Failed to read header file "
60 + ": " + err.strerror + "\n")
64 def copy_footer(path):
65 footer_path = path + "/footer.tpl"
67 footer = open(footer_path, "r")
69 sys.stdout.write(line)
70 except IOError as err:
71 sys.stderr.write("Failed to read footer file "
73 + ": " + err.strerror + "\n")
78 parser = argparse.ArgumentParser(description='Generate an HTML containing information about the MP3 files.')
79 parser.add_argument('dir', help='The directory containing the MP3 files')
80 parser.add_argument("--config", help="The directory containing the configuration")
82 args = parser.parse_args()
84 if (args.config is None):
85 cfg_dir = os.path.dirname(sys.argv[0])
92 for root, dirnames, filenames in os.walk(args.dir):
93 for filename in fnmatch.filter(filenames, '*.mp3'):
94 files.append(os.path.join(root, filename))
103 print("\t\t<td>" + tag.getArtist().encode("UTF8") + "</td>\n")
104 print("\t\t<td>" + tag.getAlbum().encode("UTF-8") + "</td>")
105 print("\t\t<td>" + tag.getTitle().encode("UTF-8") + "</td>")
107 comments = tag.getComments()
110 strComments += c.comment
112 p = re.compile("URL: (.*)\r\nComments: (.*)\r\nCurators?: (.*)\r\nCopyright: (.*)")
113 m = p.match(strComments)
120 if m.group(2) == "http://freemusicarchive.org/":
122 url = "<a href=\"" + m.group(1) + "\">FMA</a>"
124 strComments = m.group(2)
125 url = "<a href=\"" + m.group(1) + "\">source</a>"
129 copyright = fma_copyright_to_html(f, m.group(4))
131 print("\t\t<td>" + url + "</td>")
132 print("\t\t<td>" + curator + "</td>")
133 print("\t\t<td>" + copyright + "</td>")
134 print("\t\t<td>" + strComments + "</td>")