fixed permissions
[mp3tohtml.git] / scripts / mp3tohtml
1 #!/usr/bin/python2
2
3 # usage: mp3tohtml.py [-h] [--config CONFIG] dir
4 #
5 # Generate an HTML containing information about the MP3 files.
6 #
7 # positional arguments:
8 #  dir              The directory containing the MP3 files
9 #
10 # optional arguments:
11 #  -h, --help       show this help message and exit
12 #  --config CONFIG  The directory containing the configuration
13 #
14 # Last version of this tool can be get from the GIT repository:
15 # http://wpitchoune.net/mp3tohtml
16 #
17 # http://wpitchoune.net/mp3tohtml
18 # Released under the terms of the GPLv2 license.
19 # (c) 2016 Jean-Philippe Orsini <jeanfi@gmail.com>
20
21 import mp3tohtml
22
23
24 parser = argparse.ArgumentParser(description='Generate an HTML containing information about the MP3 files.')
25 parser.add_argument('dir', help='The directory containing the MP3 files')
26 parser.add_argument("--config", help="The directory containing the configuration")
27
28 args = parser.parse_args()
29
30 if (args.config is None):
31     cfg_dir = os.path.dirname(sys.argv[0])
32 else:
33     cfg_dir = args.config
34
35 copy_header(cfg_dir)
36
37 files = []
38 for root, dirnames, filenames in os.walk(args.dir):
39     for filename in fnmatch.filter(filenames, '*.mp3'):
40         files.append(os.path.join(root, filename))
41
42 for f in files:
43     tag = eyeD3.Tag()
44
45     tag.link(f)
46
47     print("\t<tr>")
48
49     print("\t\t<td>" + tag.getArtist().encode("UTF8") + "</td>\n")
50     print("\t\t<td>" + tag.getAlbum().encode("UTF-8") + "</td>")
51     print("\t\t<td>" + tag.getTitle().encode("UTF-8") + "</td>")
52
53     comments = tag.getComments()
54     strComments = ""
55     for c in comments:
56         strComments += c.comment
57
58     p = re.compile("URL: (.*)\r\nComments: (.*)\r\nCurators?: (.*)\r\nCopyright: (.*)")
59     m = p.match(strComments)
60
61     if m is None:
62         url = ""
63         curator = ""
64         copyright = ""
65     else:
66         if m.group(2) == "http://freemusicarchive.org/":
67             strComments = ""
68             url = "<a href=\"" + m.group(1) + "\">FMA</a>"
69         else:
70             strComments =  m.group(2)
71             url = "<a href=\"" + m.group(1) + "\">source</a>"
72
73         curator = m.group(3)
74
75         copyright = fma_copyright_to_html(f, m.group(4))
76
77     print("\t\t<td>" + url + "</td>")
78     print("\t\t<td>" + curator + "</td>")
79     print("\t\t<td>" + copyright + "</td>")
80     print("\t\t<td>" + strComments + "</td>")
81
82     print("\t</tr>")
83
84 copy_footer(cfg_dir)