Repository navigation
Expand file tree
/
Copy pathMediaInfoHelper.cs
More file actions
118 lines (102 loc) · 4.15 KB
/
Copy pathMediaInfoHelper.cs
File metadata and controls
118 lines (102 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Entities;
using System.Collections.Generic;
using System.Linq;
using System;
namespace SmartTags;
public static class MediaInfoHelper
{
/// <summary>
/// 分析媒体项目的流信息,返回需要添加的标签列表
/// </summary>
public static List<string> GetMediaInfoTags(BaseItem item, SmartTagsConfig config)
{
var tags = new List<string>();
// 获取所有流信息
var streams = item.GetMediaStreams();
var videoStream = streams.FirstOrDefault(s => s.Type == MediaStreamType.Video);
var audioStreams = streams.Where(s => s.Type == MediaStreamType.Audio).ToList();
// 1. 分辨率标签
if (config.EnableResolutionTags && videoStream != null && videoStream.Width.HasValue)
{
int width = videoStream.Width.Value;
if (width >= 3800) tags.Add("4K");
else if (width >= 1900) tags.Add("1080p");
else if (width >= 1200) tags.Add("720p");
}
// 2. HDR / 杜比视界标签
if (config.EnableHdrTags && videoStream != null)
{
bool isDv = false;
// 修正点:VideoRange 是 string 类型,直接获取字符串。
// 移除不存在的 VideoRangeType。
string range = videoStream.VideoRange ?? "";
string title = videoStream.DisplayTitle ?? "";
// 检查 Dolby Vision
// 通过字符串匹配 "Dolby" 或 "DOVI"
if (range.IndexOf("Dolby", StringComparison.OrdinalIgnoreCase) >= 0 ||
range.IndexOf("DOVI", StringComparison.OrdinalIgnoreCase) >= 0 ||
title.IndexOf("Dolby Vision", StringComparison.OrdinalIgnoreCase) >= 0)
{
tags.Add("Dolby Vision");
isDv = true;
}
// 检查 HDR
// 修正点:不使用 VideoRange.HDR 枚举,而是检查字符串是否包含 HDR 关键词
// 常见的 HDR 字符串值可能是 "HDR", "HDR10", "SMPTE ST 2086", "PQ", "HLG" 等
if (!isDv)
{
if (range.IndexOf("HDR", StringComparison.OrdinalIgnoreCase) >= 0 ||
range.IndexOf("PQ", StringComparison.OrdinalIgnoreCase) >= 0 ||
range.IndexOf("HLG", StringComparison.OrdinalIgnoreCase) >= 0)
{
tags.Add("HDR");
}
}
}
// 3. 音频标签 (次世代音轨)
if (config.EnableAudioTags && audioStreams.Any())
{
foreach (var audio in audioStreams)
{
string profile = audio.Profile?.ToLower() ?? "";
string codec = audio.Codec?.ToLower() ?? "";
string title = audio.DisplayTitle?.ToLower() ?? "";
// Atmos (全景声)
if (title.Contains("atmos") || profile.Contains("atmos"))
{
if (!tags.Contains("Atmos")) tags.Add("Atmos");
}
// DTS:X
if (title.Contains("dts:x") || title.Contains("dts-x") || profile.Contains("dts-x"))
{
if (!tags.Contains("DTS:X")) tags.Add("DTS:X");
}
// TrueHD
if (codec == "truehd")
{
if (!tags.Contains("TrueHD")) tags.Add("TrueHD");
}
// DTS-HD Master Audio
if (profile.Contains("dts-hd ma") || title.Contains("dts-hd ma"))
{
if (!tags.Contains("DTS-HD MA")) tags.Add("DTS-HD MA");
}
}
}
return tags;
}
/// 获取所有 SmartTags 可能生成的媒体信息标签 (供 Cleanup 任务使用)
public static IEnumerable<string> GetAllKnownMediaInfoTags()
{
return new List<string>
{
// 分辨率
"4K", "1080p", "720p",
// 画质
"HDR", "Dolby Vision",
// 音频
"Atmos", "DTS:X", "TrueHD", "DTS-HD MA"
};
}
}