private static (SVR_AnimeEpisode, SVR_AnimeSeries) GetEpisode(PlexEvent.PlexMetadata metadata) { if (!metadata.Guid.StartsWith("com.plexapp.agents.shoko://")) { return(null, null); } string[] parts = metadata.Guid.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); int animeId = int.Parse(parts[1]); int series = int.Parse(parts[2]); var anime = Repo.Instance.AnimeSeries.GetByID(animeId); EpisodeType 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 = EpisodeType.Parody; break; case -3: episodeType = EpisodeType.Trailer; break; case -2: episodeType = EpisodeType.Other; break; case -1: episodeType = EpisodeType.Credits; break; case 0: episodeType = EpisodeType.Special; break; default: episodeType = EpisodeType.Episode; break; } if (episodeType != EpisodeType.Episode || metadata.Index == 0) //metadata.index = 0 when it's something else. { return(null, anime); //right now no clean way to detect the episode. I could do by title. } return(anime .GetAnimeEpisodes() .Where(a => a.AniDB_Episode != null) .Where(a => a.EpisodeTypeEnum == episodeType) .Where(a => metadata.Title.Equals(a?.PlexContract?.Title, StringComparison.InvariantCultureIgnoreCase)) .FirstOrDefault(a => a?.TvDBEpisode?.SeasonNumber == series), anime); }
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 static (SVR_AnimeEpisode, SVR_AnimeSeries) GetEpisode(PlexEvent.PlexMetadata metadata) { Uri guid = new Uri(metadata.Guid); if (guid.Scheme != "com.plexapp.agents.shoko") { return(null, null); } PathString ps = guid.AbsolutePath; int animeId = int.Parse(guid.Authority); int series = int.Parse(guid.AbsolutePath.Split('/')[1]); int episodeNumber = int.Parse(guid.AbsolutePath.Split('/')[2]); //if (!metadata.Guid.StartsWith("com.plexapp.agents.shoko://")) return (null, null); //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); EpisodeType 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 = EpisodeType.Parody; break; case -3: episodeType = EpisodeType.Trailer; break; case -2: episodeType = EpisodeType.Other; break; case -1: episodeType = EpisodeType.Credits; break; case 0: episodeType = EpisodeType.Special; break; default: episodeType = EpisodeType.Episode; break; } if (episodeType != EpisodeType.Episode || metadata.Index == 0) //metadata.index = 0 when it's something else. { return(null, anime); //right now no clean way to detect the episode. I could do by title. } var animeEps = anime .GetAnimeEpisodes().Where(a => a.AniDB_Episode != null) .Where(a => a.EpisodeTypeEnum == episodeType) .Where(a => a.PlexContract.EpisodeNumber == episodeNumber); //if only one possible match if (animeEps.Count() == 1) { return(animeEps.First(), anime); } //if TvDB matched. SVR_AnimeEpisode result; if ((result = animeEps.FirstOrDefault(a => a?.TvDBEpisode?.SeasonNumber == series)) != null) { return(result, anime); } //catch all logger.Info($"Unable to work out the metadata for {metadata.Guid}, this might be a clash of multipl episodes linked, but no tvdb link."); return(null, anime); }
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); }