Created
October 15, 2023 06:53
-
-
Save Xnuvers007/43e2b97064a833ad7e147bdb656d3895 to your computer and use it in GitHub Desktop.
igstory downloader flask and normal, coding in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import requests, json | |
# from fake_useragent import UserAgent | |
# user_agent = UserAgent() | |
# random_user_agent = user_agent.random | |
# cookies = { | |
# 'uid': '98390561706a89a0', | |
# 'adsPopupClick': '54', | |
# 'helperWidget': '96', | |
# '_ga_99VS1KX9CV': 'GS1.1.1696774111.1.1.1696774521.0.0.0', | |
# '_ga': 'GA1.1.80242225.1696774112', | |
# '_ga_V9ECHR065F': 'GS1.1.1696774119.1.1.1696774522.0.0.0', | |
# '__gads': 'ID=fe02ca7d154b2815:T=1696774116:RT=1696774518:S=ALNI_MbsMBLJOX6Ofyf9hlUtv3AxIuaXkw', | |
# '__gpi': 'UID=00000c5aeff7ed21:T=1696774116:RT=1696774518:S=ALNI_MYpdx21b767fCzOhfajQsbOrDvfeA', | |
# 'FCNEC': '^%^5B^%^5B^%^22AKsRol_KYC1jctLJ7OzzBnBtQBOK2qGYSTHvgBuaTMD8Ct5J-5vTAxdU_tqbEcS7eQZszI7XKi5MLbwuedBxBCA1lIY-QyknBTU_caA5oJOmUUYdzAbJq6DjC5vrPx_kJNzxGGOqV9mcMUyd6HdLMLPCSJ4oTkaL9A^%^3D^%^3D^%^22^%^5D^%^2Cnull^%^2C^%^5B^%^5D^%^5D', | |
# } | |
# headers = { | |
# 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/118.0', | |
# 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8', | |
# 'Accept-Language': 'id,en-US;q=0.7,en;q=0.3', | |
# 'Connection': 'keep-alive', | |
# 'Upgrade-Insecure-Requests': '1', | |
# 'Sec-Fetch-Dest': 'document', | |
# 'Sec-Fetch-Mode': 'navigate', | |
# 'Sec-Fetch-Site': 'none', | |
# 'Sec-Fetch-User': '?1', | |
# 'If-None-Match': 'W/2b3e3-0W3dahNAbvWq7gRreKTNcnBACxk', | |
# } | |
# links = input("Masukkan link story ig / sorotan ig: ") | |
# response = requests.get( | |
# f'https://igram.world/api/ig/story?url={links}', | |
# cookies=cookies, | |
# headers=headers, | |
# ) | |
# # print(response.text) | |
# data = json.loads(response.text) | |
# # print(data['result'][0]['video_versions'][0]['url']) | |
# # for i in data['result']: | |
# # video_versions = i['video_versions'] | |
# # for j, video in enumerate(video_versions): | |
# # print(f"Video {j + 1} URL: {video['url']}") | |
# start = 1 | |
# for i in data['result']: | |
# video_versions = i['video_versions'] | |
# for j, video in enumerate(video_versions): | |
# print(f"Video {j + start} URL: {video['url']}") | |
# start += 1 | |
from flask import Flask, request, jsonify | |
import requests | |
import json | |
from flask_cors import CORS | |
from html import escape | |
from flask_limiter import Limiter | |
app = Flask(__name__) | |
# limiter = Limiter(app=app, key_func=, default_limits=["100 per day", "10 per hour"]) | |
limiter = Limiter(key_func=lambda: request.headers.get("X-Real-IP", request.remote_addr), default_limits=["100 per day", "10 per hour"], headers_enabled=True, app=app) | |
CORS(app) | |
@app.route('/igstory', methods=['GET']) | |
def get_instagram_story(): | |
if request.method == 'GET': | |
user_input = request.args.get('url') | |
else: | |
return jsonify({'error': 'Method not allowed'}) | |
if user_input: | |
user_input = escape(user_input) | |
else: | |
return jsonify({'error': 'Please provide a valid Instagram story URL', | |
'example': request.host_url + 'igstory?url=https://www.instagram.com/stories/highlights/17860230305961018/', | |
'example2': request.host_url + 'igstory?url=https://www.instagram.com/stories/instagram/2687722349609598831/'}) | |
# if not user_input: | |
# return jsonify({'error': 'Please provide a valid Instagram story URL', | |
# 'example': request.host_url + 'igstory?url=https://www.instagram.com/stories/highlights/17860230305961018/', | |
# 'example2': request.host_url + 'igstory?url=https://www.instagram.com/stories/instagram/2687722349609598831/'}) | |
cookies = { | |
'uid': '98390561706a89a0', | |
'adsPopupClick': '54', | |
'helperWidget': '96', | |
'_ga_99VS1KX9CV': 'GS1.1.1696774111.1.1.1696774521.0.0.0', | |
'_ga': 'GA1.1.80242225.1696774112', | |
'_ga_V9ECHR065F': 'GS1.1.1696774119.1.1.1696774522.0.0.0', | |
'__gads': 'ID=fe02ca7d154b2815:T=1696774116:RT=1696774518:S=ALNI_MbsMBLJOX6Ofyf9hlUtv3AxIuaXkw', | |
'__gpi': 'UID=00000c5aeff7ed21:T=1696774116:RT=1696774518:S=ALNI_MYpdx21b767fCzOhfajQsbOrDvfeA', | |
'FCNEC': '^%^5B^%^5B^%^22AKsRol_KYC1jctLJ7OzzBnBtQBOK2qGYSTHvgBuaTMD8Ct5J-5vTAxdU_tqbEcS7eQZszI7XKi5MLbwuedBxBCA1lIY-QyknBTU_caA5oJOmUUYdzAbJq6DjC5vrPx_kJNzxGGOqV9mcMUyd6HdLMLPCSJ4oTkaL9A^%^3D^%^3D^%^22^%^5D^%^2Cnull^%^2C^%^5B^%^5D^%^5D', | |
} | |
headers = { | |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/118.0', | |
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8', | |
'Accept-Language': 'id,en-US;q=0.7,en;q=0.3', | |
'Connection': 'keep-alive', | |
'Upgrade-Insecure-Requests': '1', | |
'Sec-Fetch-Dest': 'document', | |
'Sec-Fetch-Mode': 'navigate', | |
'Sec-Fetch-Site': 'none', | |
'Sec-Fetch-User': '?1', | |
'If-None-Match': 'W/2b3e3-0W3dahNAbvWq7gRreKTNcnBACxk', | |
} | |
try: | |
response = requests.get(f'https://igram.world/api/ig/story?url={user_input}', cookies=cookies, headers=headers) | |
except: | |
return jsonify({'error': 'Failed to fetch Instagram story data'}) | |
# if not response.ok: | |
# return jsonify({'error': 'Failed to fetch Instagram story data'}) | |
data = json.loads(response.text) | |
result = [] | |
start = 1 | |
for i in data['result']: | |
video_versions = i['video_versions'] | |
for j, video in enumerate(video_versions): | |
result.append({'url': video['url']})#, 'index': j + start}) | |
start += len(video_versions) | |
# return jsonify({'instagram_story_videos': result}) | |
return jsonify(result) | |
if __name__ == '__main__': | |
app.run(debug=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment