33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
#Python
|
|
import instaloader
|
|
import re
|
|
import datetime
|
|
|
|
def download_image(post_url):
|
|
# Get the post from the URL
|
|
url_id = re.search(r'https://www.instagram.com/(reel|p)/(.*)/',post_url)
|
|
url_id_post = url_id.group(2)
|
|
datenow = datetime.datetime.now().strftime('%d-%m-%Y-%H-%M-%S')
|
|
# Create an Instaloader instance
|
|
Name= (f'{datenow}_{url_id_post}')
|
|
#Name= url_id_post
|
|
L = instaloader.Instaloader(filename_pattern=Name)
|
|
|
|
#get Post
|
|
post = instaloader.Post.from_shortcode(L.context, url_id_post)
|
|
|
|
|
|
# Download the post
|
|
L.download_post(post, target=post.owner_username)
|
|
print(f'File saved in folder {post.owner_username}/ dengan nama file {Name}')
|
|
|
|
if __name__ == '__main__':
|
|
# Get the post URL
|
|
# post_url = 'https://www.instagram.com/p/Cua9Aw-BZRz/?igshid=MzRlODBiNWFlZA=='
|
|
post_url = 'https://www.instagram.com/reel/CsVi19-gHVY/?igshid=MzRlODBiNWFlZA=='
|
|
# post_url = 'https://www.instagram.com/p/CueKypRP6pf/?igshid=MzRlODBiNWFlZA=='
|
|
# post_url = 'https://www.instagram.com/p/Cuohb_qpnBY/?igshid=MzRlODBiNWFlZA=='
|
|
# match = re.search(r'https://www.instagram.com/(reel|p)/(.*)/', post_url[1])
|
|
# print(match.group(2))
|
|
# Download the image
|
|
download_image(post_url) |