support manual downloading of studio images
This commit is contained in:
parent
9edbc9ff8b
commit
e19766b1b7
|
@ -121,6 +121,7 @@
|
||||||
<Compile Include="Savers\SeriesXmlSaver.cs" />
|
<Compile Include="Savers\SeriesXmlSaver.cs" />
|
||||||
<Compile Include="Savers\XmlSaverHelpers.cs" />
|
<Compile Include="Savers\XmlSaverHelpers.cs" />
|
||||||
<Compile Include="Studios\StudioImageProvider.cs" />
|
<Compile Include="Studios\StudioImageProvider.cs" />
|
||||||
|
<Compile Include="Studios\StudiosManualImageProvider.cs" />
|
||||||
<Compile Include="TV\EpisodeImageFromMediaLocationProvider.cs" />
|
<Compile Include="TV\EpisodeImageFromMediaLocationProvider.cs" />
|
||||||
<Compile Include="TV\EpisodeIndexNumberProvider.cs" />
|
<Compile Include="TV\EpisodeIndexNumberProvider.cs" />
|
||||||
<Compile Include="TV\EpisodeProviderFromXml.cs" />
|
<Compile Include="TV\EpisodeProviderFromXml.cs" />
|
||||||
|
@ -167,7 +168,10 @@
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Studios\images.txt" />
|
<EmbeddedResource Include="Studios\backdrops.txt" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="Studios\posters.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition=" '$(ConfigurationName)' != 'Release Mono' " />
|
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition=" '$(ConfigurationName)' != 'Release Mono' " />
|
||||||
|
|
|
@ -4,10 +4,12 @@ using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.Logging;
|
using MediaBrowser.Model.Logging;
|
||||||
|
using MediaBrowser.Model.Net;
|
||||||
|
using MediaBrowser.Model.Providers;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
@ -47,7 +49,7 @@ namespace MediaBrowser.Providers.Studios
|
||||||
|
|
||||||
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(item.PrimaryImagePath))
|
if (!string.IsNullOrEmpty(item.PrimaryImagePath) && item.BackdropImagePaths.Count == 0)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -67,65 +69,70 @@ namespace MediaBrowser.Providers.Studios
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return "1";
|
return "3";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<bool> FetchAsync(BaseItem item, bool force, BaseProviderInfo providerInfo, CancellationToken cancellationToken)
|
public override async Task<bool> FetchAsync(BaseItem item, bool force, BaseProviderInfo providerInfo, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(item.PrimaryImagePath))
|
if (string.IsNullOrEmpty(item.PrimaryImagePath) || item.BackdropImagePaths.Count == 0)
|
||||||
{
|
{
|
||||||
var list = GetAvailableImages();
|
var images = await _providerManager.GetAvailableRemoteImages(item, cancellationToken, StudiosManualImageProvider.ProviderName).ConfigureAwait(false);
|
||||||
|
|
||||||
var match = FindMatch(item, list);
|
await DownloadImages(item, images.ToList(), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(match))
|
|
||||||
{
|
|
||||||
var url = GetUrl(match);
|
|
||||||
|
|
||||||
await _providerManager.SaveImage(item, url, _resourcePool, ImageType.Primary, null, cancellationToken).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetLastRefreshed(item, DateTime.UtcNow, providerInfo);
|
SetLastRefreshed(item, DateTime.UtcNow, providerInfo);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string FindMatch(BaseItem item, IEnumerable<string> images)
|
private async Task DownloadImages(BaseItem item, List<RemoteImageInfo> images, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var name = GetComparableName(item.Name);
|
if (!item.LockedFields.Contains(MetadataFields.Images))
|
||||||
|
|
||||||
return images.FirstOrDefault(i => string.Equals(name, GetComparableName(i), StringComparison.OrdinalIgnoreCase));
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetComparableName(string name)
|
|
||||||
{
|
|
||||||
return name.Replace(" ", string.Empty).Replace(".", string.Empty).Replace("&", string.Empty).Replace("!", string.Empty);
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetUrl(string image)
|
|
||||||
{
|
|
||||||
return string.Format("https://raw.github.com/MediaBrowser/MediaBrowser.Resources/master/images/studios/{0}/folder.jpg", image);
|
|
||||||
}
|
|
||||||
|
|
||||||
private IEnumerable<string> GetAvailableImages()
|
|
||||||
{
|
|
||||||
var path = GetType().Namespace + ".images.txt";
|
|
||||||
|
|
||||||
using (var stream = GetType().Assembly.GetManifestResourceStream(path))
|
|
||||||
{
|
{
|
||||||
using (var reader = new StreamReader(stream))
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
|
if (!item.HasImage(ImageType.Primary))
|
||||||
{
|
{
|
||||||
var lines = new List<string>();
|
await SaveImage(item, images, ImageType.Primary, cancellationToken).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (!reader.EndOfStream)
|
if (!item.LockedFields.Contains(MetadataFields.Backdrops))
|
||||||
|
{
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
|
if (item.BackdropImagePaths.Count == 0)
|
||||||
|
{
|
||||||
|
foreach (var image in images.Where(i => i.Type == ImageType.Backdrop))
|
||||||
{
|
{
|
||||||
var text = reader.ReadLine();
|
await _providerManager.SaveImage(item, image.Url, _resourcePool, ImageType.Backdrop, null, cancellationToken)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
lines.Add(text);
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return lines;
|
|
||||||
|
private async Task SaveImage(BaseItem item, IEnumerable<RemoteImageInfo> images, ImageType type, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
foreach (var image in images.Where(i => i.Type == type))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _providerManager.SaveImage(item, image.Url, _resourcePool, type, null, cancellationToken).ConfigureAwait(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (HttpException ex)
|
||||||
|
{
|
||||||
|
// Sometimes fanart has bad url's in their xml
|
||||||
|
if (ex.StatusCode.HasValue && ex.StatusCode.Value == HttpStatusCode.NotFound)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
135
MediaBrowser.Providers/Studios/StudiosManualImageProvider.cs
Normal file
135
MediaBrowser.Providers/Studios/StudiosManualImageProvider.cs
Normal file
|
@ -0,0 +1,135 @@
|
||||||
|
using MediaBrowser.Controller.Entities;
|
||||||
|
using MediaBrowser.Controller.Providers;
|
||||||
|
using MediaBrowser.Model.Entities;
|
||||||
|
using MediaBrowser.Model.Providers;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MediaBrowser.Providers.Studios
|
||||||
|
{
|
||||||
|
public class StudiosManualImageProvider : IImageProvider
|
||||||
|
{
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return ProviderName; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ProviderName
|
||||||
|
{
|
||||||
|
get { return "Media Browser"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Supports(IHasImages item)
|
||||||
|
{
|
||||||
|
return item is Studio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<IEnumerable<RemoteImageInfo>> GetImages(IHasImages item, ImageType imageType, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return GetImages(item, imageType == ImageType.Primary, imageType == ImageType.Backdrop, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<IEnumerable<RemoteImageInfo>> GetAllImages(IHasImages item, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return GetImages(item, true, true, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task<IEnumerable<RemoteImageInfo>> GetImages(IHasImages item, bool posters, bool backdrops, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var list = new List<RemoteImageInfo>();
|
||||||
|
|
||||||
|
if (posters)
|
||||||
|
{
|
||||||
|
list.Add(GetImage(item, "posters.txt", ImageType.Primary, "folder"));
|
||||||
|
}
|
||||||
|
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
|
if (backdrops)
|
||||||
|
{
|
||||||
|
list.Add(GetImage(item, "backdrops.txt", ImageType.Backdrop, "backdrop"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.FromResult(list.Where(i => i != null));
|
||||||
|
}
|
||||||
|
|
||||||
|
private RemoteImageInfo GetImage(IHasImages item, string filename, ImageType type, string remoteFilename)
|
||||||
|
{
|
||||||
|
var url = GetUrl(item, filename, remoteFilename);
|
||||||
|
|
||||||
|
if (url != null)
|
||||||
|
{
|
||||||
|
return new RemoteImageInfo
|
||||||
|
{
|
||||||
|
ProviderName = Name,
|
||||||
|
Type = type,
|
||||||
|
Url = url
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetUrl(IHasImages item, string listingFilename, string remoteFilename)
|
||||||
|
{
|
||||||
|
var list = GetAvailableImages(listingFilename);
|
||||||
|
|
||||||
|
var match = FindMatch(item, list);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(match))
|
||||||
|
{
|
||||||
|
return GetUrl(match, remoteFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string FindMatch(IHasImages item, IEnumerable<string> images)
|
||||||
|
{
|
||||||
|
var name = GetComparableName(item.Name);
|
||||||
|
|
||||||
|
return images.FirstOrDefault(i => string.Equals(name, GetComparableName(i), StringComparison.OrdinalIgnoreCase));
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetComparableName(string name)
|
||||||
|
{
|
||||||
|
return name.Replace(" ", string.Empty).Replace(".", string.Empty).Replace("&", string.Empty).Replace("!", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetUrl(string image, string filename)
|
||||||
|
{
|
||||||
|
return string.Format("https://raw.github.com/MediaBrowser/MediaBrowser.Resources/master/images/studios/{0}/{1}.jpg", image, filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<string> GetAvailableImages(string filename)
|
||||||
|
{
|
||||||
|
var path = GetType().Namespace + "." + filename;
|
||||||
|
|
||||||
|
using (var stream = GetType().Assembly.GetManifestResourceStream(path))
|
||||||
|
{
|
||||||
|
using (var reader = new StreamReader(stream))
|
||||||
|
{
|
||||||
|
var lines = new List<string>();
|
||||||
|
|
||||||
|
while (!reader.EndOfStream)
|
||||||
|
{
|
||||||
|
var text = reader.ReadLine();
|
||||||
|
|
||||||
|
lines.Add(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Priority
|
||||||
|
{
|
||||||
|
get { return 0; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
0
MediaBrowser.Providers/Studios/backdrops.txt
Normal file
0
MediaBrowser.Providers/Studios/backdrops.txt
Normal file
|
@ -115,6 +115,7 @@ Digital Artists
|
||||||
Digital Rights Group
|
Digital Rights Group
|
||||||
Digital Studios
|
Digital Studios
|
||||||
Discovery Channel
|
Discovery Channel
|
||||||
|
Discovery
|
||||||
Distribber
|
Distribber
|
||||||
Diva
|
Diva
|
||||||
DIY Network
|
DIY Network
|
||||||
|
@ -226,6 +227,7 @@ Indie Crush
|
||||||
IndieFlix
|
IndieFlix
|
||||||
itsallinyourhands.tv
|
itsallinyourhands.tv
|
||||||
ITV
|
ITV
|
||||||
|
ITV1
|
||||||
Janson Media
|
Janson Media
|
||||||
Jim Henson Family TV
|
Jim Henson Family TV
|
||||||
K2
|
K2
|
||||||
|
@ -297,6 +299,7 @@ NBC Sports
|
||||||
NBC Universal
|
NBC Universal
|
||||||
NBCU TV
|
NBCU TV
|
||||||
NCircle
|
NCircle
|
||||||
|
Netflix
|
||||||
New Renaissance
|
New Renaissance
|
||||||
NHL
|
NHL
|
||||||
Nickelodeon
|
Nickelodeon
|
||||||
|
@ -386,6 +389,7 @@ SpaceRip
|
||||||
SPEED
|
SPEED
|
||||||
Speed Racer Enterprises
|
Speed Racer Enterprises
|
||||||
Spike
|
Spike
|
||||||
|
Spike TV
|
||||||
Stand Up To Cancer
|
Stand Up To Cancer
|
||||||
Starz
|
Starz
|
||||||
Strand Releasing
|
Strand Releasing
|
||||||
|
@ -453,6 +457,7 @@ Universal Television
|
||||||
Univision
|
Univision
|
||||||
unwrapped.tv
|
unwrapped.tv
|
||||||
USA
|
USA
|
||||||
|
USA Network
|
||||||
uStudio
|
uStudio
|
||||||
Vanguard Cinema
|
Vanguard Cinema
|
||||||
Venevision
|
Venevision
|
Loading…
Reference in New Issue
Block a user