X-Git-Url: https://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=mp3tohtml.py;h=370cb1fbb2a3eaf3cf139da7b58f53ea9f52aac4;hb=3d882ae64a2da3b3c64bce895de02dee3a9541d8;hp=c4432f0d8e5e34b5863ba8f08369a95a1371c04e;hpb=9d21881db0a783f008952b5372e34b0fce08f005;p=radio.git diff --git a/mp3tohtml.py b/mp3tohtml.py index c4432f0..370cb1f 100755 --- a/mp3tohtml.py +++ b/mp3tohtml.py @@ -1,30 +1,46 @@ #!/usr/bin/python +# Generate an HTML page containing information about MP3s in a +# directory. +# +# Usage: mp3tohtml.py +# +# Last version of this tool can be get from the GIT repository: +# http://git.wpitchoune.net/radio.git +# +# (c) 2016 Jean-Philippe Orsini + +import eyeD3 import glob +import os.path +import re import sys -import eyeD3 + +def fma_copyright_to_html(copyright): + p = re.compile("(.*): (.*)") + m = p.match(copyright) + if m is not None: + name = m.group(1) + name = name.replace("Creative Commons", "CC") + name = name.replace("Attribution", "BY") + name = name.replace("NonCommercial", "NC") + name = name.replace("NoDerivatives", "ND") + name = name.replace("ShareAlike", "SA") + return "" + name + "" + else: + return copyright if len(sys.argv) != 2: + sys.stderr.write("Usage: mp3tohtml.py \n") exit(1) -files = glob.glob(sys.argv[1] + "/**/*mp3") - -print "" -print "" -print "List of songs" +header_path = os.path.dirname(sys.argv[0]) + "/header.tpl" +header = open(header_path, "r") +for line in header: + sys.stdout.write(line) -print " " -print "" -print " " -print "" -print "" - -print "

List of songs

" +files = glob.glob(sys.argv[1] + "/**/*mp3") -print "" -print "" for f in files: tag = eyeD3.Tag() @@ -32,13 +48,13 @@ for f in files: print "\t" - try: + try: artist = tag.getArtist() - print "\t\t" + print "\t\t" except UnicodeEncodeError: print "\t\t" - try: + try: print "\t\t" except UnicodeEncodeError: print "\t\t" @@ -48,14 +64,42 @@ for f in files: except UnicodeEncodeError: print "\t\t" - print "\t\t" + strComments += c.comment + + p = re.compile("URL: (.*)\r\nComments: (.*)\r\nCurators?: (.*)\r\nCopyright: (.*)") + m = p.match(strComments) + + if m is None: + url = "" + curator = "" + copyright = "" + else: + if m.group(2) == "http://freemusicarchive.org/": + strComments = "" + url = "FMA" + else: + strComments = m.group(2) + url = "source" + + curator = m.group(3) + + copyright = fma_copyright_to_html(m.group(4)) + + print "\t\t" + print "\t\t" + print "\t\t" + print "\t\t" print "\t" print "
ArtistAlbumTitleComments
" + artist + "" + artist + "" + tag.getAlbum() + "" + comments = tag.getComments() + strComments = "" for c in comments: - print comments[0].comment - print "\t\t" + url + "" + curator + "" + copyright + "" + strComments + "
" - +print "" print ""