Skip to main content

Add a script for downloading an Instagram post

ID
4f22042
date
2024-08-20 20:32:50+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
40e6138
message
Add a script for downloading an Instagram post
changed files
2 files, 41 additions, 1 deletion

Changed files

web/README.md (3474) → web/README.md (3892)

diff --git a/web/README.md b/web/README.md
index bcd8b3b..6da33e7 100644
--- a/web/README.md
+++ b/web/README.md
@@ -30,6 +30,12 @@ scripts = [
         """
     },
     {
+        "usage": "save_instagram_post URL",
+        "description": """
+        save the photos from a single Instagram post to a temporary directory
+        """
+    },
+    {
         "name": "save_tumblr_likes.py",
         "description": """
         save a copy of all the posts I've liked on Tumblr to my backup drive.
@@ -78,6 +84,15 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
   </dd>
 
   <dt>
+    <a href="https://github.com/alexwlchan/scripts/blob/main/web/save_instagram_post">
+      <code>save_instagram_post URL</code>
+    </a>
+  </dt>
+  <dd>
+    save the photos from a single Instagram post to a temporary directory
+  </dd>
+
+  <dt>
     <a href="https://github.com/alexwlchan/scripts/blob/main/web/save_tumblr_likes.py">
       <code>save_tumblr_likes.py</code>
     </a>
@@ -113,4 +128,4 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
     this is a wrapper around <a href="https://github.com/yt-dlp/yt-dlp">yt-dlp</a> that does parallel downloads of videos in playlists.
   </dd>
 </dl>
-<!-- [[[end]]] (checksum: cc21e25a1a69ea0dea3a50dd8737ec2d) -->
+<!-- [[[end]]] (checksum: e672cab382a39082951edc1a0a3f9f21) -->

web/save_instagram_post (0) → web/save_instagram_post (402)

diff --git a/web/save_instagram_post b/web/save_instagram_post
new file mode 100755
index 0000000..3b8e5fb
--- /dev/null
+++ b/web/save_instagram_post
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+
+set -o errexit
+set -o nounset
+
+if (( $# != 1 ))
+then
+  echo "Usage: $0 URL" >&2
+  exit 1
+fi
+
+url="$1"
+
+pushd $(mktemp -d) >/dev/null
+  uv venv --quiet .venv
+  source .venv/bin/activate
+
+  uv pip install --quiet instaloader
+
+  post_id=$(echo "$url" | tr '/' ' ' | awk '{print $4}')
+  instaloader -- "-$post_id"
+
+  echo "$(pwd)/-$post_id"
+  reveal "$(pwd)/-$post_id"
+popd >/dev/null