-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget-bundle-id.py
executable file
·88 lines (71 loc) · 2.37 KB
/
get-bundle-id.py
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
#!/usr/bin/env python3
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Get Bundle ID
# @raycast.mode inline
# @raycast.refreshTime 3s
# Optional parameters:
# @raycast.icon images/appstore-icon.png
# Documentation:
# @raycast.description Get Bundle ID
# @raycast.author CreatechStudio Shanghai Inc.
# @raycast.authorURL https://github.com/createchstudio
# 安装依赖
import importlib
import subprocess
depends = [
('requests', 'requests'),
('pyperclip', 'PaperClip')
]
for pack_name, imp_name in depends:
try:
importlib.import_module(imp_name)
except:
p = subprocess.Popen(f'/usr/bin/env python3 -m pip install {pack_name}', stdout=subprocess.PIPE, shell=True)
p.wait()
import requests
import re
import pyperclip
def extract_app_id(url):
pattern = r'id(\d+)'
match = re.search(pattern, url)
if match:
return match.group(1)
return None
def fetch_data(app_id, url):
lookup_url = f'https://itunes.apple.com/{url}/lookup?id={app_id}'
response = requests.get(lookup_url)
if response.status_code == 200:
return response.json()
return None
def extract_bundle_id(data):
if data and 'results' in data and len(data['results']) > 0:
return data['results'][0].get('bundleId')
return None
def copy_to_clipboard(text):
subprocess.run(['pbcopy'], universal_newlines=True, input=text)
def save_bundle_id_from_app_store_link():
clipboard_content = pyperclip.paste()
app_store_link = clipboard_content.strip()
if app_store_link:
app_id = extract_app_id(app_store_link)
if app_id:
json_data = fetch_data(app_id, 'cn')
bundle_id = extract_bundle_id(json_data)
if bundle_id:
copy_to_clipboard(bundle_id)
print(f"已复制 {bundle_id} 已复制到剪贴板")
else:
json_data = fetch_data(app_id, 'us')
bundle_id = extract_bundle_id(json_data)
if bundle_id:
copy_to_clipboard(bundle_id)
print(f"已复制 {bundle_id} 已复制到剪贴板")
else:
print("无法获取 bundleId。")
else:
print("无法提取 App ID。")
else:
print("剪贴板中未找到 App Store 链接。")
if __name__ == "__main__":
save_bundle_id_from_app_store_link()