-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCafe Bazaar Downloader.txt
123 lines (110 loc) · 3.69 KB
/
Cafe Bazaar Downloader.txt
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
// ==UserScript==
// @name Cafe Bazaar Downloader
// @namespace http://your-namespace.com
// @version 1.0
// @description Script for extracting app information and downloading from Cafe Bazaar
// @author https://t.me/TheErfon
// @match https://cafebazaar.ir/*
// @grant none
// @license CC BY-NC-ND 4.0
// @licenseURL https://github.com/Rainman69/CafeBazaar-Downloader/blob/main/LICENSE
// ==/UserScript==
(function() {
'use strict';
function extractPackageName(url) {
const regex = /https:\/\/cafebazaar\.ir\/app\/(?:\?id=)?([\w.-]+)/;
const match = url.match(regex);
if (match) {
const packageName = match[1];
return packageName;
} else {
console.error("Invalid URL format: " + url);
throw new Error("Invalid URL format");
}
}
function callDownloadApi(packageName, sdk, retry = true) {
const payload = {
"properties": {
"language": 2,
"clientVersionCode": 1100301,
"androidClientInfo": {
"sdkVersion": sdk,
"cpu": "x86,armeabi-v7a,armeabi"
},
"clientVersion": "11.3.1",
"isKidsEnabled": false
},
"singleRequest": {
"appDownloadInfoRequest": {
"downloadStatus": 1,
"packageName": packageName,
"referrers": []
}
}
};
return fetch("https://api.cafebazaar.ir/rest-v1/process/AppDownloadInfoRequest", {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
})
.then(response => {
if (response.ok) {
return response.json();
} else {
console.error("API request failed for package: " + packageName);
if (retry && sdk !== 25) {
console.log("Retrying with SDK version 25 for package: " + packageName);
return callDownloadApi(packageName, 25, false);
} else {
console.error("Abnormal API response for package: " + packageName);
throw new Error("Abnormal API response. Check your request and try again.");
}
}
})
.then(data => handleResponse(data));
}
function handleResponse(data) {
const appInfo = data.singleReply.appDownloadInfoReply;
if (!appInfo) {
console.error("Response does not include expected data");
throw new Error("Response does not include expected data");
}
const downloadUrls = appInfo.fullPathUrls || [];
if (!downloadUrls.length) {
console.error("Download URLs are empty");
throw new Error("Download URLs are empty");
}
const fileSize = parseInt(appInfo.packageSize, 10) / 1024 / 1024;
const versionCode = appInfo.versionCode || 0;
return {
downloadLink: downloadUrls[downloadUrls.length - 1],
fileSize,
versionCode
};
}
function main() {
try {
const currentUrl = window.location.href;
console.log("Current URL: " + currentUrl);
const packageName = extractPackageName(currentUrl);
callDownloadApi(packageName, 33)
.then(downloadInfo => {
const { downloadLink, fileSize, versionCode } = downloadInfo;
console.log("App information retrieved successfully for package: " + packageName);
console.log("Download link: " + downloadLink);
console.log("File size: " + fileSize.toFixed(2) + " MB");
console.log("Version: " + versionCode);
// Perform the download automatically
window.location.href = downloadLink;
})
.catch(error => {
console.error("An error occurred: " + error.message);
});
} catch (error) {
console.error("An error occurred: " + error.message);
}
}
main();
})();