3 # http://wpitchoune.net/mp3tohtml
4 # Released under the terms of the GPLv2 license.
5 # (c) 2016 Jean-Philippe Orsini <jeanfi@gmail.com>
14 def fma_copyright_to_html(path, copyright):
16 sys.stderr.write(path + ": no FMA copyright.\n")
19 p = re.compile("(.*): (.*)")
20 m = p.match(copyright)
23 name = name.replace("Creative Commons", "CC")
24 name = name.replace("Attribution", "BY")
25 name = name.replace("NonCommercial", "NC")
26 name = name.replace("Noncommercial", "NC")
27 name = name.replace("NoDerivatives", "ND")
28 name = name.replace("ShareAlike", "SA")
29 name = name.replace("Share Alike", "SA")
30 name = name.replace("United States", "US")
31 return "<a href=\"" + m.group(2) + "\">" + name + "</a>"
33 sys.stderr.write(path + ": invalid FMA copyright: "
37 def copy_header(path):
38 header_path = path + "/header.tpl"
40 header = open(header_path, "r")
42 sys.stdout.write(line)
45 sys.stderr.write("Failed to read header file "
47 + ": " + e.strerror + "\n")
50 def copy_footer(path):
51 footer_path = path + "/footer.tpl"
53 footer = open(footer_path, "r")
55 sys.stdout.write(line)
58 sys.stderr.write("Failed to read footer file "
60 + ": " + e.strerror + "\n")
63 def generate(mp3_dir, cfg_dir):
67 for root, dirnames, filenames in os.walk(mp3_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>")