Remove unsed code

This commit is contained in:
cxfksword 2022-10-25 18:07:28 +08:00
parent 7d14da34ae
commit 2381509376
13 changed files with 53 additions and 31 deletions

View File

@ -112,14 +112,13 @@ namespace Jellyfin.Plugin.MetaShark.Api
var key = cookieArr[0].Trim();
var value = cookieArr[1].Trim();
Console.WriteLine($"key={key} value={value}");
try
{
cookieContainer.Add(new Cookie(key, value, "/", ".douban.com"));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
this._logger.LogError(ex, ex.Message);
}
}
}
@ -495,7 +494,6 @@ namespace Jellyfin.Plugin.MetaShark.Api
protected void LimitRequestFrequently()
{
var startTime = DateTime.Now;
lock (_lock)
{
var ts = DateTime.Now - lastRequestTime;
@ -506,9 +504,6 @@ namespace Jellyfin.Plugin.MetaShark.Api
}
lastRequestTime = DateTime.Now;
}
var endTime = DateTime.Now;
var tt = (endTime - startTime).TotalMilliseconds;
Console.WriteLine(tt);
}
private string? GetText(IElement el, string css)

View File

@ -27,6 +27,7 @@ namespace Jellyfin.Plugin.MetaShark.Api
private readonly ILogger<TmdbApi> _logger;
private readonly IMemoryCache _memoryCache;
private readonly TMDbClient _tmDbClient;
private readonly PluginConfiguration _config;
/// <summary>
/// Initializes a new instance of the <see cref="TmdbApi"/> class.
@ -35,8 +36,8 @@ namespace Jellyfin.Plugin.MetaShark.Api
{
_logger = loggerFactory.CreateLogger<TmdbApi>();
_memoryCache = new MemoryCache(new MemoryCacheOptions());
var config = Plugin.Instance?.Configuration ?? new PluginConfiguration();
var apiKey = string.IsNullOrEmpty(config.TmdbApiKey) ? DEFAULT_API_KEY : config.TmdbApiKey;
_config = Plugin.Instance?.Configuration ?? new PluginConfiguration();
var apiKey = string.IsNullOrEmpty(_config.TmdbApiKey) ? DEFAULT_API_KEY : _config.TmdbApiKey;
_tmDbClient = new TMDbClient(apiKey);
_tmDbClient.RequestTimeout = TimeSpan.FromSeconds(10);
// Not really interested in NotFoundException
@ -53,6 +54,11 @@ namespace Jellyfin.Plugin.MetaShark.Api
/// <returns>The TMDb movie or null if not found.</returns>
public async Task<Movie?> GetMovieAsync(int tmdbId, string language, string imageLanguages, CancellationToken cancellationToken)
{
if (!this._config.EnableTmdb)
{
return null;
}
var key = $"movie-{tmdbId.ToString(CultureInfo.InvariantCulture)}-{language}";
if (_memoryCache.TryGetValue(key, out Movie movie))
{
@ -119,6 +125,11 @@ namespace Jellyfin.Plugin.MetaShark.Api
/// <returns>The TMDb tv show information or null if not found.</returns>
public async Task<TvShow?> GetSeriesAsync(int tmdbId, string language, string imageLanguages, CancellationToken cancellationToken)
{
if (!this._config.EnableTmdb)
{
return null;
}
var key = $"series-{tmdbId.ToString(CultureInfo.InvariantCulture)}-{language}";
if (_memoryCache.TryGetValue(key, out TvShow series))
{
@ -153,10 +164,14 @@ namespace Jellyfin.Plugin.MetaShark.Api
/// <returns>The TMDb tv season information or null if not found.</returns>
public async Task<TvSeason?> GetSeasonAsync(int tvShowId, int seasonNumber, string language, string imageLanguages, CancellationToken cancellationToken)
{
if (!this._config.EnableTmdb)
{
return null;
}
var key = $"season-{tvShowId.ToString(CultureInfo.InvariantCulture)}-s{seasonNumber.ToString(CultureInfo.InvariantCulture)}-{language}";
if (_memoryCache.TryGetValue(key, out TvSeason season))
{
Console.WriteLine("#season from cache.");
return season;
}
@ -223,6 +238,11 @@ namespace Jellyfin.Plugin.MetaShark.Api
/// <returns>The TMDb person information or null if not found.</returns>
public async Task<Person?> GetPersonAsync(int personTmdbId, CancellationToken cancellationToken)
{
if (!this._config.EnableTmdb)
{
return null;
}
var key = $"person-{personTmdbId.ToString(CultureInfo.InvariantCulture)}";
if (_memoryCache.TryGetValue(key, out Person person))
{
@ -289,6 +309,11 @@ namespace Jellyfin.Plugin.MetaShark.Api
/// <returns>The TMDb tv show information.</returns>
public async Task<IReadOnlyList<SearchTv>> SearchSeriesAsync(string name, string language, CancellationToken cancellationToken)
{
if (!this._config.EnableTmdb)
{
return new List<SearchTv>();
}
var key = $"searchseries-{name}-{language}";
if (_memoryCache.TryGetValue(key, out SearchContainer<SearchTv> series))
{
@ -366,6 +391,11 @@ namespace Jellyfin.Plugin.MetaShark.Api
/// <returns>The TMDb movie information.</returns>
public async Task<IReadOnlyList<SearchMovie>> SearchMovieAsync(string name, int year, string language, CancellationToken cancellationToken)
{
if (!this._config.EnableTmdb)
{
return new List<SearchMovie>();
}
var key = $"moviesearch-{name}-{year.ToString(CultureInfo.InvariantCulture)}-{language}";
if (_memoryCache.TryGetValue(key, out SearchContainer<SearchMovie> movies))
{

View File

@ -53,7 +53,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers
/// <inheritdoc />
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
Console.WriteLine(item.ProviderIds.ToJson());
this.Log($"GetEpisodeImages for item: {item.Name} number: {item.IndexNumber}");
var episode = (MediaBrowser.Controller.Entities.TV.Episode)item;
@ -81,7 +80,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers
var seasonResult = await this._tmdbApi
.GetSeasonAsync(seriesTmdbId, seasonNumber.Value, language, language, cancellationToken)
.ConfigureAwait(false);
Console.WriteLine($"seasonResult.Episodes.Count={seasonResult?.Episodes.Count}");
if (seasonResult == null || seasonResult.Episodes.Count < episodeNumber.Value)
{
this.Log($"Not valid season data for seasonNumber: {seasonNumber} episodeNumber: {episodeNumber}");
@ -90,7 +88,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers
var result = new List<RemoteImageInfo>();
var episodeResult = seasonResult.Episodes[episodeNumber.Value - 1];
Console.WriteLine(episodeResult.ToJson());
if (!string.IsNullOrEmpty(episodeResult.StillPath))
{
result.Add(new RemoteImageInfo

View File

@ -53,8 +53,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers
public async Task<MetadataResult<Episode>> GetMetadata(EpisodeInfo info, CancellationToken cancellationToken)
{
this.Log($"GetEpisodeMetadata of [name]: {info.Name} number: {info.IndexNumber}");
Console.WriteLine(info.ToJson());
Console.WriteLine(info.SeriesProviderIds.ToJson());
var result = new MetadataResult<Episode>();
// 剧集信息只有tmdb有
@ -62,17 +60,25 @@ namespace Jellyfin.Plugin.MetaShark.Providers
var seasonNumber = info.ParentIndexNumber; // 没有season级目录时会为null
var episodeNumber = info.IndexNumber;
var indexNumberEnd = info.IndexNumberEnd;
Console.WriteLine($"seasonNumber:{seasonNumber} episodeNumber:{episodeNumber} indexNumberEnd:{indexNumberEnd}");
if (episodeNumber is null or 0)
{
// 从文件名获取剧集的indexNumber
var fileName = Path.GetFileName(info.Path) ?? string.Empty;
episodeNumber = this.GuessEpisodeNumber(episodeNumber, fileName);
if (episodeNumber.HasValue && episodeNumber.Value > 0)
{
result.HasMetadata = true;
result.Item = new Episode
{
IndexNumber = episodeNumber
};
}
this.Log("GuessEpisodeNumber: fileName: {0} episodeNumber: {1}", fileName, episodeNumber);
}
if (episodeNumber is null or 0 || seasonNumber is null or 0 || string.IsNullOrEmpty(seriesTmdbId))
{
this.Log("Lack meta message. episodeNumber: {0} seasonNumber: {1} seriesTmdbId:{2}", episodeNumber, seasonNumber, seriesTmdbId);
return result;
}

View File

@ -51,8 +51,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers
/// <inheritdoc />
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
Console.WriteLine(item.ToJson());
Console.WriteLine(item.ProviderIds.ToJson());
var sid = item.GetProviderId(DoubanProviderId);
var metaSource = item.GetProviderId(Plugin.ProviderId);
this.Log($"GetImages for item: {item.Name} [metaSource]: {metaSource}");

View File

@ -88,7 +88,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers
this.Log($"GetMovieMetadata of [name]: {info.Name}");
var result = new MetadataResult<Movie>();
Console.WriteLine(info.ToJson());
var sid = info.GetProviderId(DoubanProviderId);
var tmdbId = info.GetProviderId(MetadataProvider.Tmdb);
var metaSource = info.GetProviderId(Plugin.ProviderId);
@ -133,7 +132,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers
var movieResult = await this._tmdbApi.FindByExternalIdAsync(subject.Imdb, FindExternalSource.Imdb, null, cancellationToken).ConfigureAwait(false);
if (movieResult?.MovieResults != null && movieResult.MovieResults.Count > 0)
{
Console.WriteLine(movieResult.MovieResults.ToJson());
this.Log($"GetMovieMetadata of found tmdb [id]: \"{movieResult.MovieResults[0].Id}\"");
movie.SetProviderId(MetadataProvider.Tmdb, $"{movieResult.MovieResults[0].Id}");
}

View File

@ -49,7 +49,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
MetadataResult<Person> result = new MetadataResult<Person>();
var cid = info.GetProviderId(DoubanProviderId);
this.Log($"GetMetadata of [cid]: {cid}");
this.Log($"GetPersonMetadata of [cid]: {cid}");
if (!string.IsNullOrEmpty(cid))
{
@ -83,7 +83,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
}
var personTmdbId = info.GetProviderId(MetadataProvider.Tmdb);
this.Log($"GetMetadata of [personTmdbId]: {personTmdbId}");
this.Log($"GetPersonMetadata of [personTmdbId]: {personTmdbId}");
if (!string.IsNullOrEmpty(personTmdbId))
{
var person = await this._tmdbApi.GetPersonAsync(personTmdbId.ToInt(), cancellationToken).ConfigureAwait(false);

View File

@ -80,7 +80,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers
// get image form TMDB
var seriesTmdbId = Convert.ToInt32(series?.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture);
Console.WriteLine($"seriesTmdbId={seriesTmdbId} season?.IndexNumber={season?.IndexNumber}");
if (seriesTmdbId <= 0 || season?.IndexNumber == null)
{
return Enumerable.Empty<RemoteImageInfo>();
@ -92,7 +91,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers
.GetSeasonAsync(seriesTmdbId, season.IndexNumber.Value, language, language, cancellationToken)
.ConfigureAwait(false);
var posters = seasonResult?.Images?.Posters;
Console.WriteLine(posters?.ToJson());
if (posters == null)
{
return Enumerable.Empty<RemoteImageInfo>();

View File

@ -68,9 +68,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
info.SeriesProviderIds.TryGetValue(MetadataProvider.Tmdb.ToString(), out var seriesTmdbId);
info.SeriesProviderIds.TryGetValue(Plugin.ProviderId, out var metaSource);
info.SeriesProviderIds.TryGetValue(DoubanProviderId, out var sid);
Console.WriteLine(info.SeriesProviderIds.ToJson());
var seasonNumber = info.IndexNumber;
Console.WriteLine($"seriesTmdbId: {seriesTmdbId} seasonNumber: {seasonNumber}");
if (metaSource == MetaSource.Douban && !string.IsNullOrEmpty(sid))
{

View File

@ -51,8 +51,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers
/// <inheritdoc />
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
Console.WriteLine(item.ToJson());
Console.WriteLine(item.ProviderIds.ToJson());
var sid = item.GetProviderId(DoubanProviderId);
var metaSource = item.GetProviderId(Plugin.ProviderId);
this.Log($"GetImages for item: {item.Name} [metaSource]: {metaSource}");

View File

@ -57,7 +57,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers
}));
// 尝试从tmdb搜索
Console.WriteLine($"info.MetadataLanguage={info.MetadataLanguage}");
var tmdbList = await this._tmdbApi.SearchSeriesAsync(info.Name, info.MetadataLanguage, cancellationToken).ConfigureAwait(false);
result.AddRange(tmdbList.Take(this._config.MaxSearchResult).Select(x =>
{

View File

@ -4,8 +4,9 @@
[![metashark](https://img.shields.io/badge/jellyfin-10.8.x-lightgrey)](https://github.com/cxfksword/jellyfin-plugin-metashark/releases)
[![metashark](https://img.shields.io/github/license/cxfksword/jellyfin-plugin-metashark)](https://github.com/cxfksword/jellyfin-plugin-metashark/main/LICENSE)
jellyfin电影元数据插件影片信息只要从豆瓣获取并由TMDB补充缺失的季数据和剧集数据。
jellyfin电影元数据插件影片信息只要从豆瓣获取并由TheMovieDb补充缺失的季数据和剧集数据。
![preview](doc/logo.png)
## 安装插件
@ -17,7 +18,11 @@ jellyfin电影元数据插件影片信息只要从豆瓣获取并由TMDB
国外访问https://github.com/cxfksword/jellyfin-plugin-metashark/releases/download/manifest/manifest.json
## 如何使用
* 进入`控制台 -> 媒体库`,在元数据下载器中勾选**MetaShark**
* 假如网络原因访问TheMovieDb比较慢也可以到插件配置页关闭从TheMovieDb获取数据
## How to build
@ -29,7 +34,7 @@ jellyfin电影元数据插件影片信息只要从豆瓣获取并由TMDB
```sh
$ dotnet restore
$ dotnet publish -c Release Jellyfin.Plugin.MetaShark/Jellyfin.Plugin.MetaShark.csproj
$ dotnet publish Jellyfin.Plugin.MetaShark/Jellyfin.Plugin.MetaShark.csproj
```
@ -37,7 +42,7 @@ $ dotnet publish -c Release Jellyfin.Plugin.MetaShark/Jellyfin.Plugin.MetaShark.
1. Build the plugin
2. Create a folder, like `metashark` and copy `bin/Release/net6.0/*.dll` into it
2. Create a folder, like `metashark` and copy `bin/Debug/net6.0/*.dll` into it
3. Move folder `metashark` to jellyfin `data/plugin` folder

Binary file not shown.

Before

Width:  |  Height:  |  Size: 291 KiB

After

Width:  |  Height:  |  Size: 9.0 KiB