Skip to content

Instantly share code, notes, and snippets.

@dopuskh3
dopuskh3 / tornado_octet-stream.py
Created November 26, 2009 08:43
How to get the content of a POST with Content-type application/octet-stream with tornado
class EntryListHandler(tornado.web.RequestHandler):
def post(self, ressource_name):
# Get file content and mime type
fileContent = None
try:
fileContent = self.request.files['fname'][0]['body']
except Exception, e:
if self.request.headers.has_key('Content-Type') and self.request.headers['Content-Type'].startswith("application/octet-stream"):
fileContent = self.request.body
# multipart post. Original from http://code.activestate.com/recipes/146306/
# use StringIO or fd instead of buffer
import mimetools
import magic
def getMime(content):
ms = magic.open(magic.MAGIC_MIME)
ms.load()
magic_s = ms.buffer(content[:1024])
import sys
from lxml import etree
CARD_MULT=1
CARD_SINGLE=0
class xmlStor:
properties = {}
#!/bin/bash
ffmpeg -threads 2 -i $1 -vcodec libx264 -g 30 -deinterlace -b 900k -s 640x360 -padtop 60 -padbottom 60 -padcolor 000000 -aspect 4:3 -acodec mp3 -ab 64k $2
def search( searchRequest, idxPath):
initVM(CLASSPATH)
fsDir = FSDirectory.getDirectory(idxPath, False)
searcher = IndexSearcher(fsDir)
language = StandardAnalyzer()
queryp = QueryParser('all', language)
query = queryp.parse(searchRequest) # "title", language)
hits = searcher.search(query)
print "# Found %d hits for %s"%(len(hits), searchRequest)
def indexFilesFromPath(dir, idxPath):
initVM(CLASSPATH)
writer = IndexWriter(idxPath, StandardAnalyzer(), True)
count = 1
for root, dirs, files in os.walk(dir):
for file in files:
#print "- "+str(root)+" "+file
sfx = file[-3:]
if sfx.lower() not in [ "mp3","mp4", "ogg", "flac" ]:
continue
#!/usr/bin/env python2.5
# vim:set fileencoding=utf-8
import os
import sys
import tagpy
from lucene import \
Document, IndexSearcher, FSDirectory, MultiFieldQueryParser, QueryParser, StandardAnalyzer, IndexWriter, \
StringReader, IndexReader, MoreLikeThis, Term, TermQuery, BooleanQuery,BooleanClause , Field, initVM, CLASSPATH
def indexFilesFromPath(dir, idxPath):