import clr
clr.AddReference("System")
from System.Text.RegularExpressions import Regex
from System.Net import WebClient
from System import Tuple
from Azyobuzi.Twirunrun import Extensions, PreviewDataTypes
clr.ImportExtensions(Extensions)

def IsUsable(uri):
	return Regex.IsMatch(uri, "^https?://(www.)?twitpic.com/\\w+$")

def GetPreviewData(uri):
	id = Regex.Match(uri, "^https?://(www.)?twitpic.com/(?<id>\\w+)$").Groups["id"].ToString()
	wc = WebClient()
	img = wc.DownloadImage("http://twitpic.com/show/full/" + id)
	wc.Dispose()
	return Tuple.Create(PreviewDataTypes.Image, img)