-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstagram GraphQL generator.pyw
185 lines (166 loc) · 7.93 KB
/
Instagram GraphQL generator.pyw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import tkinter as tk
import json
from tkinter import messagebox
import urllib.parse
import httpx
class InstagramURLGenerator:
def __init__(self, root):
self.root = root
self.root.title("Instagram GraphQL URL Generator")
# URL Input Field with Sky Blue Background
self.input_text = tk.Entry(root, width=50, bg="sky blue", font=("Arial", 12))
self.input_text.grid(row=0, column=0, padx=10, pady=10)
# Paste Button with Custom Style
paste_button = tk.Button(root, text="Paste", command=self.paste_from_clipboard,
fg="black", font=("Arial", 10, "bold"))
paste_button.grid(row=0, column=1, padx=5, pady=10)
# Generate URL Button with Custom Style
generate_button = tk.Button(root, text="Generate URL", command=self.generate_url,
bg="light blue", fg="black", font=("Arial", 10, "bold"))
generate_button.grid(row=1, column=0, columnspan=2, padx=10, pady=10)
# Output Textbox with Sky Blue Background
self.url_output = tk.Text(root, height=5, width=50, bg="sky blue", font=("Arial", 12))
self.url_output.grid(row=2, column=0, padx=10, pady=10)
# Copy to Clipboard Button with Custom Style
copy_button = tk.Button(root, text="Copy to Clipboard", command=self.copy_to_clipboard,
fg="black", font=("Arial", 10, "bold"))
copy_button.grid(row=2, column=1, padx=5, pady=10)
# Reset Button with Custom Style
reset_button = tk.Button(root, text="Reset", command=self.reset_fields,
bg="red", fg="white", font=("Arial", 10, "bold"))
reset_button.grid(row=3, column=0, columnspan=2, padx=10, pady=10)
def identify_url_type(self, url):
if 'stories/highlights' in url:
return 'highlight'
elif 'stories' in url:
return 'story'
elif '/p/' in url:
return 'post'
elif 'reel' in url:
return 'post'
else:
return 'profile'
def scrape_user(self, username):
try:
response = client.get(
f"https://i.instagram.com/api/v1/users/web_profile_info/?username={username}",
)
response.raise_for_status()
data = response.json()
return data["data"]["user"]
except Exception as e:
tk.messagebox.showerror("Error", f"Failed to retrieve user data: {e}")
return None
def generate_url(self):
url = self.input_text.get()
url_type = self.identify_url_type(url)
if url_type == 'profile':
username = url.rstrip('/').split('/')[-1]
if username:
with open("username.txt", "w") as file:
file.write(username)
base_url = "https://www.instagram.com/graphql/query/?doc_id=8759034877476257&variables="
variables = {
"data": {
"count": 25,
"include_relationship_info": True,
"latest_besties_reel_media": True,
"latest_reel_media": True
},
"username": username,
"__relay_internal__pv__PolarisIsLoggedInrelayprovider": True,
"__relay_internal__pv__PolarisFeedShareMenurelayprovider": True
}
json_string = json.dumps(variables)
encoded_variables = urllib.parse.quote(json_string)
full_url = base_url + encoded_variables
self.url_output.delete(1.0, tk.END)
self.url_output.insert(tk.END, full_url)
else:
tk.messagebox.showerror("Error", "User data not retrieved.")
elif url_type == 'highlight':
reel_id = url.split('/')[-2]
base_url = "https://www.instagram.com/graphql/query/?query_hash=de8017ee0a7c9c45ec4260733d81ea31&variables="
variables = {
"reel_ids": [],
"tag_names": [],
"location_ids": [],
"highlight_reel_ids": [int(reel_id)],
"precomposed_overlay": False,
"show_story_viewer_list": True,
"story_viewer_fetch_count": 50,
"story_viewer_cursor": ""
}
variables_json = json.dumps(variables)
encoded_variables = urllib.parse.quote(variables_json)
highlight_url = base_url + encoded_variables
self.url_output.delete(1.0, tk.END)
self.url_output.insert(tk.END, highlight_url)
elif url_type == 'story':
username = url.rstrip('/').split('/')[-2]
user_data = self.scrape_user(username)
if user_data:
user_id = user_data.get("id")
if user_id:
with open("user_id.txt", "w") as file:
file.write(user_id)
base_url = "https://www.instagram.com/graphql/query/?query_hash=de8017ee0a7c9c45ec4260733d81ea31&variables="
variables ={
"reel_ids": [int(user_id)],
"tag_names": [],
"location_ids": [],
"highlight_reel_ids": [],
"precomposed_overlay": False,
"show_story_viewer_list": True,
"story_viewer_fetch_count": 50,
"story_viewer_cursor": ""
}
variables_json = json.dumps(variables)
encoded_variables = urllib.parse.quote(variables_json)
story_url = base_url + encoded_variables
self.url_output.delete(1.0, tk.END)
self.url_output.insert(tk.END, story_url)
else:
tk.messagebox.showerror("Error", "User ID not found.")
else:
tk.messagebox.showerror("Error", "User data not retrieved.")
elif url_type == 'post':
if url.endswith('/'):
url = url[:-1] # Remove the trailing slash if present
addition = f"/?__a=1&__d=dis"
full_url = f"{url}" + addition
self.url_output.delete(1.0, tk.END)
self.url_output.insert(tk.END, full_url)
else:
tk.messagebox.showerror("Error", "Unknown URL type.")
def copy_to_clipboard(self):
self.root.clipboard_clear()
self.root.clipboard_append(self.url_output.get("1.0", "end").strip())
def paste_from_clipboard(self):
try:
clipboard_content = self.root.clipboard_get().strip()
if clipboard_content:
self.input_text.delete(0, tk.END)
self.input_text.insert(0, clipboard_content)
else:
raise ValueError("Clipboard is empty")
except ValueError as e:
messagebox.showerror("Paste Error", str(e))
except tk.TclError:
messagebox.showerror("Paste Error", "Failed to access clipboard content.")
def reset_fields(self):
self.input_text.delete(0, tk.END)
self.url_output.delete(1.0, tk.END)
if __name__ == "__main__":
client = httpx.Client(
headers={
"x-ig-app-id": "936619743392459",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36",
"Accept-Language": "en-US,en;q=0.9,ru;q=0.8",
"Accept-Encoding": "gzip, deflate, br",
"Accept": "*/*",
}
)
root = tk.Tk()
app = InstagramURLGenerator(root)
root.mainloop()