fixed links nav
[radio.git] / mp3tohtml.py
1 #!/usr/bin/python
2
3 # Generate an HTML page containing information about MP3s in a
4 # directory.
5 #
6 # Usage: mp3tohtml.py <mp3_dir>
7 #
8 # Last version of this tool can be get from the GIT repository:
9 # http://git.wpitchoune.net/radio.git
10 #
11 # (c) 2015 Jean-Philippe Orsini  <jeanfi@gmail.com>
12
13 import glob
14 import sys
15 import eyeD3
16 import os.path
17
18 if len(sys.argv) != 2:
19     exit(1)
20
21 header_path = os.path.dirname(sys.argv[0]) + "/header.tpl"
22 header = open(header_path, "r")
23 for line in header:
24     sys.stdout.write(line)
25
26 files = glob.glob(sys.argv[1] + "/**/*mp3")
27
28 for f in files:
29     tag = eyeD3.Tag()
30
31     tag.link(f)
32
33     print "\t<tr>"
34
35     try:
36         artist = tag.getArtist()
37         print "\t\t<td>" + artist + "</td>"
38     except UnicodeEncodeError:
39         print "\t\t<td></td>"
40
41     try:
42         print "\t\t<td>" + tag.getAlbum() + "</td>"
43     except UnicodeEncodeError:
44         print "\t\t<td></td>"
45
46     try:
47         print "\t\t<td>" + tag.getTitle() + "</td>"
48     except UnicodeEncodeError:
49         print "\t\t<td></td>"
50
51     print "\t\t<td>"
52     comments = tag.getComments()
53     for c in comments:
54         print comments[0].comment
55     print "\t\t</td>"
56
57     print "\t</tr>"
58
59 print "</table>"
60 print "<footer>"
61 print "            <ul>"
62 print "                    <li><a href=\"mailto:proxyradio@wpitchoune.net\">Contact</a></li>"
63 print "            </ul>"
64 print "</footer>"
65 print "</body></html>"