mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 13:23:20 -07:00
More Emby improvements !wip
This commit is contained in:
parent
207d5c8d60
commit
075b336430
3 changed files with 56 additions and 38 deletions
|
@ -104,9 +104,9 @@ namespace Ombi.Api.Emby
|
||||||
return await GetAll<EmbyMovie>("Movie", apiKey, userId, baseUri, true, startIndex, count);
|
return await GetAll<EmbyMovie>("Movie", apiKey, userId, baseUri, true, startIndex, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<EmbyItemContainer<EmbyEpisodes>> GetAllEpisodes(string apiKey, string userId, string baseUri)
|
public async Task<EmbyItemContainer<EmbyEpisodes>> GetAllEpisodes(string apiKey, int startIndex, int count, string userId, string baseUri)
|
||||||
{
|
{
|
||||||
return await GetAll<EmbyEpisodes>("Episode", apiKey, userId, baseUri);
|
return await GetAll<EmbyEpisodes>("Episode", apiKey, userId, baseUri, false, startIndex, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<EmbyItemContainer<EmbySeries>> GetAllShows(string apiKey, int startIndex, int count, string userId, string baseUri)
|
public async Task<EmbyItemContainer<EmbySeries>> GetAllShows(string apiKey, int startIndex, int count, string userId, string baseUri)
|
||||||
|
|
|
@ -71,65 +71,83 @@ namespace Ombi.Schedule.Jobs.Emby
|
||||||
//await _repo.ExecuteSql("DELETE FROM EmbyEpisode");
|
//await _repo.ExecuteSql("DELETE FROM EmbyEpisode");
|
||||||
//await _repo.ExecuteSql("DELETE FROM EmbyContent");
|
//await _repo.ExecuteSql("DELETE FROM EmbyContent");
|
||||||
|
|
||||||
var movies = await _api.GetAllMovies(server.ApiKey,0, 200, server.AdministratorId, server.FullUri);
|
var movies = await _api.GetAllMovies(server.ApiKey, 0, 200, server.AdministratorId, server.FullUri);
|
||||||
var totalCount = movies.TotalRecordCount;
|
var totalCount = movies.TotalRecordCount;
|
||||||
var processed = 0;
|
var processed = 1;
|
||||||
|
|
||||||
var mediaToAdd = new HashSet<EmbyContent>();
|
var mediaToAdd = new HashSet<EmbyContent>();
|
||||||
|
|
||||||
while (processed < totalCount)
|
while (processed < totalCount)
|
||||||
{
|
{
|
||||||
foreach (var movie in movies.Items)
|
try
|
||||||
{
|
{
|
||||||
processed++;
|
foreach (var movie in movies.Items)
|
||||||
// Regular movie
|
{
|
||||||
await ProcessMovies(movie, mediaToAdd);
|
processed++;
|
||||||
}
|
// Regular movie
|
||||||
|
await ProcessMovies(movie, mediaToAdd);
|
||||||
|
}
|
||||||
|
|
||||||
// Get the next batch
|
// Get the next batch
|
||||||
movies = await _api.GetAllMovies(server.ApiKey, processed + 1, 200, server.AdministratorId, server.FullUri);
|
movies = await _api.GetAllMovies(server.ApiKey, processed, 200, server.AdministratorId, server.FullUri);
|
||||||
await _repo.AddRange(mediaToAdd);
|
await _repo.AddRange(mediaToAdd);
|
||||||
mediaToAdd.Clear();
|
mediaToAdd.Clear();
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TV Time
|
// TV Time
|
||||||
var tv = await _api.GetAllShows(server.ApiKey, 0, 200, server.AdministratorId, server.FullUri);
|
var tv = await _api.GetAllShows(server.ApiKey, 0, 200, server.AdministratorId, server.FullUri);
|
||||||
var totalTv = tv.TotalRecordCount;
|
var totalTv = tv.TotalRecordCount;
|
||||||
processed = 0;
|
processed = 1;
|
||||||
while (processed < totalTv)
|
while (processed < totalTv)
|
||||||
{
|
{
|
||||||
foreach (var tvShow in tv.Items)
|
foreach (var tvShow in tv.Items)
|
||||||
{
|
{
|
||||||
processed++;
|
try
|
||||||
if (string.IsNullOrEmpty(tvShow.ProviderIds?.Tvdb))
|
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Provider Id on tv {0} is null", tvShow.Name);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var existingTv = await _repo.GetByEmbyId(tvShow.Id);
|
processed++;
|
||||||
if (existingTv == null)
|
if (string.IsNullOrEmpty(tvShow.ProviderIds?.Tvdb))
|
||||||
{
|
|
||||||
_logger.LogDebug("Adding new TV Show {0}", tvShow.Name);
|
|
||||||
mediaToAdd.Add(new EmbyContent
|
|
||||||
{
|
{
|
||||||
TvDbId = tvShow.ProviderIds?.Tvdb,
|
_logger.LogInformation("Provider Id on tv {0} is null", tvShow.Name);
|
||||||
ImdbId = tvShow.ProviderIds?.Imdb,
|
continue;
|
||||||
TheMovieDbId = tvShow.ProviderIds?.Tmdb,
|
}
|
||||||
Title = tvShow.Name,
|
|
||||||
Type = EmbyMediaType.Series,
|
var existingTv = await _repo.GetByEmbyId(tvShow.Id);
|
||||||
EmbyId = tvShow.Id,
|
if (existingTv == null)
|
||||||
Url = EmbyHelper.GetEmbyMediaUrl(tvShow.Id),
|
{
|
||||||
AddedAt = DateTime.UtcNow
|
_logger.LogDebug("Adding new TV Show {0}", tvShow.Name);
|
||||||
});
|
mediaToAdd.Add(new EmbyContent
|
||||||
|
{
|
||||||
|
TvDbId = tvShow.ProviderIds?.Tvdb,
|
||||||
|
ImdbId = tvShow.ProviderIds?.Imdb,
|
||||||
|
TheMovieDbId = tvShow.ProviderIds?.Tmdb,
|
||||||
|
Title = tvShow.Name,
|
||||||
|
Type = EmbyMediaType.Series,
|
||||||
|
EmbyId = tvShow.Id,
|
||||||
|
Url = EmbyHelper.GetEmbyMediaUrl(tvShow.Id),
|
||||||
|
AddedAt = DateTime.UtcNow
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogDebug("We already have TV Show {0}", tvShow.Name);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
catch (Exception)
|
||||||
{
|
{
|
||||||
_logger.LogDebug("We already have TV Show {0}", tvShow.Name);
|
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Get the next batch
|
// Get the next batch
|
||||||
tv = await _api.GetAllShows(server.ApiKey, processed + 1, 200, server.AdministratorId, server.FullUri);
|
tv = await _api.GetAllShows(server.ApiKey, processed, 200, server.AdministratorId, server.FullUri);
|
||||||
await _repo.AddRange(mediaToAdd);
|
await _repo.AddRange(mediaToAdd);
|
||||||
mediaToAdd.Clear();
|
mediaToAdd.Clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ namespace Ombi.Schedule.Jobs.Emby
|
||||||
{
|
{
|
||||||
var allEpisodes = await _api.GetAllEpisodes(server.ApiKey, 0, 200, server.AdministratorId, server.FullUri);
|
var allEpisodes = await _api.GetAllEpisodes(server.ApiKey, 0, 200, server.AdministratorId, server.FullUri);
|
||||||
var total = allEpisodes.TotalRecordCount;
|
var total = allEpisodes.TotalRecordCount;
|
||||||
var processed = 0;
|
var processed = 1;
|
||||||
var epToAdd = new HashSet<EmbyEpisode>();
|
var epToAdd = new HashSet<EmbyEpisode>();
|
||||||
while (processed < total)
|
while (processed < total)
|
||||||
{
|
{
|
||||||
|
@ -117,7 +117,7 @@ namespace Ombi.Schedule.Jobs.Emby
|
||||||
|
|
||||||
await _repo.AddRange(epToAdd);
|
await _repo.AddRange(epToAdd);
|
||||||
epToAdd.Clear();
|
epToAdd.Clear();
|
||||||
allEpisodes = await _api.GetAllEpisodes(server.ApiKey, processed + 1, 200, server.AdministratorId, server.FullUri);
|
allEpisodes = await _api.GetAllEpisodes(server.ApiKey, processed, 200, server.AdministratorId, server.FullUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (epToAdd.Any())
|
if (epToAdd.Any())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue