Skip to content

Commit

Permalink
修复只显示三个演员
Browse files Browse the repository at this point in the history
  • Loading branch information
AlifeLine committed Aug 19, 2021
1 parent 62fdb83 commit b3fc32a
Show file tree
Hide file tree
Showing 15 changed files with 231 additions and 19 deletions.
Binary file modified .vs/Emby.Plugins.Douban/v16/.suo
Binary file not shown.
24 changes: 13 additions & 11 deletions Providers/BaseProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Logging;
using System.Text.RegularExpressions;

namespace Emby.Plugins.Douban
{
Expand Down Expand Up @@ -100,16 +101,16 @@ public Task<HttpResponseMessage> GetImageResponse(string url,
protected async Task<MetadataResult<T>> GetMetadata<T>(string sid, CancellationToken cancellationToken)
where T : BaseItem, new()
{
_logger.Info("GetMetadata T");
var result = new MetadataResult<T>();

MediaType type = typeof(T) == typeof(Movie) ? MediaType.movie : MediaType.tv;
var subject = await _doubanClient.GetSubject(sid, type, cancellationToken);

var subjectCredits=await _doubanClient.GetSubjectCredits(sid, type, cancellationToken);
result.Item = TransMediaInfo<T>(subject);
result.Item.SetProviderId(ProviderID, sid);
TransPersonInfo(subject.Directors, PersonType.Director).ForEach(result.AddPerson);
TransPersonInfo(subject.Actors, PersonType.Actor).ForEach(result.AddPerson);

TransPersonInfo(subjectCredits.credits.ElementAt(0).celebrities, PersonType.Director).ForEach(result.AddPerson);
TransPersonInfo(subjectCredits.credits.ElementAt(1).celebrities, PersonType.Actor).ForEach(result.AddPerson);
result.QueriedById = true;
result.HasMetadata = true;

Expand Down Expand Up @@ -150,20 +151,21 @@ protected async Task<MetadataResult<T>> GetMetadata<T>(string sid, CancellationT
}

private static List<PersonInfo> TransPersonInfo(
List<Crew> crewList, PersonType personType)
List<CelebritiesItem> CelebritiesList, PersonType personType)
{
var result = new List<PersonInfo>();
foreach (var crew in crewList)
foreach (var Celebrities in CelebritiesList)
{
var role = Regex.Replace(Celebrities.character, @"(.*\()(.*)(\).*)", "$2");
var personInfo = new PersonInfo
{
Name = crew.Name,
Type = personType,
ImageUrl = crew.Avatar?.Large ?? "",
Role = crew.Roles.Count > 0 ? crew.Roles[0] : ""
Name = Celebrities.name,
Type = personType,
ImageUrl = Celebrities.avatar.large ?? "",
Role = role?? Celebrities.character
};

personInfo.SetProviderId(ProviderID, crew.Id);
personInfo.SetProviderId(ProviderID, Celebrities.id);
result.Add(personInfo);
}
return result;
Expand Down
23 changes: 22 additions & 1 deletion Providers/FrodoAndroidClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,30 @@ public FrodoAndroidClient(IJsonSerializer jsonSerializer,
_cache.Add(path, subject);

_logger.LogCallerInfo($"Finish doing GetSubject by Id: {doubanID}");
return subject;
return subject;
}
public async Task<Response.SubjectCredits> GetSubjectCredits(string doubanID, MediaType type, CancellationToken cancellationToken)
{
_logger.LogCallerInfo($"Start to SubjectCredits by Id: {doubanID}");

string path = $"/api/v2/{type:G}/{doubanID}/credits";
// Try to use cache firstly.
if (_cache.TryGet<Response.SubjectCredits>(path, out Response.SubjectCredits SubjectCredits))
{
_logger.LogCallerInfo($"Get subject {doubanID} from cache");
return SubjectCredits;
}

Dictionary<string, string> queryParams = new Dictionary<string, string>();
var contentStream = await GetResponse(path, queryParams, cancellationToken);
//_logger.LogCallerInfo($"SubjectCredits: {contentStream}");
SubjectCredits = _jsonSerializer.DeserializeFromString<Response.SubjectCredits>(contentStream);
// Add it into cache
_cache.Add(path, SubjectCredits);

_logger.LogCallerInfo($"Finish doing SubjectCredits by Id: {doubanID}");
return SubjectCredits;
}
/// <summary>
/// Search in Douban by a search query.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions Providers/IDoubanClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface IDoubanClient
/// <returns>The subject of one item.</returns>
public Task<Response.Subject> GetSubject(string doubanID, MediaType type,
CancellationToken cancellationToken);
public Task<Response.SubjectCredits> GetSubjectCredits(string doubanID, MediaType type, CancellationToken cancellationToken);

/// <summary>
/// Search in Douban by a search query.
Expand Down
2 changes: 0 additions & 2 deletions Providers/MovieProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Logging;
using Emby.Plugins.JavScraper.Services;
using System;

namespace Emby.Plugins.Douban.Providers
Expand All @@ -20,7 +19,6 @@ public class MovieProvider : BaseProvider, IHasOrder,
public string Name => "Douban Emby Movie Provider";
public int Order => 3;
private readonly IHttpClient _httpClient;
private readonly ImageProxyService imageProxyService;
public MovieProvider(IHttpClient http, IJsonSerializer jsonSerializer,
ILogger logger) : base(jsonSerializer, logger)
{
Expand Down
3 changes: 2 additions & 1 deletion Providers/Response/Subject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ public class Trailer
public string Runtime { get; set; }
public string Cover_Url { get; set; }
}
}

}
180 changes: 180 additions & 0 deletions Providers/Response/SubjectCredits.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
using System.Collections.Generic;

namespace Emby.Plugins.Douban.Response
{
public class User
{
/// <summary>
///
/// </summary>
public string loc { get; set; }
/// <summary>
///
/// </summary>
public string kind { get; set; }
/// <summary>
///
/// </summary>
public string followed { get; set; }
/// <summary>
/// 丹尼斯·维伦纽瓦
/// </summary>
public string name { get; set; }
/// <summary>
///
/// </summary>
public string url { get; set; }
/// <summary>
///
/// </summary>
public int verify_type { get; set; }
/// <summary>
/// 导演 丹尼斯·维伦纽瓦 Denis Villeneuve
/// </summary>
public string @abstract { get; set; }
/// <summary>
///
/// </summary>
public string reg_time { get; set; }
/// <summary>
///
/// </summary>
public string avatar { get; set; }
/// <summary>
///
/// </summary>
public string uri { get; set; }
/// <summary>
///
/// </summary>
public List<string> medal_groups { get; set; }
/// <summary>
///
/// </summary>
public string remark { get; set; }
/// <summary>
///
/// </summary>
public string in_blacklist { get; set; }
/// <summary>
///
/// </summary>
public int followers_count { get; set; }
/// <summary>
///
/// </summary>
public string id { get; set; }
/// <summary>
///
/// </summary>
public string is_banned { get; set; }
/// <summary>
///
/// </summary>
public string type { get; set; }
/// <summary>
///
/// </summary>
public string avatar_side_icon { get; set; }
/// <summary>
///
/// </summary>
public string uid { get; set; }
}

public class Avatar
{
/// <summary>
///
/// </summary>
public string large { get; set; }
/// <summary>
///
/// </summary>
public string normal { get; set; }
}

public class CelebritiesItem
{
/// <summary>
///
/// </summary>
public User user { get; set; }
/// <summary>
///
/// </summary>
public List<string> roles { get; set; }
/// <summary>
///
/// </summary>
public string latin_name { get; set; }
/// <summary>
///
/// </summary>
public string author { get; set; }
/// <summary>
///
/// </summary>
public string url { get; set; }
/// <summary>
/// 丹尼斯·维伦纽瓦生于加拿大魁北克,具有法国血统。曾凭借2000年的《迷情漩涡》、2009年的《理工学院》...
/// </summary>
public string @abstract { get; set; }
/// <summary>
/// 丹尼斯·维伦纽瓦(同名)加拿大,魁北克省,三河城影视演员
/// </summary>
public string title { get; set; }
/// <summary>
/// 导演 Director
/// </summary>
public string character { get; set; }
/// <summary>
///
/// </summary>
public string uri { get; set; }
/// <summary>
///
/// </summary>
public string cover_url { get; set; }
/// <summary>
///
/// </summary>
public Avatar avatar { get; set; }
/// <summary>
///
/// </summary>
public string sharing_url { get; set; }
/// <summary>
///
/// </summary>
public string type { get; set; }
/// <summary>
///
/// </summary>
public string id { get; set; }
/// <summary>
/// 丹尼斯·维伦纽瓦
/// </summary>
public string name { get; set; }
}

public class CreditsItem
{
/// <summary>
///
/// </summary>
public List<CelebritiesItem> celebrities { get; set; }
/// <summary>
/// 导演
/// </summary>
public string title { get; set; }
}

public class SubjectCredits
{
/// <summary>
///
/// </summary>
public List<CreditsItem> credits { get; set; }
}
}
Binary file modified bin/Debug/netstandard2.0/Emby.Plugins.Douban.dll
Binary file not shown.
Binary file modified bin/Debug/netstandard2.0/Emby.Plugins.Douban.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4a7113c2ae33fd8c874cbbee505085a16ea5f18e
95888f3773cd3d94c2546ed0e1b51bfd187b9d4b
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ D:\source\repos\Emby.Plugins.Douban\obj\Debug\netstandard2.0\Emby.Plugins.Douban
D:\source\repos\Emby.Plugins.Douban\bin\Debug\netstandard2.0\Emby.Plugins.Douban.deps.json
D:\source\repos\Emby.Plugins.Douban\bin\Debug\netstandard2.0\Emby.Plugins.Douban.dll
D:\source\repos\Emby.Plugins.Douban\bin\Debug\netstandard2.0\Emby.Plugins.Douban.pdb
D:\source\repos\Emby.Plugins.Douban\obj\Debug\netstandard2.0\Emby.Plugins.Douban.csprojAssemblyReference.cache
Binary file not shown.
Binary file modified obj/Debug/netstandard2.0/Emby.Plugins.Douban.dll
Binary file not shown.
Binary file modified obj/Debug/netstandard2.0/Emby.Plugins.Douban.pdb
Binary file not shown.
14 changes: 12 additions & 2 deletions server/ImageProxyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ public class ImageProxyService
private HttpClientEx client;
private static FileExtensionContentTypeProvider fileExtensionContentTypeProvider = new FileExtensionContentTypeProvider();

public ImageProxyService(IJsonSerializer jsonSerializer, ILogger logger, IFileSystem fileSystem, IApplicationPaths appPaths)
public ImageProxyService(IServerApplicationHost serverApplicationHost, IJsonSerializer jsonSerializer, ILogger logger, IFileSystem fileSystem, IApplicationPaths appPaths)
{
client = new HttpClientEx();
this.serverApplicationHost = serverApplicationHost;
this.jsonSerializer = jsonSerializer;
this.logger = logger;
this.fileSystem = fileSystem;
this.appPaths = appPaths;
}
private readonly IServerApplicationHost serverApplicationHost;
private readonly IJsonSerializer jsonSerializer;
private readonly ILogger logger;
private readonly IFileSystem fileSystem;
Expand Down Expand Up @@ -101,7 +103,15 @@ public async Task<HttpResponseInfo> GetImageResponse(string url, ImageType type,
/// <param name="url"></param>
/// <param name="type"></param>
/// <returns></returns>

public string GetLocalUrl(string url, ImageType type = ImageType.Backdrop)
{
logger?.Info("start get local url");
if (string.IsNullOrEmpty(url))
return url;
if (url.IndexOf("Plugins/alifeline_douban/Image", StringComparison.OrdinalIgnoreCase) >= 0)
return url;
return $"/emby/Plugins/alifeline_douban/Image?url={HttpUtility.UrlEncode(url)}&type={type}";
}
private async Task<HttpResponseInfo> Parse(HttpResponseMessage resp)
{
var r = new HttpResponseInfo()
Expand Down

0 comments on commit b3fc32a

Please sign in to comment.