use datatables.net
[radio.git] / mp3tohtml.py
1 #!/usr/bin/python
2
3 import glob
4 import sys
5 import eyeD3
6
7 if len(sys.argv) != 2:
8     exit(1)
9
10 files = glob.glob(sys.argv[1] + "/**/*mp3")
11
12 print "<html>"
13 print "<head>"
14 print "<title>List of songs</title>"
15
16 print " <link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css\">"
17 print "<script type=\"text/javascript\" language=\"javascript\" src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js\">"
18 print " </script>"
19 print " <script type=\"text/javascript\" language=\"javascript\" src=\"https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js\">"
20 print " </script>"
21 print "<script>$(document).ready(function() { $('#songs').DataTable(); } );</script>"
22 print "</head>"
23
24 print "<body><h1>List of songs</h1>"
25
26 print "<table id='songs' class='display compact' width='100%'>"
27 print "<thead><tr><th>Artist</th><th>Album</th><th>Title</th><th>Comments</th></tr></thead>"
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     
61 print "</body></html>"