added current track
[radio.git] / mp3tohtml.py
1 #!/usr/bin/python
2
3 # mp3tohtml.py <mp3_dir>
4
5 import glob
6 import sys
7 import eyeD3
8
9 if len(sys.argv) != 2:
10     exit(1)
11
12 files = glob.glob(sys.argv[1] + "/**/*mp3")
13
14 print "<html>"
15 print "<head>"
16 print "<title>List of songs</title>"
17
18 print " <link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css\">"
19 print "<script type=\"text/javascript\" language=\"javascript\" src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js\">"
20 print " </script>"
21 print " <script type=\"text/javascript\" language=\"javascript\" src=\"https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js\">"
22 print " </script>"
23 print "<script>$(document).ready(function() { $('#songs').DataTable(); } );</script>"
24 print "</head>"
25
26 print "<body><h1>List of songs</h1>"
27
28 print "<table id='songs' class='display compact' width='100%'>"
29 print "<thead><tr><th>Artist</th><th>Album</th><th>Title</th><th>Comments</th></tr></thead>"
30 for f in files:
31     tag = eyeD3.Tag()
32
33     tag.link(f)
34
35     print "\t<tr>"
36
37     try: 
38         artist = tag.getArtist()
39         print "\t\t<td>" + artist + "</td>"       
40     except UnicodeEncodeError:
41         print "\t\t<td></td>"
42
43     try:        
44         print "\t\t<td>" + tag.getAlbum() + "</td>"
45     except UnicodeEncodeError:
46         print "\t\t<td></td>"
47
48     try:
49         print "\t\t<td>" + tag.getTitle() + "</td>"
50     except UnicodeEncodeError:
51         print "\t\t<td></td>"
52
53     print "\t\t<td>"
54     comments = tag.getComments()
55     for c in comments:
56         print comments[0].comment
57     print "\t\t</td>"
58
59     print "\t</tr>"
60
61 print "</table>"
62     
63 print "</body></html>"