updated
[mp3tohtml.git] / mp3tohtml / mp3tohtml.py
1 #!/usr/bin/python2
2
3 # http://wpitchoune.net/mp3tohtml
4 # Released under the terms of the GPLv2 license.
5 # (c) 2016 Jean-Philippe Orsini <jeanfi@gmail.com>
6
7 import argparse
8 import eyeD3
9 import fnmatch
10 import glob
11 import os
12 import re
13 import sys
14
15 def fma_copyright_to_html(path, copyright):
16     if copyright == "":
17         sys.stderr.write(path + ": no FMA copyright.\n")
18         return ""
19
20     p = re.compile("(.*): (.*)")
21     m = p.match(copyright)
22     if m is not None:
23         name = m.group(1)
24         name = name.replace("Creative Commons", "CC")
25         name = name.replace("Attribution", "BY")
26         name = name.replace("NonCommercial", "NC")
27         name = name.replace("Noncommercial", "NC")
28         name = name.replace("NoDerivatives", "ND")
29         name = name.replace("ShareAlike", "SA")
30         name = name.replace("Share Alike", "SA")
31         name = name.replace("United States", "US")
32         return "<a href=\"" + m.group(2) + "\">" + name + "</a>"
33     else:
34         sys.stderr.write(path + ": invalid FMA copyright: "
35                          + copyright + ".\n");
36         return copyright
37
38 def copy_header(path):
39     header_path = path + "/header.tpl"
40     try:
41         header = open(header_path, "r")
42         for line in header:
43             sys.stdout.write(line)
44         header.close()
45     except IOError as e:
46         sys.stderr.write("Failed to read header file "
47                          + header_path
48                          + ": " + e.strerror + "\n")
49         raise
50
51 def copy_footer(path):
52     footer_path = path + "/footer.tpl"
53     try:
54         footer = open(footer_path, "r")
55         for line in footer:
56             sys.stdout.write(line)
57         footer.close()
58     except IOError as e:
59         sys.stderr.write("Failed to read footer file "
60                          + footer_path
61                          + ": " + e.strerror + "\n")
62         raise