Skip to content

Instantly share code, notes, and snippets.

@lepture
Created October 13, 2010 09:29
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 lepture/623745 to your computer and use it in GitHub Desktop.
Save lepture/623745 to your computer and use it in GitHub Desktop.
filter
@register.filter
def embed(value):
#gist
value = re.sub(r'(https?://gist.github.com/[\d]+)',r'<small><a rel="nofollow" href="\1">\1</a></small><script src="\1.js"></script>', value)
#youtube
value = re.sub(r'http://www.youtube.com/watch\?v=([a-zA-Z0-9\-\_]+)', r'<small><a rel="nofollow" href="http://www.youtube.com/watch?v=\1">Youtube Source</a></small><br /><embed src="http://www.youtube.com/v/\1?fs=1&amp;hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385" />', value)
#youku
value = re.sub(r'http://v.youku.com/v_show/id_([a-zA-Z0-9\=]+).html', r'<small><a rel="nofollow" href="http://v.youku.com/v_show/id_\1.html">Youku Source</a></small><br /><embed src="http://player.youku.com/player.php/sid/\1/v.swf" quality="high" width="480" height="400" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" />', value)
#tudou
value = re.sub(r'http://www.tudou.com/programs/view/([a-zA-z0-9\-\=]+)/',r'<small><a rel="nofollow" href="http://www.tudou.com/programs/view/\1/">Tudou Source</a></small><br /><embed src="http://www.tudou.com/v/\1/v.swf" width="480" height="400" allowScriptAccess="sameDomain" wmode="opaque" type="application/x-shockwave-flash" />', value)
return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment