Created
June 13, 2014 20:08
-
-
Save szolotykh/e9c38fec0a0343a8ff3b to your computer and use it in GitHub Desktop.
VK video
This file contains 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
from urllib2 import Request, urlopen, URLError | |
def findURL(page_srt, res): | |
try: | |
att = "url"+res | |
start_ind = page_srt.index(att) | |
end_ind = page_srt.index("?",start_ind) | |
url = page_srt[(start_ind+len(att)+1):end_ind] | |
return url | |
except: | |
return None | |
def GetVideoDirectUrl(url, res): | |
res = str(res) | |
req = Request(url) | |
try: | |
response = urlopen(req) | |
except URLError as e: | |
if hasattr(e, 'reason'): | |
print 'We failed to reach a server.' | |
print 'Reason: ', e.reason | |
elif hasattr(e, 'code'): | |
print 'The server couldn\'t fulfill the request.' | |
print 'Error code: ', e.code | |
else: | |
page_data = response.read() | |
video_url = findURL(page_data, res) | |
return video_url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment