Created
August 28, 2022 14:39
-
-
Save gamingflexer/3dd686ab25b8d00c90ddd7c0a55f6ece to your computer and use it in GitHub Desktop.
Download Instagram Video from link
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
def download_image_video(url): | |
x = re.match(r'^(https:)[/][/]www.([^/]+[.])*instagram.com', url) | |
try: | |
if x: | |
request_image = requests.get(url) | |
src = request_image.content.decode('utf-8') | |
check_type = re.search(r'<meta name="medium" content=[\'"]?([^\'" >]+)', src) | |
check_type_f = check_type.group() | |
final = re.sub('<meta name="medium" content="', '', check_type_f) | |
if final == "video": | |
extract_video_link = re.search(r'meta property="og:video" content=[\'"]?([^\'" >]+)', src) | |
video_link = extract_video_link.group() | |
final = re.sub('meta property="og:video" content="', '', video_link) | |
_response = requests.get(final).content | |
file_size_request = requests.get(final, stream=True) | |
file_size = int(file_size_request.headers['Content-Length']) | |
block_size = 1024 | |
filename = uuid.uuid4() | |
with open(str(filename) + '.mp4', 'wb') as f: | |
for data in file_size_request.iter_content(block_size): | |
f.write(data) | |
print("Video downloaded successfully") | |
print(video_link) | |
return video_link | |
else: | |
print("Entered URL is not an instagram.com URL.") | |
except AttributeError: | |
print("Unknown URL") | |
#print(download_image_video("https://www.instagram.com/p/Chgr7LQNZHi/")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment