Google-Photos-Toolkit icon indicating copy to clipboard operation
Google-Photos-Toolkit copied to clipboard

[Feature Request] Filter by has location or not

Open christhetree opened this issue 8 months ago • 14 comments

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!

christhetree avatar Mar 23 '25 18:03 christhetree

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');

xob0t avatar Mar 24 '25 01:03 xob0t

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?

christhetree avatar Mar 24 '25 11:03 christhetree

make sure you're on the Google Photos page https://photos.google.com/

xob0t avatar Mar 24 '25 11:03 xob0t

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.

christhetree avatar Mar 24 '25 12:03 christhetree

No, brave should be fine. Are you using the latest version of the script?

xob0t avatar Mar 24 '25 12:03 xob0t

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!

christhetree avatar Mar 24 '25 12:03 christhetree

I've updated the snippet, try it now

xob0t avatar Mar 24 '25 13:03 xob0t

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.

christhetree avatar Mar 24 '25 13:03 christhetree

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.

xob0t avatar Apr 03 '25 12:04 xob0t

Nice thanks a lot, I'll try it out soon!

christhetree avatar Apr 07 '25 10:04 christhetree

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 avatar May 01 '25 19:05 minisergium

@minisergium I have not tested it in FF, try chrome.

xob0t avatar May 01 '25 19:05 xob0t

Thanks, it worked perfect in chrome!!

minisergium avatar May 01 '25 19:05 minisergium

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.

mikeymckay avatar Aug 12 '25 17:08 mikeymckay