Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Photos Takeout now adds a suffix to json file (and not properly either) #353

Open
AalianKhan opened this issue Oct 27, 2024 · 2 comments

Comments

@AalianKhan
Copy link

AalianKhan commented Oct 27, 2024

Hello, Thanks a lot for this tool but unfortunately it is not working correctly for me. I noticed either other people's json file was just the filename with .json at the end.

But I noticed mine have a suffix at the end of each json file. Most of my files have this extension .supplemental-metadata.json after the file name. but with some of the longer files, the extensions are cut off at the end such as PXL_20240817_202602411.mp4 has the json file named PXL_20240817_202602411.mp4.supplemental-metada.json. and there are many others like that with .supplemental-me, .supplementa, etc

Guessing works with some but fails terribly with others. I have some that are dated to 1868 and 2068 😂

@AalianKhan AalianKhan changed the title Can't find correct json file for items with long names Can't find correct json file for items with cut off suffix Oct 27, 2024
@AalianKhan AalianKhan changed the title Can't find correct json file for items with cut off suffix Google Photos Takeout now adds a suffix to json file (and not properly either) Oct 27, 2024
@AalianKhan
Copy link
Author

AalianKhan commented Oct 28, 2024

Added this to json_extractor.dart and it works now (FYI AI generated)

Future<File?> _jsonForFile(File file, {required bool tryhard}) async {
  final dir = Directory(p.dirname(file.path));
  var name = p.basename(file.path);

  // Use methods to generate potential JSON file names
  for (final method in [
    (String s) => s,
    _shortenName,
    _bracketSwap,
    _removeExtra,
    if (tryhard) ...[
      _removeExtraRegex,
      _removeDigit,
    ]
  ]) {
    final baseJsonFile = File(p.join(dir.path, '${method(name)}.json'));
    if (await baseJsonFile.exists()) return baseJsonFile;

    // Check for JSON file with suffix and truncated suffix variations
    final supplementalJsonFile =
        await _matchSupplementalSuffix(dir, method(name));
    if (supplementalJsonFile != null) return supplementalJsonFile;
  }
  return null;
}

/// Attempts to find a JSON file with `.supplemental-metadata.json` suffix or a truncated version
Future<File?> _matchSupplementalSuffix(Directory dir, String baseName) async {
  const suffix = '.supplemental-metadata.json';
  const maxLength = 51;

  // Try with full suffix
  final fullFile = File(p.join(dir.path, '$baseName$suffix'));
  if (await fullFile.exists()) return fullFile;

  // Try truncated suffixes if file length exceeds max length
  for (int i = suffix.length; i > 0; i--) {
    final truncatedSuffix = suffix.substring(0, i);
    final truncatedFile =
        File(p.join(dir.path, '$baseName$truncatedSuffix.json'));
    if (await truncatedFile.exists()) return truncatedFile;
  }
  return null;
}

@TheLastGimbus
Copy link
Owner

TheLastGimbus commented Nov 1, 2024

ooo jaaapierdole...

okay, will look into this... soon ™️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants