Rasedul Islam
Rasedul Islam

Reputation: 87

Download only instagram videos with instaloader

This code is working for downloading all photos and videos

from instaloader import Instaloader, Profile

L = Instaloader()
PROFILE = "username"
profile = Profile.from_username(L.context, PROFILE)

posts_sorted_by_likes = sorted(profile.get_posts(), key=lambda post: post.likes,reverse=True)

for post in posts_sorted_by_likes:
L.download_post(post, PROFILE)

Now i want to download only videos, But I can't. How can I filter this code for only videos?

Upvotes: 4

Views: 11265

Answers (2)

Tomas1906
Tomas1906

Reputation: 7

Sometimes the 'is_video' is not enough, so you can just delete the ones that don't have the .mp4 extension:

for file in os.listdir(path):
        if not file.endswith(".mp4"):
            os.remove(path + file)

Upvotes: 1

Abhinav Mathur
Abhinav Mathur

Reputation: 8101

Post has an is_video property

for post in posts_sorted_by_likes:
    if post.is_video:
        L.download_post(post, PROFILE)

Upvotes: 3

Related Questions