Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bakes82 committed Nov 23, 2020
1 parent 86729d8 commit 72eeca9
Show file tree
Hide file tree
Showing 23 changed files with 1,669 additions and 39 deletions.
4 changes: 2 additions & 2 deletions TraktLists/Api/TraktURIs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{
public static class TraktUris
{
public const string Id = "c44548028dcd8f31e9bee55318562e6e5deb8524f5ca3e77e167fd3b1c9ce380";
public const string Secret = "d453bc07bcf42f72e3915715a5275d99de8381ff007c84d20e89ed1070310c89";
public const string Id = "780354638b11da9a2e93e0c4498d6a1a0e8428a6da3cca70c98c19c8f0caeb52";
public const string Secret = "113ea33e3283ef7349dfe0cb675aee83fe49be9ee540eb81fb1aec3f676b9f71";

#region POST URI's

Expand Down
28 changes: 11 additions & 17 deletions TraktLists/Channels/ChannelHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task<ChannelItemResult> GetChannelItemResult(IUserManager userManag
ILibraryManager libraryManager, TraktChannel channelToConfigure, ILogger logger, TraktApi traktApi,
CancellationToken cancellationToken)
{
await Plugin.Instance.SchedTaskResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
//await Plugin.Instance.SchedTaskResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);

try
{
Expand Down Expand Up @@ -139,13 +139,7 @@ public async Task<ChannelItemResult> GetChannelItemResult(IUserManager userManag

logger.Info(channelToConfigure.ChannelName);
logger.Info("Found " + channelLibraryItem.Length.ToString());


// ReSharper disable once ComplexConditionExpression
var ids = libraryManager.GetInternalItemIds(new InternalItemsQuery
{
IncludeItemTypes = new[] {"Movie"}
});

var libraryItems = libraryManager.GetInternalItemIds(new InternalItemsQuery
{
Expand Down Expand Up @@ -177,15 +171,21 @@ public async Task<ChannelItemResult> GetChannelItemResult(IUserManager userManag
logger.Info($"Count of items in emby {mediaItems.Count}");

var foundMovies = new List<string>();
var notFoundMovies = new List<string>();
//var notFoundMovies = new List<string>();

logger.Info("Internal Ids: " + string.Join(", ", libraryItems.Select(x => x.ToString()).ToArray()));

foreach (var movie in mediaItems.OfType<Movie>())
foreach (var movie in mediaItems.OfType<Movie>().OrderBy(x => x.Name))
{
if (channels.Select(x => x.ParentId).Contains(movie.Parent.ParentId))
{
continue;
}

//Logger.Info($"Movie {movie.Name}");

//logger.Info(movie.InternalId.ToString());

if (libraryItems.Contains(movie.InternalId)) continue;

var foundMovie = Match.FindMatch(movie, listData);
Expand Down Expand Up @@ -224,11 +224,6 @@ public async Task<ChannelItemResult> GetChannelItemResult(IUserManager userManag
// }
}
}
else
{
notFoundMovies.Add(movie.Name);
//logger.Debug($"Movie {movie.Name} not found");
}
}

logger.Info($"Count of items in List to add {newItems.Count}");
Expand All @@ -238,8 +233,7 @@ public async Task<ChannelItemResult> GetChannelItemResult(IUserManager userManag
logger.Info($"Count of distinct items in List to add {distinctItems.Count}");

logger.Info("Found Movies: " + string.Join(", ", foundMovies.Select(x => x.ToString()).ToArray()));
logger.Info(
"Not Found Movies: " + string.Join(", ", notFoundMovies.Select(x => x.ToString()).ToArray()));
//logger.Info("Not Found Movies: " + string.Join(", ", notFoundMovies.Select(x => x.ToString()).ToArray()));

logger.Info(
"Not Found Movies: " + string.Join(", ", distinctItems.Select(x => x.Id.ToString()).ToArray()));
Expand All @@ -252,7 +246,7 @@ public async Task<ChannelItemResult> GetChannelItemResult(IUserManager userManag
}
finally
{
Plugin.Instance.SchedTaskResourcePool.Release();
//Plugin.Instance.SchedTaskResourcePool.Release();
}
}
}
Expand Down
127 changes: 127 additions & 0 deletions TraktLists/Channels/PreConfigured/ChannelP10.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Channels;
using MediaBrowser.Model.Drawing;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using TraktLists.Api;
using TraktLists.Channels;

namespace TraktLists
{
public class ChannelP10 : IChannel, IHasCacheKey, IRequiresMediaInfoCallback
{
private IHttpClient HttpClient { get; }
private ILogger Logger { get; }
private IJsonSerializer JsonSerializer { get; }
private ILibraryManager LibraryManager { get; }
private IUserManager UserManager { get; }
private TraktApi TraktApi { get; }

private readonly TraktChannel _channelToConfigure = Plugin.Instance.PluginConfiguration.PreConfiguredTraktChannels.Single(x => x.Id == 10);

public ChannelP10(IHttpClient httpClient, ILogManager logManager, IJsonSerializer jsonSerializer, ILibraryManager lib, TraktApi traktApi, IUserManager userManager)
{
HttpClient = httpClient;
Logger = logManager.GetLogger(GetType().Name);
JsonSerializer = jsonSerializer;
LibraryManager = lib;
TraktApi = traktApi;
UserManager = userManager;
}

public string DataVersion => "12";

public InternalChannelFeatures GetChannelFeatures()
{
return new InternalChannelFeatures
{
ContentTypes = new List<ChannelMediaContentType>
{
ChannelMediaContentType.Movie
},

MediaTypes = new List<ChannelMediaType>
{
ChannelMediaType.Video
},

SupportsContentDownloading = true,
SupportsSortOrderToggle = true,
};
}

private async Task<ChannelItemResult> GetChannelItemsInternal(CancellationToken cancellationToken)
{
var helper = new ChannelHelper();
return await helper.GetChannelItemResult(UserManager, LibraryManager, _channelToConfigure, Logger, TraktApi, cancellationToken);
}

public bool IsEnabledFor(string userId)
{
return true;
}

public async Task<ChannelItemResult> GetChannelItems(InternalChannelItemQuery query, CancellationToken cancellationToken)
{
return await GetChannelItemsInternal(cancellationToken);
}

public async Task<DynamicImageResponse> GetChannelImage(ImageType type, CancellationToken cancellationToken)
{
switch (type)
{
case ImageType.Backdrop:
{
var path = GetType().Namespace + ".Images." + type.ToString().ToLower() + ".png";

return await Task.FromResult(new DynamicImageResponse
{
Format = ImageFormat.Png,
HasImage = true,
Stream = GetType().Assembly.GetManifestResourceStream(path)
});
}
default:
throw new ArgumentException("Unsupported image type: " + type);

}
}

public IEnumerable<ImageType> GetSupportedChannelImages()
{
return new List<ImageType> { ImageType.Primary, ImageType.Thumb };
}

public string Name => _channelToConfigure.ChannelName;
public string Description { get; private set; }
public string HomePageUrl
{
get { return ""; }
}

public ChannelParentalRating ParentalRating
{
get { return ChannelParentalRating.GeneralAudience; }
}

public string GetCacheKey(string userId)
{
return Guid.NewGuid().ToString("N");
}

public Task<IEnumerable<MediaSourceInfo>> GetChannelItemMediaInfo(string id, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
}
127 changes: 127 additions & 0 deletions TraktLists/Channels/PreConfigured/ChannelP11.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Channels;
using MediaBrowser.Model.Drawing;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using TraktLists.Api;
using TraktLists.Channels;

namespace TraktLists
{
public class ChannelP11 : IChannel, IHasCacheKey, IRequiresMediaInfoCallback
{
private IHttpClient HttpClient { get; }
private ILogger Logger { get; }
private IJsonSerializer JsonSerializer { get; }
private ILibraryManager LibraryManager { get; }
private IUserManager UserManager { get; }
private TraktApi TraktApi { get; }

private readonly TraktChannel _channelToConfigure = Plugin.Instance.PluginConfiguration.PreConfiguredTraktChannels.Single(x => x.Id == 11);

public ChannelP11(IHttpClient httpClient, ILogManager logManager, IJsonSerializer jsonSerializer, ILibraryManager lib, TraktApi traktApi, IUserManager userManager)
{
HttpClient = httpClient;
Logger = logManager.GetLogger(GetType().Name);
JsonSerializer = jsonSerializer;
LibraryManager = lib;
TraktApi = traktApi;
UserManager = userManager;
}

public string DataVersion => "12";

public InternalChannelFeatures GetChannelFeatures()
{
return new InternalChannelFeatures
{
ContentTypes = new List<ChannelMediaContentType>
{
ChannelMediaContentType.Movie
},

MediaTypes = new List<ChannelMediaType>
{
ChannelMediaType.Video
},

SupportsContentDownloading = true,
SupportsSortOrderToggle = true,
};
}

private async Task<ChannelItemResult> GetChannelItemsInternal(CancellationToken cancellationToken)
{
var helper = new ChannelHelper();
return await helper.GetChannelItemResult(UserManager, LibraryManager, _channelToConfigure, Logger, TraktApi, cancellationToken);
}

public bool IsEnabledFor(string userId)
{
return true;
}

public async Task<ChannelItemResult> GetChannelItems(InternalChannelItemQuery query, CancellationToken cancellationToken)
{
return await GetChannelItemsInternal(cancellationToken);
}

public async Task<DynamicImageResponse> GetChannelImage(ImageType type, CancellationToken cancellationToken)
{
switch (type)
{
case ImageType.Backdrop:
{
var path = GetType().Namespace + ".Images." + type.ToString().ToLower() + ".png";

return await Task.FromResult(new DynamicImageResponse
{
Format = ImageFormat.Png,
HasImage = true,
Stream = GetType().Assembly.GetManifestResourceStream(path)
});
}
default:
throw new ArgumentException("Unsupported image type: " + type);

}
}

public IEnumerable<ImageType> GetSupportedChannelImages()
{
return new List<ImageType> { ImageType.Primary, ImageType.Thumb };
}

public string Name => _channelToConfigure.ChannelName;
public string Description { get; private set; }
public string HomePageUrl
{
get { return ""; }
}

public ChannelParentalRating ParentalRating
{
get { return ChannelParentalRating.GeneralAudience; }
}

public string GetCacheKey(string userId)
{
return Guid.NewGuid().ToString("N");
}

public Task<IEnumerable<MediaSourceInfo>> GetChannelItemMediaInfo(string id, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
}
Loading

0 comments on commit 72eeca9

Please sign in to comment.