import urllib from searcher import guess_date def escape(data): if type(data) is unicode: data = data.encode('utf-8') if type(data) != str: data = str(data) data = data.replace('&', '&') data = data.replace('<', '<') # Do this for attributes data = data.replace('"', '"') return data def quote(data): if type(data) is unicode: data = data.encode('utf-8') if type(data) != str: data = str(data) return urllib.quote(data) def header(wsgi): fp = open('/home/bryan/public_html/pages/navbar.html') navbar = fp.read() fp.close() return r""" Toolserver :: ~bryan :: OggSearch

Toolserver :: ~bryan :: OggSearch

""" + navbar + """
""" def js_header(wsgi): return "%s('" % wsgi['request'].get('callback', 'ogg_search') def checked(boolean): if boolean: return 'checked="checked"' return '' def search_form(wsgi): request = dict(((k, v.encode('utf-8')) for k, v in wsgi['request'].iteritems())) data = """

Ogg files are containers for media streams. They can contain an unlimited amount of audio and video streams. MediaWiki currently supports Theora, an MPEG-4 like lossy codec, for videos. For audio MediaWiki supports Vorbis, a general audio codec intended to replace MP3, FLAC, a lossless audio format, and Speex, which is aimed at voice recordings.

Ogg files are directly playable in the webbrowser via Cortado (Java), the VLC ActiveX control and Apple Quicktime.

Search

File name

Minimum length

Maximum length

Uploaded after

Uploaded before

Date format: YYYY-MM-DD HH:MM:SS or YYYYMMDDHHMMSS. Less significant digits can be left out and will be replace by 0.

Category

In category

Not in category

Seperate multiple categories by |. Limit: %i.

Video

Minimum resolution

Maximum resolution

Audio

Audio format

""" % ( request.get('name', ''), request.get('min-min', '0'), request.get('min-sec', '0'), request.get('max-min', ''), request.get('max-sec', ''), guess_date(request.get('min-date', ''), True), guess_date(request.get('max-date', ''), True), request.get('in-category', ''), request.get('not-in-category', ''), wsgi['config']['category_limit'], checked(request.get('video') == 'no'), checked(request.get('video') == 'yes'), checked(request.get('video') not in ('yes', 'no')), request.get('min-w', '0'), request.get('min-h', '0'), request.get('max-w', ''), request.get('max-h', ''), checked(request.get('audio') == 'no'), checked(request.get('audio') == 'yes'), checked(request.get('audio') not in ('yes', 'no')), checked('vorbis' in request or 'search' not in request), checked('flac' in request or 'search' not in request), checked('speex' in request or 'search' not in request), ) if wsgi['request'].get('format') == 'raw_js': return data.replace('\n', "\\n' +\n'") else: return data def no_results(wsgi): return """
No search results
""" def search_header(wsgi): return '
\n' + search_navigation(wsgi) def search_navigation(wsgi): result = ['

'] link = '&'.join(('%s=%s' % (quote(i[0]), quote(i[1])) for i in wsgi['query_string'].items() + wsgi['postdata'].items() if i[0] != 'offset')) result.append('View streams') if wsgi['continuation'] - wsgi['limit']: result.append('(previous %s)' % \ (max(0, wsgi['continuation'] - 2 * wsgi['limit']), link, wsgi['limit'])) for i in xrange(1, int(wsgi['continuation'] / wsgi['limit'])): result.append('%s' % \ ((i - 1) * wsgi['limit'], link, i)) if not wsgi['is_last']: result.append('(next %s)' % \ (wsgi['continuation'], link, wsgi['limit'])) result.append('(') result.append(' | '.join(('%s' % \ (link, max(0, wsgi['continuation'] - wsgi['limit']), i, i) for i in (10, 20, 50, 100)))) result.append(')') result.append('

') return ' '.join(result) import md5 import searcher def search_item(wsgi, image, streams): result = ['
'] name, size, length, stream_types, timestamp = image name_md5 = md5.new(name).hexdigest() if stream_types & searcher.Searcher.OGG_VIDEO: icon = 'http://' + quote('upload.wikimedia.org/wikipedia/commons/thumb/' + '%s/%s/%s/mid-%s.jpg' % (name_md5[0], name_md5[:2], name, name)) elif stream_types & searcher.Searcher.OGG_AUDIO: icon = 'http://' + quote('upload.wikimedia.org/wikipedia/commons/thumb/' + '2/21/Speaker_Icon.svg/240px-Speaker_Icon.svg.png') else: icon = '' result.append('
' % name_md5) result.append('' % icon) result.append('
') result.append('

') result.append('' % \ escape('"id": "image-preview-%s", "videoUrl": "http://upload.wikimedia.org/wikipedia/commons/%s/%s/%s", ' % \ (name_md5, name_md5[0], name_md5[:2], quote(name)) + '"length": %s, ' % length + \ '"width": %s, "height": %s, ' % find_resolution(streams) + \ '"linkUrl": "http://commons.wikimedia.org/wiki/Image:%s", ' % quote(name) + \ '"isVideo": %s' % (stream_types & searcher.Searcher.OGG_VIDEO))) result.append('%s' % (quote(name), escape(name))) result.append('– Size: %.2f kB,' % (size / 1024)) result.append('Length: %s,' % lengthf(length)) result.append('Uploaded: %s%s%s%s-%s%s-%s%s %s%s:%s%s:%s%s' % tuple(timestamp)) result.append('

') for (stream_type, stream_length, stream_bitrate, stream_width, stream_height, stream_framerate, stream_channels, stream_samplerate) in streams: result.append('

') result.append('%s:' % escape(stream_type)) result.append('Length: %s,' % lengthf(stream_length)) result.append('Bit rate: %s,' % bitratef(stream_bitrate)) if stream_type in searcher.Searcher.video_types: result.append('Resolution: %s × %s,' % (stream_width, stream_height)) result.append('Frame rate: %.2f fps' % stream_framerate) elif stream_type in searcher.Searcher.audio_types: result.append('Channels: %s,' % stream_channels) result.append('Sample rate: %sHz' % stream_samplerate) result.append('

') result.append('
\n') return '\n'.join(result) def lengthf(seconds): if seconds > 60: return '%im %is' % (seconds / 60, seconds % 60) return '%is' % seconds def bitratef(bps): return '%.2f kbps' % (bps / 1024) def find_resolution(streams): for (stream_type, stream_length, stream_bitrate, stream_width, stream_height, stream_framerate, stream_channels, stream_samplerate) in streams: if stream_width and stream_height: return stream_width, stream_height return 200, 0 def search_footer(wsgi): return search_navigation(wsgi) + '
\n' def footer(wsgi): return """
\n\n""" def js_footer(wsgi): return "');"