Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DontRemoveFromCollection option. #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Trakt/Configuration/configPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ <h3 class="checkboxListLabel">Exclude folders:</h3>
When checked items will to be added to or removed from collection on Trakt.
</div>
</div>
<div class="checkboxContainer checkboxContainer-withDescription">
<label>
<input is="emby-checkbox" type="checkbox" id="chkDontRemoveFromCollection" name="chkDontRemoveFromCollection" />
<span>Don't Remove From Collection</span>
</label>
<div class="fieldDescription checkboxFieldDescription">
Don't remove the item in the Trakt Collection when removed from the local library.
</div>
</div>
<div class="checkboxContainer checkboxContainer-withDescription">
<label>
<input is="emby-checkbox" type="checkbox" id="chkExtraLogging" name="chkExtraLogging" />
Expand Down Expand Up @@ -120,10 +129,11 @@ <h3 class="checkboxListLabel">Exclude folders:</h3>
}
// Default this to an empty array so the rendering code doesn't have to worry about it
currentUserConfig.LocationsExcluded = currentUserConfig.LocationsExcluded || [];
$('#txtTraktPIN', page).val(currentUserConfig.PIN);
$('#txtTraktPIN', page).val(currentUserConfig.PIN);
page.querySelector('#chkSkipUnwatchedImportFromTrakt').checked = currentUserConfig.SkipUnwatchedImportFromTrakt;
page.querySelector('#chkPostWatchedHistory').checked = currentUserConfig.PostWatchedHistory;
page.querySelector('#chkSyncCollection').checked = currentUserConfig.SyncCollection;
page.querySelector('#chkDontRemoveFromCollection').checked = currentUserConfig.DontRemoveFromCollection;
page.querySelector('#chkExtraLogging').checked = currentUserConfig.ExtraLogging;
page.querySelector('#chkExportMediaInfo').checked = currentUserConfig.ExportMediaInfo;
// List the folders the user can access
Expand Down Expand Up @@ -185,6 +195,7 @@ <h3 class="checkboxListLabel">Exclude folders:</h3>
currentUserConfig.SkipUnwatchedImportFromTrakt = page.querySelector('#chkSkipUnwatchedImportFromTrakt').checked;
currentUserConfig.PostWatchedHistory = page.querySelector('#chkPostWatchedHistory').checked;
currentUserConfig.SyncCollection = page.querySelector('#chkSyncCollection').checked;
currentUserConfig.DontRemoveFromCollection = page.querySelector('#chkDontRemoveFromCollection').checked;
currentUserConfig.ExtraLogging = page.querySelector('#chkExtraLogging').checked;
currentUserConfig.ExportMediaInfo = page.querySelector('#chkExportMediaInfo').checked;
currentUserConfig.PIN = $('#txtTraktPIN', page).val();
Expand Down
15 changes: 10 additions & 5 deletions Trakt/Helpers/LibraryManagerEventsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class LibraryManagerEventsHelper
private readonly TraktApi _traktApi;

/// <summary>
///
///
/// </summary>
/// <param name="logger"></param>
/// <param name="traktApi"></param>
Expand All @@ -33,7 +33,7 @@ public LibraryManagerEventsHelper(ILogger logger, TraktApi traktApi)
}

/// <summary>
///
///
/// </summary>
/// <param name="item"></param>
/// <param name="eventType"></param>
Expand All @@ -59,6 +59,11 @@ public void QueueItem(BaseItem item, EventType eventType)
// we need to process the video for each user
foreach (var user in users.Where(x => _traktApi.CanSync(item, x)))
{
if (eventType == EventType.Remove && user.DontRemoveFromCollection)
{
continue;
}

// we have a match, this user is watching the folder the video is in. Add to queue and they
// will be processed when the next timer elapsed event fires.
var libraryEvent = new LibraryEvent { Item = item, TraktUser = user, EventType = eventType };
Expand All @@ -68,7 +73,7 @@ public void QueueItem(BaseItem item, EventType eventType)
}

/// <summary>
///
///
/// </summary>
private async void OnQueueTimerCallback(object state)
{
Expand Down Expand Up @@ -194,7 +199,7 @@ private async Task ProcessQueuedShowEvents(IEnumerable<LibraryEvent> events, Tra
}

/// <summary>
///
///
/// </summary>
/// <param name="events"></param>
/// <param name="traktUser"></param>
Expand All @@ -217,7 +222,7 @@ private async Task ProcessQueuedMovieEvents(IEnumerable<LibraryEvent> events, Tr
}

/// <summary>
///
///
/// </summary>
/// <param name="events"></param>
/// <param name="traktUser"></param>
Expand Down
6 changes: 4 additions & 2 deletions Trakt/Model/TraktUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Trakt.Model
public class TraktUser
{
public String PIN { get; set; }

public String AccessToken { get; set; }

public String RefreshToken { get; set; }
Expand All @@ -14,12 +14,14 @@ public class TraktUser

public bool UsesAdvancedRating { get; set; }

public bool SkipUnwatchedImportFromTrakt { get; set; }
public bool SkipUnwatchedImportFromTrakt { get; set; }

public bool PostWatchedHistory { get; set; }

public bool SyncCollection { get; set; }

public bool DontRemoveFromCollection { get; set; }

public bool ExtraLogging { get; set; }

public bool ExportMediaInfo { get; set; }
Expand Down
20 changes: 12 additions & 8 deletions Trakt/ScheduledTasks/SyncLibraryTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Trakt.ScheduledTasks
using Trakt.Model;

/// <summary>
/// Task that will Sync each users local library with their respective trakt.tv profiles. This task will only include
/// Task that will Sync each users local library with their respective trakt.tv profiles. This task will only include
/// titles, watched states will be synced in other tasks.
/// </summary>
public class SyncLibraryTask : IScheduledTask
Expand Down Expand Up @@ -223,8 +223,11 @@ private async Task SyncMovies(
// send movies to mark collected
await SendMovieCollectionAdds(traktUser, collectedMovies, progress.Split(4), cancellationToken).ConfigureAwait(false);

// send movies to mark uncollected
await SendMovieCollectionRemoves(traktUser, uncollectedMovies, progress.Split(4), cancellationToken).ConfigureAwait(false);
if (!traktUser.DontRemoveFromCollection)
{
// send movies to mark uncollected
await SendMovieCollectionRemoves(traktUser, uncollectedMovies, progress.Split(4), cancellationToken).ConfigureAwait(false);
}
}
// send movies to mark watched
await SendMoviePlaystateUpdates(true, traktUser, playedMovies, progress.Split(4), cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -277,6 +280,7 @@ private async Task SendMovieCollectionAdds(
ISplittableProgress<double> progress,
CancellationToken cancellationToken)
{
_logger.Info("Dont Remove Collections: ", traktUser.DontRemoveFromCollection);
_logger.Info("Movies to add to collection: " + movies.Count);
if (movies.Count > 0)
{
Expand Down Expand Up @@ -486,18 +490,18 @@ private async Task SyncShows(
_logger.Debug("Could not match {0} to any Emby show, marking for collection removal", _jsonSerializer.SerializeToString(traktShowCollected.show));
uncollectedShows.Add(new TraktShowCollected() { ids = traktShowCollected.show.ids, title = traktShowCollected.show.title, year = traktShowCollected.show.year });
}



}

if (traktUser.SyncCollection)
{
await SendEpisodeCollectionAdds(traktUser, collectedEpisodes, progress.Split(4), cancellationToken)
.ConfigureAwait(false);

await SendEpisodeCollectionRemovals(traktUser, uncollectedShows, progress.Split(5), cancellationToken)
.ConfigureAwait(false);
if (!traktUser.DontRemoveFromCollection)
{
await SendEpisodeCollectionRemovals(traktUser, uncollectedShows, progress.Split(5), cancellationToken)
.ConfigureAwait(false);
}
}

await SendEpisodePlaystateUpdates(true, traktUser, playedEpisodes, progress.Split(4), cancellationToken).ConfigureAwait(false);
Expand Down
4 changes: 2 additions & 2 deletions Trakt/Trakt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;</TargetFrameworks>
<AssemblyVersion>3.4.4.0</AssemblyVersion>
<FileVersion>3.4.4.0</FileVersion>
<AssemblyVersion>3.4.5.0</AssemblyVersion>
<FileVersion>3.4.5.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down