import re

URL_REGEX = re.compile(
    r'<p>(?P<url>(?:http|ftp)s?://' # http:// or https://
    r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain...
    r'localhost|' #localhost...
    r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
    r'(?::\d+)?' # optional port
    r'(?:/?|[/?]\S+))<\/p>', re.IGNORECASE
)

URL_PATTERNS = (
	(r'^https?://(.+\.)?blip\.tv/file/.+$', 'http://blip.tv/oembed/?%s', 'json'),
	(r'^https?://(www\.)?clikthrough\.com/theater/.+$', 
		'http://clikthrough.com/services/oembed/?%s', 'json'
	),
	(r'^https?://(www\.)?dailymotion\.com/video/.+$',
		'http://www.dailymotion.com/api/oembed/?%s', 'json'
	),
	(r'^https?://(www\.)?dotsub\.com/view/.+$',
		'http://dotsub.com/services/oembed?%s', 'json'
	),
	(r'^https?://(www\.)?flickr\.com/photos/.+$',
		'http://www.flickr.com/services/oembed/?%s', 'xml'
	),
	(r'^https?://(www\.)?hulu\.com/watch/.+$',
		'http://www.hulu.com/api/oembed.json?%s', 'json'
	),
	(r'^https?://(www\.)?kinomap\.com/.+$',
		'http://www.kinomap.com/oembed?%s', 'xml'
	),
	(r'^https?://(www\.)?nfb\.ca/film/.+$',
		'http://www.nfb.ca/remote/services/oembed/?%s',
		'xml'
	),
	(r'^https?://(www\.)?poddle\.tv/[\w-]+/\d+/$',
		'http://poddle.tv/oembed/?%s', 'json'
	),
	(r'^https?://(.+\.)?photobucket\.com/(albums|groups)/.+$', 
		'http://photobucket.com/oembed?%s', 'json'
	),
	(r'^https?://(www\.)?qik\.com/video/.+$',
		'http://qik.com/api/oembed.json?%s', 'json'
	),
	(r'^https?://(www\.)?revision3\.com/.+$',
		'http://revision3.com/api/oembed/?%s', 'json'
	),
	(r'^https?://(www\.)?scribd\.com/doc/.+$',
		'http://www.scribd.com/services/oembed?%s', 'json'
	),
	(r'^https?://twitter\.com/(#!/)?[\w]+/status/\d+',
		'https://api.twitter.com/1/statuses/oembed.json?%s', 'json'
	),
	(r'^https?://(www\.)?viddler\.com/explore/.+$',
		'http://lab.viddler.com/services/oembed/?%s', 'xml'
	),
	(r'^https?://(www\.)?vimeo\.com/.+$',
		'http://vimeo.com/api/oembed.json?%s', 'json'
	),
	(r'^https?://(www\.)?yfrog\.(com|ru|com\.tr|it|fr|co\.il|co\.uk|com\.pl|pl|eu|us)/.+$', 
		'http://www.yfrog.com/api/oembed?%s', 'json'
	),
	(r'^https?://(www\.)?youtube\.com/watch\?v=.+$',
		'http://www.youtube.com/oembed?%s', 'json'
	)
)