[Feature Request] Filter by has location or not
Hi there, really great toolkit, thanks for making it! Just a quick feature request, would it be possible to filter out images that don't have a location? I'm not talking about filtering based on the location in the image, just the boolean value of whether there is location information embedded in the image / video or not. This would be super useful for separating saved screenshots uploaded to your library from photos taken by a device. Thanks!
Hi! It is possible with api right now. Paste this in your browser console.
const hasLocation = false;
const newAlbumName = 'filtered by location';
const filteredItems = [];
let nextPageId = null;
gptkCore.isProcessRunning = true;
try {
do {
const page = await gptkApi.getItemsByTakenDate(timestamp = null, source = null, pageId = nextPageId);
for (const item of page.items) {
const hasCoordinates = Boolean(item.geoLocation.coordinates);
if (hasCoordinates !== hasLocation) continue;
filteredItems.push(item);
}
nextPageId = page.nextPageId;
} while (nextPageId);
if (filteredItems) {
await gptkApiUtils.addToNewAlbum(filteredItems, albumName = newAlbumName);
}
} finally{
gptkCore.isProcessRunning = false;
}
console.log('DONE');
Nice thanks a lot! I'm getting this error when pasting it into my console:
Uncaught ReferenceError: gptkApi is not defined
at <anonymous>:4:16
and afterwards
Uncaught TypeError: Expected type number but got string
at assertType (Google Photos Toolkit.user.js:1229:13)
at Api.getItemsByTakenDate (Google Photos Toolkit.user.js:1301:22)
at <anonymous>:4:30
is an import statement or something like that missing?
make sure you're on the Google Photos page https://photos.google.com/
Yep I'm running it from https://photos.google.com/ I'm using Brave which might be blocking it under the hood, but using the toolkit UI from Brave seems to be working fine.
No, brave should be fine. Are you using the latest version of the script?
Ah so the initial error was caused because I had disabled violentmonkey. However, now I get this error:
Uncaught TypeError: Expected type number but got string
at assertType (Google Photos Toolkit.user.js:1229:13)
at Api.getItemsByTakenDate (Google Photos Toolkit.user.js:1301:22)
at <anonymous>:4:30
Thanks for the help!
I've updated the snippet, try it now
Thanks, I've run the script and it completed successfully (it printed "DONE") in the console, but there is no new album "Items Without Location" to be found. I think perhaps the 20,000 limit might have been reach or something else went wrong. I can debug it, ideally by filtering to only include photos in a certain date range so it doesn't take as long.
Yea, there was a bug, I tested it on a small batch and it worked, but adding more than 500 items to an album would fail. I've updated the snippet again, should work now.
Nice thanks a lot, I'll try it out soon!
Hi, thanks for your help. When pasting it in firefox console I get this error: "Uncaught SyntaxError: await is only valid in async functions, async generators and modules" Im I doing something wrong?
@minisergium I have not tested it in FF, try chrome.
Thanks, it worked perfect in chrome!!
This looks great. Now I am trying to figure out how to get all photos by location that fall within a bounding box... I will post here if I figure it out.
Ok this gist now works: https://gist.github.com/mikeymckay/9bd6a28c0b5bc21898a95bd2efaa4587
It creates a bounding box around the area I am interested in and then opens each photo to get the coordinate and puts the photos in the bounding box into a new folder. Works for up to 20,000 pictures. Lots of fancy restarting features thanks to ChatGPT.