Package: instagram-private-api-extensions
Instagram Private API ExtensionsAn extension module toinstagram_private_apito help with common tasks such as posting a photo or video.Featuresmedia: Edits a photo/video so that it complies with Instagram's requirements by:ResizingCropping to fit the minimum/maximum aspect ratioGenerating the video thumbnail imageClipping the video duration if it is too longChanging the format/encodingpagination: Page through an api call such asapi.user_feed().live: Download an ongoing IG live stream. Requires ffmpeg installed.replay: Download an IG live replay stream. Requires ffmpeg installed.DocumentationDocumentation is available athttps://instagram-private-api-extensions.readthedocs.io/en/latest/InstallInstall with pip usingpipinstallgit+https://git@github.com/ping/instagram_private_api_extensions.git@0.3.8To update:pipinstallgit+https://git@github.com/ping/instagram_private_api_extensions.git@0.3.8--upgradeTo update with latest repo code:pipinstallgit+https://git@github.com/ping/instagram_private_api_extensions.git--upgrade--force-reinstallUsageMediafrominstagram_private_apiimportClient,MediaRatiosfrominstagram_private_api_extensionsimportmediaapi=Client('username','password')# post a photophoto_data,photo_size=media.prepare_image('pathto/my_photo.jpg',aspect_ratios=MediaRatios.standard)api.post_photo(photo_data,photo_size,caption='Hello World!')# post a videovid_data,vid_size,vid_duration,vid_thumbnail=media.prepare_video('pathto/my_video.mp4',aspect_ratios=MediaRatios.standard)api.post_video(vid_data,vid_size,vid_duration,vid_thumbnail)# post a photo storyphoto_data,photo_size=media.prepare_image('pathto/my_photo.jpg',aspect_ratios=MediaRatios.reel)api.post_photo_story(photo_data,photo_size)# post a video storyvid_data,vid_size,vid_duration,vid_thumbnail=media.prepare_video('pathto/my_video.mp4',aspect_ratios=MediaRatios.reel)api.post_video_story(vid_data,vid_size,vid_duration,vid_thumbnail)# post a video without reading the whole file into memoryvid_saved_path,vid_size,vid_duration,vid_thumbnail=media.prepare_video('pathto/my_video.mp4',aspect_ratios=MediaRatios.standard,save_path='pathto/my_saved_video.mp4',save_only=True)# To use save_only, the file must be saved locally# by specifying the save_pathwithopen(vid_saved_path,'rb')asvideo_fp:api.post_video(video_fp,vid_size,vid_duration,vid_thumbnail)Paginationfrominstagram_private_api_extensionsimportpagination# page through a feeditems=[]forresultsinpagination.page(api.user_feed,args={'user_id':'123456'}):ifresults.get('items'):items.extend(results['items'])print(len(items))Livefrominstagram_private_api_extensionsimportlivebroadcast=api.broadcast_info('1234567890')dl=live.Downloader(mpd=broadcast['dash_playback_url'],output_dir='output_{}/'.format(broadcast['id']),user_agent=api.user_agent)try:dl.run()exceptKeyboardInterrupt:ifnotdl.is_aborted:dl.stop()finally:# combine the downloaded files# Requires ffmpeg installed. If you prefer to use avconv# for example, omit this step and do it manuallydl.stitch('my_video.mp4')Replayfrominstagram_private_api_extensionsimportreplayuser_story_feed=api.user_story_feed('12345')broadcasts=user_story_feed.get('post_live_item',{}).get('broadcasts',[])forbroadcastinbroadcasts:dl=replay.Downloader(mpd=broadcast['dash_manifest'],output_dir='output_{}/'.format(broadcast['id']),user_agent=api.user_agent)# download and save to filedl.download('output_{}.mp4'.format(broadcast['id']))SupportMake sure to review thecontributing documentationbefore submitting an issue report or pull request.