mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
Instagram Video Downloader (#94)
* Instagram Video Downloader downloads all the videos from instagram post * Update README.md Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com>
This commit is contained in:
parent
e428f6a3fd
commit
b2139ce2e9
|
@ -71,6 +71,7 @@ So far, the following projects have been integrated to this repo:
|
||||||
|[Find PhoneNumber in String](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Find-PhoneNumber-in-String)|[Austin Zuniga](https://github.com/AustinZuniga)|
|
|[Find PhoneNumber in String](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Find-PhoneNumber-in-String)|[Austin Zuniga](https://github.com/AustinZuniga)|
|
||||||
|[IMDB TV Series Info Extractor](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/imdb_episode_ratings)|[Yash Raj Sarrof](https://github.com/yashYRS) |
|
|[IMDB TV Series Info Extractor](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/imdb_episode_ratings)|[Yash Raj Sarrof](https://github.com/yashYRS) |
|
||||||
|[Yoda-speak Translator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/speak_like_yoda)|[sonniki](https://github.com/sonniki) |
|
|[Yoda-speak Translator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/speak_like_yoda)|[sonniki](https://github.com/sonniki) |
|
||||||
|
|[Instagram Video Downloader](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/insta_video_downloader)|[Shobhit Bhosure](https://github.com/shobhit99) |
|
||||||
|[Medium Article Downloader](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/medium_article_downloader)|[coolsonu39](https://github.com/coolsonu39)|
|
|[Medium Article Downloader](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/medium_article_downloader)|[coolsonu39](https://github.com/coolsonu39)|
|
||||||
|[Face Recognition](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/image_recognition)|[LOKESH KHURANA](https://github.com/theluvvkhurana)|
|
|[Face Recognition](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/image_recognition)|[LOKESH KHURANA](https://github.com/theluvvkhurana)|
|
||||||
|[File Encrypt Decrypt](file-encrypt-decrypt)|[Aditya Arakeri](https://github.com/adityaarakeri)|
|
|[File Encrypt Decrypt](file-encrypt-decrypt)|[Aditya Arakeri](https://github.com/adityaarakeri)|
|
||||||
|
|
12
insta_video_downloader/README.md
Normal file
12
insta_video_downloader/README.md
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# Instagram Video Downloader
|
||||||
|
### Downlaods all the videos from instagram post. User needs to provide instagram post id as parameter
|
||||||
|
>> Example
|
||||||
|
|
||||||
|
```
|
||||||
|
python instavideo.py B3NUFfmgRYW
|
||||||
|
```
|
||||||
|
>> Example output file
|
||||||
|
|
||||||
|
```
|
||||||
|
B3NUFfmgRYW_0.mp4
|
||||||
|
```
|
38
insta_video_downloader/instavideo.py
Normal file
38
insta_video_downloader/instavideo.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import urllib.request
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def download(post_id):
|
||||||
|
multiple_posts = False
|
||||||
|
videos = []
|
||||||
|
data = requests.get("https://instagram.com/p/{}".format(post_id))
|
||||||
|
if data.status_code == 404:
|
||||||
|
print("Specified post not found")
|
||||||
|
sys.exit()
|
||||||
|
json_data = json.loads(re.findall(r'window._sharedData\s=\s(\{.*\});</script>', data.text)[0])
|
||||||
|
data = json_data['entry_data']['PostPage'][0]['graphql']['shortcode_media']
|
||||||
|
if 'edge_sidecar_to_children' in data.keys():
|
||||||
|
multiple_posts = True
|
||||||
|
caption = data['edge_media_to_caption']['edges'][0]['node']['text']
|
||||||
|
media_url = data['display_resources'][2]['src']
|
||||||
|
is_video = data['is_video']
|
||||||
|
if not is_video and not multiple_posts:
|
||||||
|
print("No Videos found")
|
||||||
|
sys.exit()
|
||||||
|
if is_video:
|
||||||
|
videos.append(data['video_url'])
|
||||||
|
if multiple_posts:
|
||||||
|
for post in data['edge_sidecar_to_children']['edges']:
|
||||||
|
if post['node']['is_video']:
|
||||||
|
videos.append(post['node']['video_url'])
|
||||||
|
print("Found total {} videos".format(len(videos)))
|
||||||
|
for no, video in zip(list(range(len(videos))), videos):
|
||||||
|
print("Downloading video {}".format(no))
|
||||||
|
urllib.request.urlretrieve(video, "{}_{}.mp4".format(post_id, no))
|
||||||
|
|
||||||
|
if len(sys.argv) == 1:
|
||||||
|
print("Please provide instagram post id")
|
||||||
|
else:
|
||||||
|
download(sys.argv[1])
|
1
insta_video_downloader/requirements.txt
Normal file
1
insta_video_downloader/requirements.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
requests
|
Loading…
Reference in New Issue
Block a user