Skip to content

Commit

Permalink
Merge pull request #201 from MuneebNazir/master
Browse files Browse the repository at this point in the history
Add python script for downloading posts from Instagram - photos and videos
  • Loading branch information
DhanushNehru authored Apr 20, 2024
2 parents 628805e + c6ff856 commit e274693
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
20 changes: 20 additions & 0 deletions InstaDownloader/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# INSTA DOWNLOADER
### Downloads posts from Private and Public profiles on Instagram

This python code takes user input for private and public profiles to download required posts.

#### Requirements:
* Install instaloader
* run `pip install instaloader` or `pip3 install instaloader`

### Usage
* Clone the repo
* open the `InstaDownloader` folder
##### for windows
* run `python insta_down.py`
##### for linux
* run `python3 insta_down.py`

### Important
* Please enter the post code only for the desired post
* You might face errors if you are downloading from a private profile without logging in
65 changes: 65 additions & 0 deletions InstaDownloader/insta_down.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import instaloader
from instaloader import Post
import requests
import sys

#Banner
print('''
------------------ Instagram Images and Post Downloader ------------------
[Coded By Muneeb]
''')

# #Function to check the internet connection
# #Got this from https://stackoverflow.com/a/24460981
def connection(url='http://www.google.com/', timeout=5):
try:
req = requests.get(url, timeout=timeout)
req.raise_for_status()
print("You're connected to internet\n")
return True
except requests.HTTPError as e:
print("Checking internet connection failed, status code {0}.".format(
e.response.status_code))
except requests.ConnectionError:
print("No internet connection available.")
return False

def download_insta_post(loader, target_username, post_code):
profile = instaloader.Profile.from_username(loader.context, target_username)
post = Post.from_shortcode(loader.context, post_code)
loader.download_post(post, target=target_username)

if connection() == True:
# Create an instance of Instaloader
L = instaloader.Instaloader()
try:
while True:
a = "Press 'A' to download an instagram post from a private profile.\nPress 'B' to download an instagram post from a public profile.\nPress 'Q' to exit."
print(a)
select = str(input("\nInstaSave > ")).upper()
try:
if select == 'A':
username = input("Enter your IG username: ")
password = input("Enter your IG password: ")
L.login(username, password)
t_username = input("Enter the target insta username: ")
post_code = input("Enter the post code for the media (Please don't enter the URL - only code) : ")
download_insta_post(L, t_username, post_code)
print("Post downloaded successfully")
if select == 'B':
t_username = input("Enter the target insta username: ") #sample input: quote_nietzsche
post_code = input("Enter the post code for the media (Please don't enter the URL - only code) : ") #sample input: Cyv0uoAOewp
download_insta_post(L, t_username, post_code)
print("Post downloaded successfully")
if select == 'Q':
sys.exit()
else:
sys.exit()
except (KeyboardInterrupt):
print("Programme Interrupted")
except(KeyboardInterrupt):
print("\nProgramme Interrupted")
else:
sys.exit()

0 comments on commit e274693

Please sign in to comment.