Skip to content

Instantly share code, notes, and snippets.

@emre
Created July 5, 2012 22:48
Show Gist options
  • Save emre/3056942 to your computer and use it in GitHub Desktop.
Save emre/3056942 to your computer and use it in GitHub Desktop.
video URL to video code converter for popular video sharing sites.
import re
def videoUrlToVideoCode(url):
if not url.startswith("http://"):
raise ValueError(u'URL http:// ile başlamalıdır.')
pattern_list = [
['youtube.com', 'youtube\.com/watch\?v=([^&]*)'],
['vimeo.com', 'vimeo.com\/([0-9]*)$'],
['dailymotion.com', 'dailymotion\.com/video/([^_]*)'],
['kanald.com.tr', 'kanald.com.tr/.*?/Video/.*?/(.*)'],
['metacafe.com', 'metacafe.com/watch/([^/]*)'],
['spike.com', 'spike.com/video-clips/([^/]*)'],
['vidivodo.com', 'vidivodo.com/video/.*?/([^/]*)'],
]
for pattern in pattern_list:
if url.startswith("http://" + pattern[0]) or url.startswith("http://www." + pattern[0]):
matches = re.findall(pattern[1], url)
if len(matches) > 0:
return matches[0], re.findall('^([^\.]*)', pattern[0])[0], url
raise LookupError("Sonuç bulunamadı")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment