LeoKlaus / plappa

An Audiobook client for Jellyfin and AudioBookShelf, written in Swift/SwiftUI.
https://plappa.me
237 stars 1 forks source link

[BUG] Not syncing from ABS anymore (Error while decoding sessions) #192

Closed JakobTischler closed 2 months ago

JakobTischler commented 2 months ago

Describe the bug The listening sessions aren't synced from AudiobookShelf anymore. Already completed books remain in the "continue" queue/section. The log shows a null value error.

To Reproduce

  1. Listen to books both using Plappa and the ABS clients.

Expected behavior Progress and active books should sync.

Logs

[2024-09-18, 13:38] [plappa] Encountered an error while decoding sessions: The data couldn’t be read because it is missing.
valueNotFound(Swift.String, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "sessions", intValue: nil), _CodingKey(stringValue: "Index 561", intValue: 561), CodingKeys(stringValue: "libraryItemId", intValue: nil)], debugDescription: "Cannot get value of type String -- found null value instead", underlyingError: nil))
[2024-09-18, 13:38] [plappa] Encountered an error while decoding sessions: The data couldn’t be read because it is missing.
valueNotFound(Swift.String, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "sessions", intValue: nil), _CodingKey(stringValue: "Index 561", intValue: 561), CodingKeys(stringValue: "libraryItemId", intValue: nil)], debugDescription: "Cannot get value of type String -- found null value instead", underlyingError: nil))
[2024-09-19, 10:58] [plappa] Encountered an error while decoding sessions: The data couldn’t be read because it is missing.
valueNotFound(Swift.String, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "sessions", intValue: nil), _CodingKey(stringValue: "Index 561", intValue: 561), CodingKeys(stringValue: "libraryItemId", intValue: nil)], debugDescription: "Cannot get value of type String -- found null value instead", underlyingError: nil))
[2024-09-19, 10:58] [plappa] Encountered an error while decoding sessions: The data couldn’t be read because it is missing.
valueNotFound(Swift.String, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "sessions", intValue: nil), _CodingKey(stringValue: "Index 561", intValue: 561), CodingKeys(stringValue: "libraryItemId", intValue: nil)], debugDescription: "Cannot get value of type String -- found null value instead", underlyingError: nil))
[2024-09-19, 11:13] [AudioBookShelfAPIHandler] Successfully posted sessions
[2024-09-19, 11:13] [plappa] Encountered an error while decoding sessions: The data couldn’t be read because it is missing.
valueNotFound(Swift.String, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "sessions", intValue: nil), _CodingKey(stringValue: "Index 561", intValue: 561), CodingKeys(stringValue: "libraryItemId", intValue: nil)], debugDescription: "Cannot get value of type String -- found null value instead", underlyingError: nil))

Environment(please complete the following information):

LeoKlaus commented 2 months ago

This is not really a bug in plappa, playback sessions should always have a libraryItemId.

You should be able to identify the offending session by opening https://[your-server-url]/api/me/listening-sessions?itemsPerPage=1&page=561 in your browser.

If you don't mind sharing, feel free to post the response here (you might want to remove the deviceInfo key).

JakobTischler commented 2 months ago

Sure. This is a newest response (page 1):

{
  "total": 675,
  "numPages": 675,
  "page": 1,
  "itemsPerPage": 1,
  "sessions": [
    {
      "id": "c9ecdec7-c82f-48e6-aeef-62fde66917de",
      "userId": "1f82ffbc-6b77-4bad-9ea2-6955efb5ab1e",
      "libraryId": "f8e098aa-5450-4ada-b39f-31a7ba0dac4e",
      "libraryItemId": "c7fbcc51-d2eb-4312-a709-485aa0425ac9",
      "bookId": "ce0bc04d-f83c-4f6e-9982-2ca5083283ba",
      "episodeId": null,
      "mediaType": "book",
      "mediaMetadata": {
        "title": "The Last Murder at the End of the World",
        "subtitle": null,
        "authors": [
          {
            "id": "93077ab7-e332-47e3-b949-4be469397406",
            "name": "Stuart Turton",
            "coverPath": null
          }
        ],
        "narrators": [
          "Adjoa Andoh"
        ],
        "series": [],
        "genres": [
          "Mystery, Thriller & Suspense",
          "Contemporary",
          "Post-Apocalyptic"
        ],
        "publishedYear": "2024-03-28",
        "publishedDate": null,
        "publisher": null,
        "description": "Solve the murder to save what's left of the world. Outside the island there is nothing: the world destroyed by a fog that swept the planet, killing anyone it touched. On the island: it is idyllic. 122 villagers and 3 scientists, living in peaceful harmony. The villagers are content to fish, farm and feast, to obey their nightly curfew, to do what they’re told by the scientists. Until, to the horror of the islanders, one of their beloved scientists is found brutally stabbed to death. And they learn the murder has triggered a lowering of the security system around the island, the only thing that was keeping the fog at bay. If the murder isn’t solved within 92 hours, the fog will smother the island – and everyone on it. But the security system has also wiped everyone’s memories of exactly what happened the night before, which means that someone on the island is a murderer – and they don’t even know it… An outstanding high concept murder mystery from the Sunday Times bestselling and Costa Book Award winning author of The Seven Deaths of Evelyn Hardcastle. An ingenious puzzle, an extraordinary backdrop, an audacious solution.\"",
        "isbn": null,
        "asin": "B0CFY6QRW2",
        "language": "English",
        "explicit": false,
        "abridged": false
      },
      "chapters": [],
      "displayTitle": "The Last Murder at the End of the World",
      "displayAuthor": "Stuart Turton",
      "coverPath": null,
      "duration": 39521.261678,
      "playMethod": 3,
      "mediaPlayer": "exo-player",
      "deviceInfo": {
        REMOVED
      },
      "serverVersion": "2.13.4",
      "date": "2024-09-17",
      "dayOfWeek": "Tuesday",
      "timeListening": 7649,
      "startTime": 0,
      "currentTime": 24743.427,
      "startedAt": 1726571651822,
      "updatedAt": 1726596314393
    }
  ]
}

And this is the session of one of the books still in the "continue" queue on Plappa:

{
  "total": 675,
  "numPages": 675,
  "page": 4,
  "itemsPerPage": 1,
  "sessions": [
    {
      "id": "0361176a-9073-4c46-b356-f2a4d6eda2ed",
      "userId": "1f82ffbc-6b77-4bad-9ea2-6955efb5ab1e",
      "libraryId": "f8e098aa-5450-4ada-b39f-31a7ba0dac4e",
      "libraryItemId": "ed516c4d-2ede-496b-abc0-c1add90e98df",
      "bookId": "87882145-2c06-404a-bc79-7b7a108f0f7c",
      "episodeId": null,
      "mediaType": "book",
      "mediaMetadata": {
        "title": "A Foreign Country",
        "subtitle": null,
        "authors": [
          {
            "id": "014efe33-6c81-4a95-9e66-852867d6e253",
            "name": "Charles Cumming",
            "coverPath": null
          }
        ],
        "narrators": [
          "Jot Davies"
        ],
        "series": [],
        "genres": [
          "Mystery, Thriller & Suspense",
          "Espionage",
          "Fiction",
          "France"
        ],
        "publishedYear": "2012-08-07",
        "publishedDate": null,
        "publisher": null,
        "description": "From the internationally acclaimed, New York Times best-selling author of The Trinity Six, Charles Cumming, comes A Foreign Country, a compelling tale of deceit and betrayal, conspiracy and redemption. On the vacation of a lifetime in Egypt, an elderly French couple are brutally murdered. Days later, a meticulously planned kidnapping takes place on the streets of Paris. Amelia Levene, the first female Chief of MI6, has disappeared without a trace, six weeks before she is due to take over as the most influential spy in Europe. It is the gravest crisis MI6 has faced in more than a decade. Desperate not only to find her, but to keep her disappearance a secret, Britain’s top intelligence agents turn to one of their own: disgraced MI6 officer Thomas Kell. Tossed out of the Service only months before, Kell is given one final chance to redeem himself - find Amelia Levene at any cost. The trail leads Kell to France and Tunisia, where he uncovers a shocking secret and a conspiracy that could have unimaginable repercussions for Britain and its allies. Only Kell stands in the way of personal and political catastrophe. \"",
        "isbn": null,
        "asin": "B008O8ZOBA",
        "language": null,
        "explicit": false,
        "abridged": false
      },
      "chapters": [],
      "displayTitle": "A Foreign Country",
      "displayAuthor": "Charles Cumming",
      "coverPath": null,
      "duration": 34418.985,
      "playMethod": 3,
      "mediaPlayer": "exo-player",
      "deviceInfo": {
        REMOVED
      },
      "serverVersion": "2.13.4",
      "date": "2024-09-14",
      "dayOfWeek": "Saturday",
      "timeListening": 8508,
      "startTime": 0,
      "currentTime": 34418.953,
      "startedAt": 1726312386978,
      "updatedAt": 1726329657759
    }
  ]
}
LeoKlaus commented 2 months ago

Thank you for sending the response. The logs indicate the issue comes up in session 561, so it's important that you go to page 561. I've implemented a workaround for this just now and will release it to TestFlight shortly.

JakobTischler commented 2 months ago

Ah, my mistake.

This is indeed a rather old session, which neither has a libraryItemId nor a bookId:

{
    "total": 675,
    "numPages": 675,
    "page": 561,
    "itemsPerPage": 1,
    "sessions": [
        {
            "id": "e38a307f-4757-4567-911d-d56d75b818eb",
            "userId": "1f82ffbc-6b77-4bad-9ea2-6955efb5ab1e",
            "libraryId": "3a13d003-0a43-409e-8427-cb1558c004e8",
            "libraryItemId": null,
            "bookId": null,
            "episodeId": null,
            "mediaType": "podcast",
            "mediaMetadata": {
            "title": "James Bonding",
            "author": "Matt Gourley, Matt Mira",
            "description": "Matt Gourley and Matt Mira love James Bond so much they decided to make a podcast about it. Each episode they invite a guest to dive deep into one movie from the greatest film franchise known to man. The entire James Bonding catalogue is now being re-released for free, one week at a time, starting 10/5/22. We never left.",
            "releaseDate": null,
            "genres": [
                "Comedy",
                "Movies"
            ],
            "feedUrl": "REMOVED",
            "imageUrl": "https://stitcher.imgix.net/50584f0daeb6f033b7100c1348f622f71799bfdfa9f3e90dfe78a7d6e6d40b43?w=600&h=600&q=75",
            "itunesPageUrl": null,
            "itunesId": null,
            "itunesArtistId": null,
            "explicit": false,
            "language": null,
            "type": "episodic"
            },
            "chapters": [],
            "displayTitle": "Do You Expect Me To Talk?",
            "displayAuthor": "Matt Gourley, Matt Mira",
            "coverPath": "/podcasts/James Bonding/cover.jpg",
            "duration": 2648.16325,
            "playMethod": 0,
            "mediaPlayer": "html5",
            "deviceInfo": {
            "REMOVED"
            },
            "serverVersion": "2.2.12",
            "date": "2023-01-21",
            "dayOfWeek": "Saturday",
            "timeListening": 65,
            "startTime": 6.071152,
            "currentTime": 110.153637,
            "startedAt": 1674342379036,
            "updatedAt": 1674342448067
        }
    ]
}

This is a podcast episode, though, meaning it's a different library.


I've implemented a workaround for this just now and will release it to TestFlight shortly.

Thank you very much for the quick help.

LeoKlaus commented 2 months ago

Sessions are synced per account, not per library, so it makes sense that this pops up. The lack of a bookId shouldn't cause any issues with plappa.

You might be able to fix this yourself by deleting this particular session using the ABS interface. Otherwise, the update should release to TestFlight in the next 15 minutes (you can join here: https://testflight.apple.com/join/oSAekRD5) and to the AppStore in the coming days.

JakobTischler commented 2 months ago

Alright, thank you very much.

Edit: Using 1.4.3 (56) the sync goes through (there are around 20 or so sessions that are skipped) and my overall progress and active books are there again.