-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
150 lines (136 loc) · 6.43 KB
/
api.js
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
import authProperties from './auth.js';
const {
cookie,
xClientData
} = authProperties;
if(!cookie) {
throw new Error('fdsafdsa')
}
function parseOutInfo(text) {
const regex = /\[\[.*\"generic\"\]\]/g;
const found = text.match(regex);
let outer = JSON.parse(found[0])
let inner = JSON.parse(outer[0][2])
let photoIds = inner[0].map(el => el?.[0])
let pageToken = inner.at(-5)
return {photoIds, pageToken}
}
export async function getPhotoList({searchQuery}) {
let numPhotos = 1000; // number per batch...doesn't always seem to come back with 1000 though
let res = await fetch("https://photos.google.com/_/PhotosUi/data/batchexecute?rpcids=EzkLib&source-path=%2Fsearch%2Fjpg%2520OR%2520jpeg%2520OR%2520png%2520OR%2520heic&f.sid=307050036153956327&bl=boq_photosuiserver_20221116.05_p1&hl=en&soc-app=165&soc-platform=1&soc-device=1&_reqid=79959&rt=c", {
"headers": {
"accept": "*/*",
"accept-language": "en,pt-BR;q=0.9,pt;q=0.8",
"cache-control": "no-cache",
"content-type": "application/x-www-form-urlencoded;charset=UTF-8",
"pragma": "no-cache",
"sec-ch-ua": "\"Google Chrome\";v=\"107\", \"Chromium\";v=\"107\", \"Not=A?Brand\";v=\"24\"",
"sec-ch-ua-arch": "\"arm\"",
"sec-ch-ua-bitness": "\"64\"",
"sec-ch-ua-full-version": "\"107.0.5304.87\"",
"sec-ch-ua-full-version-list": "\"Google Chrome\";v=\"107.0.5304.87\", \"Chromium\";v=\"107.0.5304.87\", \"Not=A?Brand\";v=\"24.0.0.0\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-model": "",
"sec-ch-ua-platform": "\"macOS\"",
"sec-ch-ua-platform-version": "\"12.5.1\"",
"sec-ch-ua-wow64": "?0",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"x-client-data": xClientData,
"x-goog-ext-353267353-jspb": "[null,null,null,128892]",
"x-same-domain": "1",
"cookie": cookie,
"Referer": "https://photos.google.com/",
"Referrer-Policy": "origin"
},
"body": `f.req=%5B%5B%5B%22EzkLib%22%2C%22%5B%5C%22${searchQuery}%5C%22%2C%5B%5D%2Cnull%2Cnull%2C${numPhotos}%5D%22%2Cnull%2C%22generic%22%5D%5D%5D&at=AGnVvw5ygyuyFbvyqUD1okY4bjzp%3A1668748357080&`,
"method": "POST"
});
let allPhotoIds = []
let text = await res.text();
let {photoIds, pageToken} = parseOutInfo(text)
allPhotoIds.push(...photoIds);
try {
for (let i = 0; i < 100; i++) {
console.log("fetching page " + (i + 2));
text = await nextPage({pageToken, searchQuery}).then(r => r.text());
let obj = parseOutInfo(text);
allPhotoIds.push(...obj.photoIds);
pageToken = obj.pageToken;
}
} catch (e) {
console.log('error, so must be done!')
}
// console.log("photoIds: ", JSON.stringify(allPhotoIds));
console.log("first photo id: ", allPhotoIds[0]);
console.log("last photo id: ", allPhotoIds.at(-1));
console.log("unique photoIds: ", new Set(allPhotoIds).size);
return allPhotoIds;
}
export function moveToAlbum({photoIds, albumId}) {
let delimiter = '%5C%22%2C%5C%22'
let joinedPhotoIds = photoIds.join(delimiter);
return fetch("https://photos.google.com/_/PhotosUi/data/batchexecute?rpcids=E1Cajb&source-path=%2Fphoto%2FAF1QipN9gSlNlByTys6fOrb-0jz5PEXep0f2lxEaFBY1&f.sid=-2858565525455532615&bl=boq_photosuiserver_20221113.06_p0&hl=en&soc-app=165&soc-platform=1&soc-device=1&_reqid=20078249&rt=c", {
"headers": {
"accept": "*/*",
"accept-language": "en,pt-BR;q=0.9,pt;q=0.8",
"cache-control": "no-cache",
"content-type": "application/x-www-form-urlencoded;charset=UTF-8",
"pragma": "no-cache",
"sec-ch-ua": "\"Google Chrome\";v=\"107\", \"Chromium\";v=\"107\", \"Not=A?Brand\";v=\"24\"",
"sec-ch-ua-arch": "\"arm\"",
"sec-ch-ua-bitness": "\"64\"",
"sec-ch-ua-full-version": "\"107.0.5304.87\"",
"sec-ch-ua-full-version-list": "\"Google Chrome\";v=\"107.0.5304.87\", \"Chromium\";v=\"107.0.5304.87\", \"Not=A?Brand\";v=\"24.0.0.0\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-model": "",
"sec-ch-ua-platform": "\"macOS\"",
"sec-ch-ua-platform-version": "\"12.5.1\"",
"sec-ch-ua-wow64": "?0",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"x-client-data": xClientData,
"x-goog-ext-353267353-jspb": "[null,null,null,128871]",
"x-same-domain": "1",
"cookie": cookie,
"Referer": "https://photos.google.com/",
"Referrer-Policy": "origin"
},
"body": `f.req=%5B%5B%5B%22E1Cajb%22%2C%22%5B%5B%5C%22${joinedPhotoIds}%5C%22%5D%2C%5C%22${albumId}%5C%22%5D%22%2Cnull%2C%22generic%22%5D%5D%5D&at=AGnVvw7JAfMK3nPYypXzj_HDeLV8%3A1668487444855&`,
"method": "POST"
})
}
function nextPage({pageToken, searchQuery}) {
return fetch("https://photos.google.com/_/PhotosUi/data/batchexecute?rpcids=EzkLib&source-path=%2Fsearch%2Fjpg%2520OR%2520jpeg%2520OR%2520png%2520OR%2520heic&f.sid=307050036153956327&bl=boq_photosuiserver_20221116.05_p1&hl=en&soc-app=165&soc-platform=1&soc-device=1&_reqid=119579959&rt=c", {
"headers": {
"accept": "*/*",
"accept-language": "en,pt-BR;q=0.9,pt;q=0.8",
"cache-control": "no-cache",
"content-type": "application/x-www-form-urlencoded;charset=UTF-8",
"pragma": "no-cache",
"sec-ch-ua": "\"Google Chrome\";v=\"107\", \"Chromium\";v=\"107\", \"Not=A?Brand\";v=\"24\"",
"sec-ch-ua-arch": "\"arm\"",
"sec-ch-ua-bitness": "\"64\"",
"sec-ch-ua-full-version": "\"107.0.5304.87\"",
"sec-ch-ua-full-version-list": "\"Google Chrome\";v=\"107.0.5304.87\", \"Chromium\";v=\"107.0.5304.87\", \"Not=A?Brand\";v=\"24.0.0.0\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-model": "",
"sec-ch-ua-platform": "\"macOS\"",
"sec-ch-ua-platform-version": "\"12.5.1\"",
"sec-ch-ua-wow64": "?0",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"x-client-data": xClientData,
"x-goog-ext-353267353-jspb": "[null,null,null,128907]",
"x-same-domain": "1",
"cookie": cookie,
"Referer": "https://photos.google.com/",
"Referrer-Policy": "origin"
},
"body": `f.req=%5B%5B%5B%22EzkLib%22%2C%22%5B%5C%22${searchQuery}%5C%22%2C%5B%5D%2C%5C%22${pageToken}%5C%22%5D%22%2Cnull%2C%22generic%22%5D%5D%5D&at=AGnVvw5ygyuyFbvyqUD1okY4bjzp%3A1668748357080&`,
"method": "POST"
});
}