Download media from Instagram
Project description
BasketCase
Download images and videos from Instagram.
Notable features:
- Stories can be downloaded without triggering the "seen" flag.
- Downloads a high quality version of a profile picture.
"Green Day - Basket Case" on YouTube ;)
Installation methods
pipx
The author prefers pipx, which greatly simplifies user installations while avoiding conflicts with the system.
pipx install basketcase
venv
Or you could simply install it in a virtual environment created with venv.
pip install basketcase
I would keep mine at ~/.venv, then I'd use a shell alias to quickly activate it.
zipapp
A pre-built executable for Linux is provided with the releases, and you
can just put it in your PATH.
User install
Finally, you can install it from PyPI as a user install. But be aware that some operating systems forbid this practice.
pip install --user basketcase
Command-line usage
basketcase get "https://instagram.com/p/<post_id>"
Downloaded resources will be stored in the current working directory by default. Override with the
get --outputoption.
To download from multiple URLs, create a text file (e.g. urls.txt)
and populate it with resource URLs:
https://instagram.com/p/<post_id>
https://instagram.com/reel/<reel_id>
https://instagram.com/<username>
basketcase get ./urls.txt
See --help for more info.
Supported URLs
| Supported URL | Description |
|---|---|
https://instagram.com/<username> |
User profile. Downloads stories from the past 24 hours, and the profile picture. |
https://instagram.com/p/<post_id> |
Standard feed post |
https://instagram.com/reel/<reel_id> |
Reels movie |
https://instagram.com/stories/highlights/<highlight_id>/ |
A collection of stories, or "highlights" |
https://instagram.com/s/<code> |
An alternative URL commonly used for highlighted stories |
https://instagram.com/tv/<code> |
Similar to reels |
Session management
To retrieve your Instagram cookies, follow these steps:
- Navigate to instagram.com on your browser.
- Open up Developer Tools, switch to the Network tab, then reload the page.
- On the list, find the initial request that returns HTML, and inspect its request headers.
- Copy the value of the
Cookieheader and put it in a text file (e.g.cookies.txt).
basketcase session add-cookies ./cookies.txt --set-name "jane.doe"
# New session created (id=1) with 10 cookie(s)
This is the recommended method, since we should try to look like a real browser as much as we can to avoid "automated behavior" warnings.
Alternatively, add a single sessionid cookie.
basketcase session add-cookie "COOKIE_VALUE" --set-name "john.doe"
# New session created (id=1) with one 'sessionid' cookie
Specify its identifier when downloading.
basketcase get -s 1 URL_OR_FILE
List all available sessions with
basketcase session list.To disable sessions, use
get --no-session.If only one exists, it is treated as the default.
When the instance is closed (
BasketCase.close()) or the script exits, cookies from the HTTP client are saved in the database. This keeps your cookies up-to-date.
User data
Cookies and other application data are kept in your home directory
(i.e. ~/.basketcase).
Known limitations
This program relies on the APIs used by the web browser Instagram client, which can change without a notice.
To discover and run all tests in this project, activate the project venv,
cd to the project root and run python -m unittest. Test coverage is
still low and needs some effort.
Multiple authors, owner is private
Fails to locate a suitable extractor for a standard feed post with multiple authors, in which the owner - or main author - has a private profile you cannot see.
Development setup
This project uses pipenv for dependency and virtual environment management, so make sure it's installed. pipx is a convenient tool to manage your virtual-environment user installations, and it can be used to install pipenv.
cd to the project root, then run pipenv install --dev.
Package build and upload
First, increment the version in pyproject.toml.
Then build the package.
python -m build
If that succeeds, commit and push the changes, then tag the release.
git tag -a <version> -m 'Briefly describe the changes'
Now publish it.
python -m twine upload dist/*
Finally, merge next into main.
Build an executable
With the zipapp module we can build the whole package as an executable file for Linux. The only runtime requirement is Python 3.
cdto the project root.- Activate the virtual environment.
- Run
sh zipapp.sh.
The executable file basketcase is in the dist folder.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file basketcase-8.0.0.tar.gz.
File metadata
- Download URL: basketcase-8.0.0.tar.gz
- Upload date:
- Size: 30.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
480f0cdfaaf6822cf76978f216dd3324ad1cdb10c4cc70536f0a898a3a8bca4c
|
|
| MD5 |
3fee00d1e88da9d9cde57e07993f0128
|
|
| BLAKE2b-256 |
60636ddf36afd99ce8b3dfbdbea02507f03560d2075bdb7941d8373548361e46
|
File details
Details for the file basketcase-8.0.0-py3-none-any.whl.
File metadata
- Download URL: basketcase-8.0.0-py3-none-any.whl
- Upload date:
- Size: 30.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d81bbd2d346da5ebb43009e82568671d2707c3b6521c6d34a7c6062eafc3756b
|
|
| MD5 |
0c3a0120b40c081feaf62ea7519aa7a2
|
|
| BLAKE2b-256 |
3fc2d177c07647c7bd481b927189fdb43226440b4c324bb19e506efb597d1fe0
|