inthreedee / photoprism-transfer-album

Transfer a Google Photos album to a new Photoprism album
GNU General Public License v3.0
109 stars 12 forks source link

Improve Tip in README #8

Closed CatoLynx closed 1 year ago

CatoLynx commented 1 year ago

Thank you for this super useful script, it worked nearly perfectly! The tip to use tee to view and save the output was helpful, but I noticed some errors due to album titles somehow including backslashes or something, which led to "400 Invalid Request" responses from photoprism due to malformed JSON. These errors went to stderr and thus were not logged by tee. To also be able to log and grep for those, I suggest to include the following in the readme (assuming bash):

./transfer-album.sh > >(tee -a stdout.log) 2> >(tee -a stderr.log >&2)

This displays both stdout and stderr, but also logs them to their respective files. :)

CatoLynx commented 1 year ago

Actually, even better, both in one file:

./transfer-album.sh 2>&1 | tee output.log

CatoLynx commented 1 year ago

More detail on the malformed JSON: It seems this occurs when the album name, according to the metadata JSON, contains quotation marks. This apparently causes the script to terminate the string at the backslash and submit that as JSON to the API.

inthreedee commented 1 year ago

Thanks for this! I’m currently traveling for a few weeks but I’ll have a look at it when I get back.

I’ll look into why it’s misinterpreting the JSON (your details provide an obvious clue, thank you very much), and try to fix the problem.

inthreedee commented 1 year ago

@Mezgrman So you're right, the script currently uses awk to parse the json and assumes no escaped quotes. There's a line in the get_json_filed() function that will use an external tool, jq, to parse jsons but it obviously requires that tool to be installed. You can comment out the awk line and uncomment the jq line if you wanted to try it out.

Can you please provide an example of the line in your JSON that it's getting tripped up on so I have something to experiment with?

CatoLynx commented 1 year ago

Hi, here's an example - it's the Metadata.json file of an album.

{
  "title": "This is an example album title with \"quotes\", incredible!",
  "description": "",
  "access": "protected",
  "date": {
    "timestamp": "1561401138",
    "formatted": "24.06.2019, 18:32:18 UTC"
  },
  "location": "",
  "geoData": {
    "latitude": 0.0,
    "longitude": 0.0,
    "altitude": 0.0,
    "latitudeSpan": 0.0,
    "longitudeSpan": 0.0
  }
}
CatoLynx commented 1 year ago

As for trying it out, I have fixed the few json files by hand to remove the quotes so I don't really have or need anything to import right now, sorry 😅

inthreedee commented 1 year ago

I made some improvements to json parsing and updated the readme with a note about possible future breakages and the alternate jq option that's available.

As a side note, it appears Photoprism converts double quotes in album titles to single quotes, so I've gone ahead and done that too in the code since it avoids some string parsing problems that would otherwise arise.

Thanks for reporting this!