7a030ac9fee4601209043885d74c88b07f05bf11
[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
17 if len(sys.argv) != 2:
18     exit(1)
19
20 files = glob.glob(sys.argv[1] + "/**/*mp3")
21
22 print "<html>"
23 print "<head>"
24 print "<title>All songs</title>"
25
26 print " <link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css\">"
27 print "<script type=\"text/javascript\" language=\"javascript\" src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js\">"
28 print " </script>"
29 print " <script type=\"text/javascript\" language=\"javascript\" src=\"https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js\">"
30 print " </script>"
31 print "<script>$(document).ready(function() { $('#songs').DataTable(); } );</script>"
32 print "</head>"
33
34 print "<body><h1>List of songs</h1>"
35
36 print "<table id='songs' class='display compact' width='100%'>"
37 print "<thead><tr><th>Artist</th><th>Album</th><th>Title</th><th>Comments</th></tr></thead>"
38 for f in files:
39     tag = eyeD3.Tag()
40
41     tag.link(f)
42
43     print "\t<tr>"
44
45     try:
46         artist = tag.getArtist()
47         print "\t\t<td>" + artist + "</td>"
48     except UnicodeEncodeError:
49         print "\t\t<td></td>"
50
51     try:
52         print "\t\t<td>" + tag.getAlbum() + "</td>"
53     except UnicodeEncodeError:
54         print "\t\t<td></td>"
55
56     try:
57         print "\t\t<td>" + tag.getTitle() + "</td>"
58     except UnicodeEncodeError:
59         print "\t\t<td></td>"
60
61     print "\t\t<td>"
62     comments = tag.getComments()
63     for c in comments:
64         print comments[0].comment
65     print "\t\t</td>"
66
67     print "\t</tr>"
68
69 print "</table>"
70 print "<footer>"
71 print "            <ul>"
72 print "                    <li><a href=\"mailto:proxyradio@wpitchoune.net\">Contact</a></li>"
73 print "            </ul>"
74 print "</footer>"
75 print "</body></html>"