added footer
[radio.git] / mp3tohtml.py
1 #!/usr/bin/python
2
3 # Generate an HTML page containing information about
4 # MP3s in a directory.
5 #
6 # Usage: mp3tohtml.py <mp3_dir>
7 #
8 # Last version of this tool can be get from the GIT repository http://git.wpitchoune.net/radio.git
9 #
10 # (c) 2015 Jean-Philippe Orsini  <jeanfi@gmail.com>
11
12 import glob
13 import sys
14 import eyeD3
15
16 if len(sys.argv) != 2:
17     exit(1)
18
19 files = glob.glob(sys.argv[1] + "/**/*mp3")
20
21 print "<html>"
22 print "<head>"
23 print "<title>All songs</title>"
24
25 print " <link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css\">"
26 print "<script type=\"text/javascript\" language=\"javascript\" src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js\">"
27 print " </script>"
28 print " <script type=\"text/javascript\" language=\"javascript\" src=\"https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js\">"
29 print " </script>"
30 print "<script>$(document).ready(function() { $('#songs').DataTable(); } );</script>"
31 print "</head>"
32
33 print "<body><h1>List of songs</h1>"
34
35 print "<table id='songs' class='display compact' width='100%'>"
36 print "<thead><tr><th>Artist</th><th>Album</th><th>Title</th><th>Comments</th></tr></thead>"
37 for f in files:
38     tag = eyeD3.Tag()
39
40     tag.link(f)
41
42     print "\t<tr>"
43
44     try:
45         artist = tag.getArtist()
46         print "\t\t<td>" + artist + "</td>"
47     except UnicodeEncodeError:
48         print "\t\t<td></td>"
49
50     try:
51         print "\t\t<td>" + tag.getAlbum() + "</td>"
52     except UnicodeEncodeError:
53         print "\t\t<td></td>"
54
55     try:
56         print "\t\t<td>" + tag.getTitle() + "</td>"
57     except UnicodeEncodeError:
58         print "\t\t<td></td>"
59
60     print "\t\t<td>"
61     comments = tag.getComments()
62     for c in comments:
63         print comments[0].comment
64     print "\t\t</td>"
65
66     print "\t</tr>"
67
68 print "</table>"
69 print "<footer>"
70 print "            <ul>"
71 print "                    <li><a href=\"mailto:proxyradio@wpitchoune.net\">Contact</a></li>"
72 print "            </ul>"
73 print "</footer>"
74 print "</body></html>"