Created
July 5, 2012 22:48
-
-
Save emre/3056942 to your computer and use it in GitHub Desktop.
video URL to video code converter for popular video sharing sites.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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