#!/usr/bin/python #Credits: Original version: John C. Spray #Modifications: Daelstorm import sys, os, re, getopt def usage(): print ("""M3U to HTML conversion - Author: Daelstorm Options: m3u2html-dael.py [OPTION]... Default options: --output=playlist.html Output HTML file > playlist.html Pipe to output file --input=playlist.m3u Input M3U file --body-background= Default: (black) --link= Default: (001111) --font-color= Default: (white) --table-background= Default: (219191) --table-border-color= Default: (555555) --table-border-width= Default: (1px) --table-border-style= Default: (solid) --number-width= Default: (30px) --number-font-color= Default: (white) --number-font-weight= Default: (bold) --number-align= Default: (right) --number-background= Default: (015151) --item-border-color= Default: (black) --item-border-width= Default: (1px) --item-border-style= Default: (dotted) --item-font-color= Default: (white) --item-font-weight= Default: (bold) --item-align= Default: (left) -h, --help Display this help and exit """) sys.exit(2) titlename="" lines="" outputfile="" body_background = "000000" link = "001111" font_color = "ffffff" table_background = "219191" table_border_color = "555555" table_border_width = "1px" table_border_style = "solid" number_width = "30px" number_font_color = "FFFFFF" number_font_weight = "bold" number_align = "right" number_background_color = "015151" item_border_color = "black" item_border_width = "1px" item_border_style = "dotted" item_font_color = "ffffff" item_font_weight = "bold" item_align = "left" if len(sys.argv)<2: print "Insufficient arguments!" usage() sys.exit() try: opts, args = getopt.getopt(sys.argv[1:], "h", ["help", "output=", "input=", "body-background=", "link=", "font-color=", "table-background=", "table-border-color=", "table-border-width=", "table-border-style=", "number-width=", "number-font-color=", "number-font-weight=", "number-align=", "number-background=", "item-border-color=", "item-border-width=", "item-border-style=", "item-font-color=", "item-font-weight=", "item-align="]) except getopt.GetoptError: # print help information and exit: usage() sys.exit(2) for opts, args in opts: if opts in ("-h", "--help"): usage() sys.exit() if opts in ( "--input"): try: lines=open(args).readlines() titlename = args except: print "Unable to open file '%s'!" % args sys.exit() if opts in ( "--output"): output = os.path.expanduser(args) outputfile = open(output, 'w') if opts in ( "--body-background"): body_background = args if opts in ( "--link"): link = args if opts in ( "--font-color"): font_color =args if opts in ( "--table-background"): table_background = args if opts in ( "--table-border-color"): table_border_color = args if opts in ( "--table-border-width"): table_border_width = args if opts in ( "--table-border-style"): table_border_style = args if opts in ( "--number-width"): number_width = args if opts in ( "--number-font-color"): number_font_color =args if opts in ( "--number-font-weight"): number_font_weight = args if opts in ( "--number-align"): number_align = args if opts in ( "--number-background"): number_background_color = args if opts in ( "--item-border-color"): item_border_color =args if opts in ( "--item-border-width"): item_border_width = args if opts in ( "--item-border-style"): item_border_style = args if opts in ( "--item-font-color"): item_font_color = args if opts in ( "--item-font-weight"): item_font_weight =args if opts in ( "--item-align"): item_align =args header= "
| Num | \nFilename \n | " + str(number) + " | "% (line, line) if outputfile == "": print item elif outputfile != "": print >> outputfile, item # End hack else: try: filename=re.search("/([^/]*)$",line).group()[1:]; # cut "prefix/" off except: continue # Ignore this line number = number +1 item = " | "+ str(number) + " | " % (line, filename) if outputfile == "": print item elif outputfile != "": print >> outputfile, item footer= " |
Generated by m3u2html-1.0.py
" if outputfile == "": print footer elif outputfile != "": print >> outputfile, footer