# -*- coding: utf-8 # -*- Mode: Python; py-indent-offset: 4 -*- # $Id: common.py 282 2007-10-16 15:11:59Z ayly $ # # Copyright (c) 2007, Vahur Rebas, HTK, TLU # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ Useful utils """ __version__ = "$Revision:33$"[11:-2] def get_video_dimensions(extension, head): """ returns: width, height """ width = 320 height = 256 try: import pymedia.muxer as muxer dm = muxer.Demuxer( extension ) r = dm.parse( head ) streams = dm.streams for x in streams: if x is None: continue if x.get('type') != muxer.CODEC_TYPE_VIDEO: continue width = x.get('width') height = x.get('height') break except: pass return width, height def send_mail(email, mail_subject, mail_content, charset='utf-8', mail_type='plain', from_name='', from_mail=''): """ """ from zope.sendmail.interfaces import IMailer from zope.component import getUtility mailer = getUtility(IMailer, 'qtauthor.smtp') from email.MIMEText import MIMEText from email.Header import Header from email.Utils import parseaddr, formataddr if mail_type != 'html': msg = MIMEText(mail_content.encode('utf-8'), 'plain', charset) else: msg = MIMEText(mail_content, 'html', charset) if not from_name: msg['From'] = formataddr(('TATS', 'dont-reply@htk.tlu.ee')) else: msg['From'] = formataddr((from_name, from_mail)) msg['To'] = formataddr(('', email)) msg['Subject'] = Header(mail_subject, charset) mailer.send('TATS ', email, msg.as_string()) # EOF