mbari-org / Sharktopoda

Mac Video Player for creating, editing, and viewing localizations.
Apache License 2.0
2 stars 1 forks source link

Framecapture does not handle paths with spaces #21

Closed hohonuuli closed 1 year ago

hohonuuli commented 1 year ago

The frame capture command should be able to handle paths with spaces in them. For example:

/Users/brian/.vars/images/Doc Ricketts 1461 20221002T192205Z--cf5f53ef-8577-416d-abb6-325806b37856--20221212T230634.782Zpng

But Sharktopoda responds to those with:

 {"cause":"Image location is malformed URL","response":"frame capture","status":"failed"}

Maybe the conversion to a file URL still requires escaping the paths? (using %20). The path on disk should still include the spaces though.

Log output

2022-12-12 23:06:34 [Thread-17                       ] DEBUG org.mbari.vcr4j.remote.control.RVideoIO             cf5f53ef-8577-416d-abb6-325806b37856@localhost:8800 - Sending command >>> {
  "imageLocation": "/Users/brian/.vars/images/Doc Ricketts 1461 20221002T192205Z--cf5f53ef-8577-416d-abb6-325806b37856--20221212T230634.782Zpng",
  "imageReferenceUuid": "e46a293b-8e2b-4dbf-a380-557ba87a0e1f",
  "command": "frame capture",
  "uuid": "cf5f53ef-8577-416d-abb6-325806b37856"
}
2022-12-12 23:06:34 [Thread-17                       ] DEBUG org.mbari.vcr4j.remote.control.RVideoIO             cf5f53ef-8577-416d-abb6-325806b37856@localhost:8800 - Received response <<< {"cause":"Image location is malformed URL","response":"frame capture","status":"failed"}
hohonuuli commented 1 year ago

Sanity checks:

Scala/Java (using scala-cli repl)

Spaces are allowed in file URLs in Java.

scala> import java.net.URL

scala> val url = new URL("file:/Users/brian/.vars/images/Doc Ricketts 1461 20221002T192205Z--cf5f53ef-8577-416d-abb6-325806b37856--20221212T230634.782Zpng")
val url: java.net.URL = file:/Users/brian/.vars/images/Doc Ricketts 1461 20221002T192205Z--cf5f53ef-8577-416d-abb6-325806b37856--20221212T230634.782Zpng

Swift (using swift repl)

Spaces fail in URLs in Swift. Replacing with %20 works.

1> import Foundation
2> let url = URL(string: "file:/Users/brian/.vars/images/Doc Ricketts 1461 20221002T192205Z--cf5f53ef-8577-416d-abb6-325806b37856--20221212T230634.782Zpng")
url: Foundation.URL? = nil
3> let url = URL(string: "file:/Users/brian/.vars/images/Doc%20Ricketts%201461%2020221002T192205Z--cf5f53ef-8577-416d-abb6-325806b37856--20221212T230634.782Zpng")
url: Foundation.URL? =
 "file:/Users/brian/.vars/images/Doc%20Ricketts%201461%2020221002T192205Z--cf5f53ef-8577-416d-abb6-325806b37856--20221212T230634.782Zpng"
hohonuuli commented 1 year ago

Sanity Check:

Scala/Java

scala> import java.nio.*

scala> import java.nio.file.*

scala> val p = Paths.get("/Users/brian/.vars/images/Doc Ricketts 1461 20221002T192205Z--cf5f53ef-8577-416d-abb6-325806b37856--20221212T230634.782Zpng")

scala> p.toUri()
val res2: java.net.URI = file:///Users/brian/.vars/images/Doc%20Ricketts%201461%2020221002T192205Z--cf5f53ef-8577-416d-abb6-325806b37856--20221212T230634.782Zpng
dingosky commented 1 year ago

I believe the HTTP URL spec does not allow spaces, and Swift is adhering strictly whereas Java is lenient. It should be a simple matter to urlEncode the URL. But if this an backward compatibility issue, we can urlEncode the incoming "URL"

hohonuuli commented 1 year ago

In the spec, framecapture always sends a path to a local file. If I remember correctly, the URL conversion is internal to Sharktopoda .In any case, the remote app will be sending a path to a file that will often include spaces.

dingosky commented 1 year ago

Ah, right. I was remembering the field as being url 🤦🏽‍♂️. I'll fix to urlEncode the path while forming the file: URL.

dingosky commented 1 year ago

Proposed fix: commit 4db50192995a1fa7f9ccc9fa8c6ab0b3723f1b79

hohonuuli commented 1 year ago

Resolved. Ran test using

mvn install -Dmaven.test.skip=true
mvn exec:java -Dexec.mainClass=org.mbari.vcr4j.examples.remote.Issue21 -Dexec.args="8800 http://varsdemo.mbari.org/media/M3/mezzanine/Ventana/2017/03/4003/V4003_20170301T185553.933Z_t2s4_hd_tc01495915_h264.mp4" -pl vcr4j-examples

Comms shows the correct time is reported

2022-12-23 08:26:45 [org.mbari.vcr4j.examples.remote.Issue21.main()] DEBUG org.mbari.vcr4j.remote.control.RemoteControl$Builder - Building. Listening on port 5555. Sending commands to localhost:8800
2022-12-23 08:26:45 [org.mbari.vcr4j.examples.remote.Issue21.main()] DEBUG org.mbari.vcr4j.remote.player.PlayerIO - anicca.lan:5555 - Started server's receiver thread: Thread-1
2022-12-23 08:26:45 [Thread-1] DEBUG org.mbari.vcr4j.remote.player.PlayerIO - anicca.lan:5555 - Received command <<< {"command":"open done","status":"ok","uuid":"1b1fd0a0-52d8-4740-9350-d9c98fa9ac5f"}
2022-12-23 08:26:45 [Thread-1] DEBUG org.mbari.vcr4j.remote.player.PlayerIO - anicca.lan:5555 - Responding >>> {
  "response": "open done",
  "status": "ok"
}
2022-12-23 08:26:49 [Thread-1] DEBUG org.mbari.vcr4j.remote.player.PlayerIO - anicca.lan:5555 - Received command <<< {"command":"frame capture done","elapsedTimeMillis":810509,"imageLocation":"/Users/brian/workspace/M3/vcr4j/trashme 810521.png","imageReferenceUuid":"78b6ae9f-f8af-4048-bc4c-6857fec4bb91","status":"ok","uuid":"1b1fd0a0-52d8-4740-9350-d9c98fa9ac5f"}
2022-12-23 08:26:49 [Thread-1] DEBUG org.mbari.vcr4j.remote.player.PlayerIO - anicca.lan:5555 - Responding >>> {
  "response": "frame capture done",
  "status": "ok"
}