Created
August 18, 2009 08:10
-
-
Save voidfiles/169600 to your computer and use it in GitHub Desktop.
one page python mp3 server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /home/alexkess/opt/bin/python | |
# One file mp3 server. | |
# Need newish version of sqlite3 | |
# python2.5 or python2.6 | |
# INSTALL | |
# get id3reader from here and install on path http://nedbatchelder.com/code/modules/id3reader.html | |
# easy_install pod | |
NO_NEWF = False | |
try: | |
from newf import Application, Response, ResponseRedirect | |
except ImportError: | |
NO_NEWF = True | |
try: | |
from flup.server.fcgi import WSGIServer | |
except: | |
print "no flup might want to fix that" | |
import os,sys, id3reader, shelve | |
MP3_PATH="/media/storage/Downloaded" | |
def index(request): | |
return Response("<h1>Index!</h1>") | |
urls = ( | |
(r'^/$', index), | |
) | |
if not NO_NEWF: | |
application = Application(urls) | |
WSGIServer(application).run() | |
def resync(): | |
#db = pod.Db(file = 'mypod.sqlite3', dynamic_index = True) | |
db = shelve.open('mp3.cache') | |
MP3_PATH = globals()["MP3_PATH"] or os.getcwd() | |
for path, dirs, files in os.walk(MP3_PATH): | |
for file in [os.path.abspath(os.path.join(path, filename)) for filename in files if filename.endswith(".mp3")]: | |
if file in db: continue | |
try: | |
id3r = id3reader.Reader(file) | |
except UnicodeDecodeError: | |
continue | |
try: | |
new_mp3 = dict( | |
path = file, | |
filename = filename, | |
artist = id3r.getValue('performer'), | |
album = id3r.getValue('album'), | |
title = id3r.getValue('title'), | |
track = id3r.getValue('track'), | |
year = id3r.getValue('year') | |
) | |
except: | |
new_mp3 = Mp3( | |
path = file, | |
filename = filename | |
) | |
db[file] = new_mp3 | |
if __name__ == "__main__": | |
if sys.argv[1] == "resync": resync() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment