Skip to content

Commit

Permalink
feat: add episode count match config. #42
Browse files Browse the repository at this point in the history
  • Loading branch information
cxfksword committed Jul 2, 2024
1 parent e8e6a90 commit c0e8658
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 17 deletions.
15 changes: 15 additions & 0 deletions Jellyfin.Plugin.Danmu/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public class PluginConfiguration : BasePluginConfiguration
/// </summary>
public string AssSpeed { get; set; } = string.Empty;


/// <summary>
/// 检测弹幕数和视频剧集数需要一致才自动下载弹幕.
/// </summary>
public DanmuDownloadOption DownloadOption { get; set; } = new DanmuDownloadOption();

/// <summary>
/// 透明度.
/// </summary>
Expand Down Expand Up @@ -124,6 +130,15 @@ public ScraperConfigItem(string name, bool enable)

}

public class DanmuDownloadOption
{
/// <summary>
/// 检测弹幕数和视频剧集数需要一致才自动下载弹幕.
/// </summary>
public bool EnableEpisodeCountSame { get; set; } = true;

}

/// <summary>
/// 弹弹play配置
/// </summary>
Expand Down
21 changes: 21 additions & 0 deletions Jellyfin.Plugin.Danmu/Configuration/configPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ <h3>弹幕源配置</h3>
</div>
</fieldset>

<fieldset class="verticalSection verticalSection-extrabottompadding">
<legend>
<h3>弹幕匹配下载配置</h3>
</legend>

<div class="checkboxContainer checkboxContainer-withDescription">
<label class="emby-checkbox-label">
<input id="EnableEpisodeCountSame" name="EnableEpisodeCountSame" type="checkbox"
is="emby-checkbox" />
<span>弹幕总数需和电视剧总集数一致</span>
</label>
<div class="fieldDescription">勾选后,假如匹配了错误的电视剧,可以避免自动下载错误的弹幕。</div>
</div>
</fieldset>

<fieldset class="verticalSection verticalSection-extrabottompadding">
<legend>
<h3>弹弹play配置</h3>
Expand Down Expand Up @@ -120,6 +135,8 @@ <h3>生成ASS配置</h3>
document.querySelector('#AssLineCount').value = config.AssLineCount;
document.querySelector('#AssSpeed').value = config.AssSpeed;

document.querySelector('#EnableEpisodeCountSame').checked = config.DownloadOption.EnableEpisodeCountSame;

document.querySelector('#WithRelatedDanmu').checked = config.Dandan.WithRelatedDanmu;
document.querySelector('#ChConvert').value = config.Dandan.ChConvert;

Expand Down Expand Up @@ -165,6 +182,10 @@ <h3>生成ASS配置</h3>
});
config.Scrapers = scrapers;

var download = new Object();
download.EnableEpisodeCountSame = document.querySelector('#EnableEpisodeCountSame').checked;
config.DownloadOption = download;

var dandan = new Object();
dandan.WithRelatedDanmu = document.querySelector('#WithRelatedDanmu').checked;
dandan.ChConvert = document.querySelector('#ChConvert').value;
Expand Down
33 changes: 16 additions & 17 deletions Jellyfin.Plugin.Danmu/LibraryManagerEventsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -581,27 +581,26 @@ public async Task ProcessQueuedSeasonEvents(IReadOnlyCollection<LibraryEvent> ev
continue;
}

if (media.Episodes.Count == episodes.Count)
if (this.Config.DownloadOption.EnableEpisodeCountSame && media.Episodes.Count != episodes.Count)
{
var epId = media.Episodes[idx].Id;
var commentId = media.Episodes[idx].CommentId;
_logger.LogInformation("[{0}]成功匹配. {1}.{2} -> epId: {3} cid: {4}", scraper.Name, indexNumber, episode.Name, epId, commentId);

// 更新eposide元数据
var episodeProviderVal = episode.GetProviderId(scraper.ProviderId);
if (!string.IsNullOrEmpty(epId) && episodeProviderVal != epId)
{
episode.SetProviderId(scraper.ProviderId, epId);
queueUpdateMeta.Add(episode);
}

// 下载弹幕
await this.DownloadDanmu(scraper, episode, commentId).ConfigureAwait(false);
_logger.LogInformation("[{0}]刷新弹幕失败, 集数不一致。video: {1}.{2} 弹幕数:{3} 集数:{4}", scraper.Name, indexNumber, episode.Name, media.Episodes.Count, episodes.Count);
continue;
}
else

var epId = media.Episodes[idx].Id;
var commentId = media.Episodes[idx].CommentId;
_logger.LogInformation("[{0}]成功匹配. {1}.{2} -> epId: {3} cid: {4}", scraper.Name, indexNumber, episode.Name, epId, commentId);

// 更新eposide元数据
var episodeProviderVal = episode.GetProviderId(scraper.ProviderId);
if (!string.IsNullOrEmpty(epId) && episodeProviderVal != epId)
{
_logger.LogInformation("[{0}]刷新弹幕失败, 集数不一致。video: {1}.{2} 弹幕数:{3} 集数:{4}", scraper.Name, indexNumber, episode.Name, media.Episodes.Count, episodes.Count);
episode.SetProviderId(scraper.ProviderId, epId);
queueUpdateMeta.Add(episode);
}

// 下载弹幕
await this.DownloadDanmu(scraper, episode, commentId).ConfigureAwait(false);
}

break;
Expand Down

0 comments on commit c0e8658

Please sign in to comment.