Skip to content

Instantly share code, notes, and snippets.

@danielpclark
Created September 1, 2012 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielpclark/3574431 to your computer and use it in GitHub Desktop.
Save danielpclark/3574431 to your computer and use it in GitHub Desktop.
MP3 Host is a autogenerated mp3 hoster.
#!/usr/bin/env python
# -----------------------------------------------------
# MP3 Host is created by Daniel P. Clark of 6ft Dan(TM)
# Version 0.1 Stable 02/27/2011
# email: webmaster@6ftdan.com
#
# Purpose: This web applications generates a web page on the fly with media
# content to share. Thus allowing you to place new files in subfolders and
# there is no need to update a web page. It's done automagically!
# Enjoy!!
#
# If you run into any errors check the python path, your file permisions, file mode,
# make sure the cgi script is in a folder that's allowed to execute cgi scripts,
# check the filename&url, and lastly make sure you have content in the same folder or
# subfolder that matches the file types you've defined.
#
# For changes please e-mail suggestions to webmaster@6ftdan.com
# -----------------------------------------------------
import os
#----------------------------------------------
###### Begin User Modification ######
#Define your base web url here with the folder that contains your MP3 content
#NOTE: Leave of the last forward slash /
path = "http://www.mysite.com/audiofolder"
#This is your media types you will be sharing. Must be seperated by a semicolon ;
pattern = "*.mp3;*.ogg"
## Color Scheme (You can use hex colors or color names such as "grey")
#Backgrounds
BackgroundColor = "#40D080"
HeaderBGColor = "#20B060"
LinkABGColor = "#00A050"
LinkBBGColor = "#20B060"
#Header Font Color
HeaderFGColor = "#EEEEFF"
##Content
#Page Title (You may insert an image here)
# EXAMPLE:
# PageTitle = "<img src='http://www.myurl.com/myimage.jpg' width=xxx height=xxx>"
PageTitle = "MP3 Host"
#Title Styles
TitleBGWidth = "486px"
TitleBGHeight = "84px"
TitleFontSize = "68px"
TitleFont = "times"
#Define any copyrights/media rights on the content you are sharing
MediaRights = "Copyright: Free to Listen/Do Not Modify or Reuse Content"
##Define wether you want current directory name to be used as a title for each sections content
#Must be either True or False (case sensitive)
ShowFolder = True
###### End User Modification ######
#--------------------------------------------
###### DO NOT MODIFY BEYOND THIS POINT ######
#Print files that match to file extensions
def printFiles(dirList, typeList):
for fileZ in dirList[2]:
for ext in typeList:
if fileZ.lower().endswith(ext.lower()):
# for alternating styles
if dirList[2].index(fileZ) % 2 == 0:
print "<div style='background-color:" + LinkABGColor + ";'><table border=0 width='100%'><tr><td><a href='" + str(dirList[0] + os.sep + fileZ).replace(" ","%20") + "'>" + fileZ + "</a></td><td align='right'>size: " + str(os.path.getsize(dirList[0]+os.sep+fileZ)/1024/1024) + "Mb</td></tr></table></div>\n"
else: # Even index, different div (for css style)
print "<div style='background-color:" + LinkBBGColor + ";'><table border=0 width='100%'><tr><td><a href='" + str(dirList[0] + os.sep + fileZ).replace(" ","%20") + "'>" + fileZ + "</a></td><td align='right'>size: " + str(os.path.getsize(dirList[0]+os.sep+fileZ)/1024/1024) + "Mb</td></tr></table></div>\n"
# print "<br>\n"
break
#Convert pattern string to list of file extensions
extList = []
for ext in pattern.split(";"):
extList.append(ext.lstrip("*"))
#Main program
if __name__ == '__main__':
print "Content-Type: text/html\n\n"
print "<!-- MP3 Host by 6ft Dan&trade Copyright 2011, All Rights Reserved //-->\n"
print "<html><head><title>" + PageTitle + "</title>\n"
print "</head><body style='background-color:" + BackgroundColor + ";'>\n"
print "\n"
print "<div style='background-color:" + HeaderBGColor + ";width:" + TitleBGWidth + ";height:" + TitleBGHeight + ";align:center;text-align:center;font-size:" + TitleFontSize + ";font-family:" + TitleFont + ";font-weight:bold;color:" + HeaderFGColor + ";'>" + PageTitle + "</div>\n"
print "<br><br><br><hr>\n"
#Walk the tree to print file
for directory in os.walk(path):
containsExt = False
for x in extList:
for y in directory[2]:
if x.lower() == y[-len(x):].lower():
containsExt = True
if containsExt:
if ShowFolder:
print "<font style='font-weight:bold;'>" + directory[0].split("/")[-1].upper() + "</font>\n"
printFiles(directory,extList)
print "<hr>"
print "<br><br><br><center><font size='-1'>" + MediaRights + "</font></center>\n"
print "<br><center><font size=1>MP3 Host :: Copyright 2011 &copy All Rights Reserved :: 6ft Dan&trade</font></center>\n"
print "</body></html>\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment