Welcome folks today in this blog post we will be using the tkinter
framework to download all the media
of the instagram user and save it inside the zip
file. All the full source code of the application is shown below.
Get Started
In order to get started you need to install the below library
using the pip command as shown below
pip install instaloader
And after that you need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import instaloader import tkinter as tk from tkinter import filedialog import os import zipfile def download_instagram_media(): # Get the Instagram username or URL from the text input field username_or_url = username_entry.get() # Initialize Instaloader loader = instaloader.Instaloader() # If the input is a URL, extract the username if username_or_url.startswith('https://www.instagram.com/'): username_or_url = username_or_url[28:] if username_or_url.endswith('/'): username_or_url = username_or_url[:-1] # Download the media files profile = instaloader.Profile.from_username(loader.context, username_or_url) media_count = 0 for post in profile.get_posts(): loader.download_post(post, target=media_folder) media_count += 1 message_label.config(text=f"Downloaded {media_count} media files") def select_output_folder(): # Open a file dialog to select the output folder for the ZIP file global output_folder output_folder = filedialog.askdirectory() def create_zip_file(): # Create a ZIP file of the downloaded media files global output_folder output_filename = os.path.join(output_folder, f"{username_entry.get()}_media.zip") with zipfile.ZipFile(output_filename, 'w', zipfile.ZIP_DEFLATED) as zip_file: for dirpath, dirnames, filenames in os.walk(media_folder): for filename in filenames: extension = os.path.splitext(filename)[1].lower() if extension in ['.mp4', '.jpg', '.jpeg', '.png']: filepath = os.path.join(dirpath, filename) zip_file.write(filepath, arcname=filename) message_label.config(text=f"Created ZIP file: {output_filename}") # Initialize the GUI window window = tk.Tk() window.title("Instagram Media Downloader") # Add a text input field for the Instagram username or URL username_label = tk.Label(window, text="Instagram Username or URL:") username_label.pack() username_entry = tk.Entry(window) username_entry.pack() # Add a button to download the media files download_button = tk.Button(window, text="Download Media Files", command=download_instagram_media) download_button.pack() # Add a button to select the output folder for the ZIP file output_folder_button = tk.Button(window, text="Select Output Folder", command=select_output_folder) output_folder_button.pack() # Add a button to create the ZIP file create_zip_button = tk.Button(window, text="Create ZIP File", command=create_zip_file) create_zip_button.pack() # Add a label to display status messages message_label = tk.Label(window, text="") message_label.pack() # Create the media folder if it doesn't exist media_folder = "media" if not os.path.exists(media_folder): os.mkdir(media_folder) # Start the GUI event loop window.mainloop() |
As you can see we have the input
field where the user will enter the username and then we have three buttons to download
the media files and also select the output
folder and lastly export it to the zip
file.