diff --git a/README.md b/README.md index dcdd319..1a22fa2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ -# One-More-Episode +# 1 More Episode? +"#^%$! I fell asleep and woke up watching a different season! What was the last episode I saw?!" - You, probably -Track what episode (Jellyfin) you fell asleep to from your Pebble smartwatch! \ No newline at end of file +Well now your Pebble smartwatch can tell you! This app uses your Pebble Health +data to match the time you fell asleep with your Jellyfin/Plex watch history. +You can even track what you fell asleep to each night on your timeline! + +Simply provide your Jellyfin/Plex ([Tautulli](https://tautulli.com/)) API key+URL +in settings and let your Pebble keep track! + +>[!WARNING] +>Jellyfin is strongly encouraged! Plex support requires installing [Tautulli](https://tautulli.com/) +>since the official API doesn't seem to want to return watch history (unless you have Plex Pass?). diff --git a/src/pkjs/index.js b/src/pkjs/index.js index 7b97208..f1f8e6e 100644 --- a/src/pkjs/index.js +++ b/src/pkjs/index.js @@ -4,10 +4,18 @@ Pebble.addEventListener("ready", function () { Pebble.addEventListener("appmessage", function (dict) { if (dict.payload["API_HOST"]) { - if (dict.payload["API_IS_PLEX"] == 1) { - callAPI(dict.payload["API_HOST"] + "/status/sessions/history/all", true, dict.payload["API_KEY"]); - } else { + if (dict.payload["API_IS_PLEX"] == 0) { callAPI(dict.payload["API_HOST"] + "/System/ActivityLog/Entries", false, dict.payload["API_KEY"]); + } else { + // The official history endpoint doesn't seem to return history w/o Plex Pass. + // If someone with Plex Pass wants to give it a shot, I'd be happy to accept a PR adding this as an option. + // Until then, I'm using Tautulli because it's free. + //callAPI(dict.payload["API_HOST"] + "/status/sessions/history/all", true, dict.payload["API_KEY"]); + callAPI( + dict.payload["API_HOST"] + "/api/v2?apikey=" + dict.payload["API_KEY"] + "&cmd=get_history", + true, + NULL, + ); } } }); @@ -18,15 +26,13 @@ function callAPI(fullURL, isPlex, apiKey) { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState === 4) { - console.log(xhr.responseText); // raw JSON string from API + console.log(xhr.responseText); } }; xhr.open("GET", fullURL, true); xhr.setRequestHeader("Accept", "application/json"); - if (isPlex) { - xhr.setRequestHeader("X-Plex-Token", apiKey); - } else { + if (!isPlex) { xhr.setRequestHeader("Authorization", 'MediaBrowser Token="' + apiKey + '"'); }