Migrating instagram photos

This was a somewhat quick project for this sunday.

With the App 4K stogram I downloaded all my photos from instagram. The program saves each file with time and date in the filename. So I placed each one of them in a folder, changing spaces to underscores in the filenames and ran the small script bellow to magically create the posts. I saved my files in content/instagram, keep that in mind if you use the script.

for dir in *; 
	do date=`cut -d'_' -f 1 <<< "$dir"`; 
		file=$dir'.jpg'; 
		time=`cut -d'_' -f 2 <<< "$dir" | sed -e 's/\./\:/g'`; 
		datetime=$date'T'$time'+00:00'; 
		printf '%s\n' '---'  'categories: ["instagram"]'  "date: $datetime"  'description: ""'  'draft: false'  "featured_image: /instagram/$dir/$file" 'layout: post'  'slug:'  'stories:'  'subtitle:'  'title: Untitled'  '---' '' "<img src=\"$file\" />" > $dir/index.md ; 
	done

This was later turned into a section, with it’s own layouts and minor tweaks.

5 Likes

If not private, I’d be interested to see the site :slight_smile:

sure thing, the site and the new instagram section is here: https://brunoamaral.eu/instagram/

The template is a port of Future Imperfect with a lot of changes, you can see the code here: https://github.com/brunoamaral/future-imperfect-DI

(A side effect of this is that Hugo now takes a minute to build the full site.)

3 Likes

Nice site!

1 Like

And quick too! Where did you deploy your website Bruno, if I may ask?

@jura I am using Digital Ocean, yet I think you can get similar results in other hosting services.

I have added my build script to the public repo so that you can take a look: https://github.com/brunoamaral/future-imperfect-DI/blob/master/build.sh

It minimizes images and scripts using the same tools that you find in https://imageoptim.com/mac

hope this helps !

1 Like

I tried this idea on my own site and have some detail questions :wink:

  1. what are you doing with mp3 files (for instagram videos). I assume it’s as easy as adding mp3 to the extension in the script, but in the end depending on the ending the content of the md-file needs to be different.
  2. is there any reason (performance?) to put them in a subdirectory per image? In my understanding of hugo it would also work with imagename.md in one folder if I have not hundreds of images?

I rewrote the script a little bit (to take care of the underscoring and moving the files into their own respective folders. Result below (careful in the end, I did not get the line endings correct, believe three lines are one):

#!/bin/bash

# replacing spaces with underscores
for file in *; do mv "$file" `echo $file | tr ' ' '_'` ; done

# creating subfolders and moving files
for x in ./*.jpg; do
  mkdir "${x%.*}" && mv "$x" "${x%.*}"
done

# creating index.md for each subfolder
for dir in *;
do date=`cut -d'_' -f 1 <<< "$dir"`;
	file=$dir'.jpg';
	time=`cut -d'_' -f 2 <<< "$dir" | sed -e 's/\./\:/g'`;
	datetime=$date'T'$time'+00:00';
	printf '%s\n' '---'  'categories: ["instagram"]'  "date: $datetime"  'description: ""'  'draft: false'  
"featured_image: /instagram/$dir/$file" 'layout: post'  'slug:'  'stories:'  'subtitle:'  'title: Untitled'  '---' '' "<img 
src=\"$file\" />" > $dir/index.md ;
done

nice, thanks for that ! :slight_smile:

to answer your questions:

  1. I am not extracting videos or mp3 files at all, as in my use case they are very rare.

  2. No reason other than my own organisation, a side effect was that that this approach helps if you want to use the recent function .Resources in your template.

There are also some params that most people won’t need: stories, subtitle, and description.

1 Like

@Jimmy4321 if you post a link to an Instagram bot service again you will be suspended from this forum.

Consider this as a warning.

I’m going to keep this in the same thread for clarity’s sake.

There has been some talks around the forum on how to migrate photos from instagram and in one of them I found out about instaloader.

This weekend I reviewed the script I was using to import photos, and published the instructions in case someone else is looking to do the same thing.

The post gives an explanation on how the script works and the code is on github in case anyone needs to tweak it somehow.

Hope this is useful for someone.