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\XmlSaverHelpers.cs" />
|
||||
<Compile Include="Studios\StudioImageProvider.cs" />
|
||||
<Compile Include="Studios\StudiosManualImageProvider.cs" />
|
||||
<Compile Include="TV\EpisodeImageFromMediaLocationProvider.cs" />
|
||||
<Compile Include="TV\EpisodeIndexNumberProvider.cs" />
|
||||
<Compile Include="TV\EpisodeProviderFromXml.cs" />
|
||||
|
@ -167,7 +168,10 @@
|
|||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Studios\images.txt" />
|
||||
<EmbeddedResource Include="Studios\backdrops.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Studios\posters.txt" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition=" '$(ConfigurationName)' != 'Release Mono' " />
|
||||
|
|
|
@ -4,10 +4,12 @@ using MediaBrowser.Controller.Library;
|
|||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Net;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -47,7 +49,7 @@ namespace MediaBrowser.Providers.Studios
|
|||
|
||||
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(item.PrimaryImagePath))
|
||||
if (!string.IsNullOrEmpty(item.PrimaryImagePath) && item.BackdropImagePaths.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -67,65 +69,70 @@ namespace MediaBrowser.Providers.Studios
|
|||
{
|
||||
get
|
||||
{
|
||||
return "1";
|
||||
return "3";
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (!string.IsNullOrEmpty(match))
|
||||
{
|
||||
var url = GetUrl(match);
|
||||
|
||||
await _providerManager.SaveImage(item, url, _resourcePool, ImageType.Primary, null, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
await DownloadImages(item, images.ToList(), cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
SetLastRefreshed(item, DateTime.UtcNow, providerInfo);
|
||||
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);
|
||||
|
||||
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))
|
||||
if (!item.LockedFields.Contains(MetadataFields.Images))
|
||||
{
|
||||
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 Studios
|
||||
Discovery Channel
|
||||
Discovery
|
||||
Distribber
|
||||
Diva
|
||||
DIY Network
|
||||
|
@ -226,6 +227,7 @@ Indie Crush
|
|||
IndieFlix
|
||||
itsallinyourhands.tv
|
||||
ITV
|
||||
ITV1
|
||||
Janson Media
|
||||
Jim Henson Family TV
|
||||
K2
|
||||
|
@ -297,6 +299,7 @@ NBC Sports
|
|||
NBC Universal
|
||||
NBCU TV
|
||||
NCircle
|
||||
Netflix
|
||||
New Renaissance
|
||||
NHL
|
||||
Nickelodeon
|
||||
|
@ -386,6 +389,7 @@ SpaceRip
|
|||
SPEED
|
||||
Speed Racer Enterprises
|
||||
Spike
|
||||
Spike TV
|
||||
Stand Up To Cancer
|
||||
Starz
|
||||
Strand Releasing
|
||||
|
@ -453,6 +457,7 @@ Universal Television
|
|||
Univision
|
||||
unwrapped.tv
|
||||
USA
|
||||
USA Network
|
||||
uStudio
|
||||
Vanguard Cinema
|
||||
Venevision
|
Loading…
Reference in New Issue
Block a user