Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ShokoAnime/ShokoServer
Browse files Browse the repository at this point in the history
  • Loading branch information
Cazzar committed Mar 22, 2018
2 parents 74fa3e6 + b6a5303 commit 6233e4f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
8 changes: 5 additions & 3 deletions Shoko.Server/Commands/AniDB/CommandRequest_AddFileToMyList.cs
Expand Up @@ -63,7 +63,6 @@ public override void ProcessCommand()
{
if (vid == null) return;

List<SVR_AnimeEpisode> animeEpisodes = vid.GetAnimeEpisodes();
// when adding a file via the API, newWatchedStatus will return with current watched status on AniDB
// if the file is already on the user's list

Expand Down Expand Up @@ -128,7 +127,10 @@ public override void ProcessCommand()
}
}

SVR_AnimeSeries ser = animeEpisodes[0].GetAnimeSeries();
// if we don't have xrefs, then no series or eps.
if (xrefs.Count <= 0) return;

SVR_AnimeSeries ser = RepoFactory.AnimeSeries.GetByAnimeID(xrefs[0].AnimeID);
// all the eps should belong to the same anime
ser.QueueUpdateStats();
//StatsCache.Instance.UpdateUsingSeries(ser.AnimeSeriesID);
Expand All @@ -137,7 +139,7 @@ public override void ProcessCommand()
if (ServerSettings.Trakt_IsEnabled &&
!string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken))
{
foreach (SVR_AnimeEpisode aep in animeEpisodes)
foreach (SVR_AnimeEpisode aep in vid.GetAnimeEpisodes())
{
CommandRequest_TraktCollectionEpisode cmdSyncTrakt =
new CommandRequest_TraktCollectionEpisode(aep.AnimeEpisodeID, TraktSyncAction.Add);
Expand Down
8 changes: 4 additions & 4 deletions Shoko.Server/Commands/Trakt/CommandRequest_TraktUpdateInfo.cs
Expand Up @@ -36,23 +36,23 @@ public CommandRequest_TraktUpdateInfo(string traktID)

public override void ProcessCommand()
{
logger.Info("Processing CommandRequest_TraktUpdateInfoAndImages: {0}", TraktID);
logger.Info("Processing CommandRequest_TraktUpdateInfo: {0}", TraktID);

try
{
TraktTVHelper.UpdateAllInfo(TraktID);
}
catch (Exception ex)
{
logger.Error("Error processing CommandRequest_TraktUpdateInfoAndImages: {0} - {1}", TraktID,
logger.Error("Error processing CommandRequest_TraktUpdateInfo: {0} - {1}", TraktID,
ex);
}
}


public override void GenerateCommandID()
{
CommandID = $"CommandRequest_TraktUpdateInfoAndImages{TraktID}";
CommandID = $"CommandRequest_TraktUpdateInfo{TraktID}";
}

public override bool LoadFromDBCommand(CommandRequest cq)
Expand All @@ -70,7 +70,7 @@ public override bool LoadFromDBCommand(CommandRequest cq)
docCreator.LoadXml(CommandDetails);

// populate the fields
TraktID = TryGetProperty(docCreator, "CommandRequest_TraktUpdateInfoAndImages", "TraktID");
TraktID = TryGetProperty(docCreator, "CommandRequest_TraktUpdateInfo", "TraktID");
}

return true;
Expand Down
8 changes: 8 additions & 0 deletions Shoko.Server/Extensions/ModelDatabase.cs
Expand Up @@ -69,6 +69,14 @@ public static void CreateAnimeEpisode(this AniDB_Episode episode, ISession sessi
animeEp.AnimeSeriesID = animeSeriesID;
RepoFactory.AnimeEpisode.Save(animeEp);
}
else
{
if (existingEp.AnimeSeriesID != animeSeriesID) existingEp.AnimeSeriesID = animeSeriesID;
existingEp.PlexContract = null;
RepoFactory.AnimeEpisode.Save(existingEp);
foreach (var episodeUser in RepoFactory.AnimeEpisode_User.GetByEpisodeID(existingEp.AnimeEpisodeID))
RepoFactory.AnimeEpisode_User.SaveWithOpenTransaction(session, episodeUser);
}
}

public static MovieDB_Movie GetMovieDB_Movie(this CrossRef_AniDB_Other cross)
Expand Down
17 changes: 14 additions & 3 deletions Shoko.Server/Models/SVR_VideoLocal.cs
Expand Up @@ -289,6 +289,9 @@ public void ToggleWatchedStatus(bool watched, int userID)
{
// get the episodes for this file, may be more than one (One Piece x Toriko)
SVR_AnimeEpisode ep = RepoFactory.AnimeEpisode.GetByAniDBEpisodeID(xref.EpisodeID);
// a show we don't have
if (ep == null) continue;

// get all the files for this episode
int epPercentWatched = 0;
foreach (CrossRef_File_Episode filexref in ep.FileCrossRefs)
Expand All @@ -303,6 +306,8 @@ public void ToggleWatchedStatus(bool watched, int userID)
if (epPercentWatched > 95)
{
ser = ep.GetAnimeSeries();
// a problem
if (ser == null) continue;
if (!toUpdateSeries.ContainsKey(ser.AnimeSeriesID))
toUpdateSeries.Add(ser.AnimeSeriesID, ser);
if (user.IsAniDBUser == 0)
Expand Down Expand Up @@ -337,9 +342,9 @@ public void ToggleWatchedStatus(bool watched, int userID)
{
// get the episodes for this file, may be more than one (One Piece x Toriko)
SVR_AnimeEpisode ep = RepoFactory.AnimeEpisode.GetByAniDBEpisodeID(xrefEp.EpisodeID);
ser = ep.GetAnimeSeries();
if (!toUpdateSeries.ContainsKey(ser.AnimeSeriesID))
toUpdateSeries.Add(ser.AnimeSeriesID, ser);
// a show we don't have
if (ep == null) continue;

// get all the files for this episode
int epPercentWatched = 0;
foreach (CrossRef_File_Episode filexref in ep.FileCrossRefs)
Expand All @@ -360,6 +365,12 @@ public void ToggleWatchedStatus(bool watched, int userID)
if (juser.IsAniDBUser == 1)
ep.SaveWatchedStatus(false, juser.JMMUserID, watchedDate, true);

ser = ep.GetAnimeSeries();
// a problem
if (ser == null) continue;
if (!toUpdateSeries.ContainsKey(ser.AnimeSeriesID))
toUpdateSeries.Add(ser.AnimeSeriesID, ser);

if (syncTrakt && ServerSettings.Trakt_IsEnabled &&
!string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken))
{
Expand Down
4 changes: 2 additions & 2 deletions Shoko.Server/Providers/TraktTV/TraktURIs.cs
Expand Up @@ -30,11 +30,11 @@ public static class TraktURIs

// http://docs.trakt.apiary.io/#reference/shows/summary/get-a-single-show
// {0} trakt ID, trakt slug, or IMDB ID Example: game-of-thrones
public const string ShowSummary = TraktConstants.BaseAPIURL + @"/shows/{0}?extended=full,images";
public const string ShowSummary = TraktConstants.BaseAPIURL + @"/shows/{0}?extended=full";

// http://docs.trakt.apiary.io/#reference/seasons/summary/get-all-seasons-for-a-show
// {0} trakt ID, trakt slug, or IMDB ID Example: game-of-thrones
public const string ShowSeasons = TraktConstants.BaseAPIURL + @"/shows/{0}/seasons?extended=episodes,images";
public const string ShowSeasons = TraktConstants.BaseAPIURL + @"/shows/{0}/seasons?extended=episodes";

// get comments for a show
// http://docs.trakt.apiary.io/#reference/shows/watched-progress/get-all-show-comments
Expand Down

0 comments on commit 6233e4f

Please sign in to comment.