public ActionResult WebhookPost([FromForm] PlexEvent eventData) { /*PlexEvent eventData = JsonConvert.DeserializeObject<PlexEvent>(this.Context.Request.Form.payload, * new JsonSerializerSettings() {ContractResolver = new CamelCasePropertyNamesContractResolver()});*/ logger.Trace($"{eventData.Event}: {eventData.Metadata.Guid}"); switch (eventData.Event) { case "media.scrobble": Scrobble(eventData); break; case "media.resume": case "media.play": TraktScrobble(eventData, ScrobblePlayingStatus.Start); break; case "media.pause": TraktScrobble(eventData, ScrobblePlayingStatus.Pause); break; case "media.stop": TraktScrobble(eventData, ScrobblePlayingStatus.Stop); break; } return(APIStatus.OK()); }
object WebhookPost() { PlexEvent eventData = JsonConvert.DeserializeObject <PlexEvent>(this.Context.Request.Form.payload, new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver() }); switch (eventData.Event) { case "media.scrobble": Scrobble(eventData); break; case "media.resume": case "media.play": TraktScrobble(eventData, ScrobblePlayingStatus.Start); break; case "media.pause": TraktScrobble(eventData, ScrobblePlayingStatus.Pause); break; case "media.stop": TraktScrobble(eventData, ScrobblePlayingStatus.Stop); break; } return(APIStatus.OK()); }
public ActionResult WebhookPost([FromForm, ModelBinder(BinderType = typeof(PlexBinder))] PlexEvent payload) { /*PlexEvent eventData = JsonConvert.DeserializeObject<PlexEvent>(this.Context.Request.Form.payload, * new JsonSerializerSettings() {ContractResolver = new CamelCasePropertyNamesContractResolver()});*/ logger.Trace($"{payload.Event}: {payload.Metadata.Guid}"); switch (payload.Event) { case "media.scrobble": Scrobble(payload); break; case "media.resume": case "media.play": TraktScrobble(payload, ScrobblePlayingStatus.Start); break; case "media.pause": TraktScrobble(payload, ScrobblePlayingStatus.Pause); break; case "media.stop": TraktScrobble(payload, ScrobblePlayingStatus.Stop); break; } return(Ok()); //doesn't need to be an ApiStatus.OK() since really, all I take is plex. }
object WebhookPost() { PlexEvent eventData = JsonConvert.DeserializeObject <PlexEvent>(this.Context.Request.Form.payload, new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver() }); switch (eventData.Event) { case "media.scrobble": Scrobble(eventData); break; } return(null); }
private static void TraktScrobble(PlexEvent evt, ScrobblePlayingStatus type) { PlexEvent.PlexMetadata metadata = evt.Metadata; (SVR_AnimeEpisode episode, SVR_AnimeSeries anime) = GetEpisode(metadata); if (episode == null) { return; } var vl = Repo.Instance.VideoLocal.GetByAniDBEpisodeID(episode.AniDB_EpisodeID).FirstOrDefault(); float per = 100 * (metadata.ViewOffset / (float)vl.Duration); //this will be nice if plex would ever give me the duration, so I don't have to guess it. ScrobblePlayingType scrobbleType = episode.PlexContract.IsMovie ? ScrobblePlayingType.movie : ScrobblePlayingType.episode; TraktTVHelper.Scrobble(scrobbleType, episode.AnimeEpisodeID.ToString(), type, per); }
private void Scrobble(PlexEvent data) { PlexEvent.PlexMetadata metadata = data.Metadata; (SVR_AnimeEpisode episode, SVR_AnimeSeries anime) = GetEpisode(metadata); if (episode == null) { return; } var user = RepoFactory.JMMUser.GetAll().FirstOrDefault(u => data.Account.Title.FindIn(u.GetPlexUsers())); if (user == null) { return; //At this point in time, we don't want to scrobble for unknown users. } episode.ToggleWatchedStatus(true, true, FromUnixTime(metadata.LastViewedAt), false, user.JMMUserID, true); anime.UpdateStats(true, false, true); }
private void Scrobble(PlexEvent data) { PlexEvent.PlexMetadata metadata = data.Metadata; (SVR_AnimeEpisode episode, SVR_AnimeSeries anime) = GetEpisode(metadata); if (episode == null) { logger.Info("No episode returned, aborting scrobble. This might not have been a ShokoMetadata library"); return; } logger.Trace($"Got anime: {anime}, ep: {episode.PlexContract.EpisodeNumber}"); var user = Repo.Instance.JMMUser.GetAll().FirstOrDefault(u => data.Account.Title.FindIn(u.GetPlexUsers())); if (user == null) { logger.Info($"Unable to determine who \"{data.Account.Title}\" is in Shoko, make sure this is set under user settings in Desktop"); return; //At this point in time, we don't want to scrobble for unknown users } episode.ToggleWatchedStatus(true, true, FromUnixTime(metadata.LastViewedAt), false, user.JMMUserID, true); anime.UpdateStats(true, false, true); }
private void Scrobble(PlexEvent data) { PlexEvent.PlexMetadata metadata = data.Metadata; if (!data.Metadata.Guid.StartsWith("com.plexapp.agents.shoko://")) { return; } string[] parts = metadata.Guid.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); int animeId = int.Parse(parts[1]); int series = int.Parse(parts[2]); var anime = RepoFactory.AnimeSeries.GetByID(animeId); enEpisodeType episodeType; switch (series ) //I hate magic number's but this is just about how I can do this, also the rest of this is for later. { case -4: episodeType = enEpisodeType.Parody; break; case -3: episodeType = enEpisodeType.Trailer; break; case -2: episodeType = enEpisodeType.Other; break; case -1: episodeType = enEpisodeType.Credits; break; case 0: episodeType = enEpisodeType.Special; break; default: episodeType = enEpisodeType.Episode; break; } if (episodeType != enEpisodeType.Episode || metadata.Index == 0) //metadata.index = 0 when it's something else. { return; //right now no clean way to detect the episode. I could do by title. } SVR_AnimeEpisode episode = anime .GetAnimeEpisodes() .Where(a => a.EpisodeTypeEnum == episodeType) .Where(a => metadata.Title.Equals(a?.PlexContract?.Title, StringComparison.InvariantCultureIgnoreCase)) .FirstOrDefault(a => a?.TvDBEpisode?.SeasonNumber == series); if (episode == null) { return; } var user = RepoFactory.JMMUser.GetAll().FirstOrDefault(u => data.Account.Title.FindIn(u.GetPlexUsers())); if (user == null) { return; //At this point in time, we don't want to scrobble for unknown users. } episode.ToggleWatchedStatus(true, true, FromUnixTime(metadata.LastViewedAt), false, false, user.JMMUserID, true); anime.UpdateStats(true, false, true); }