mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-01-04 05:10:09 -06:00
FF-1042 - added options to subtitle extractor
This commit is contained in:
@@ -29,7 +29,7 @@ internal class SubtitleHelper
|
||||
/// <param name="codec">the subtitle codec</param>
|
||||
/// <returns>true if the subtitle is an image based subtitle</returns>
|
||||
internal static bool IsImageSubtitle(string codec)
|
||||
=> Regex.IsMatch(codec.Replace("_", ""), "dvbsub|pgs|xsub|vobsub", RegexOptions.IgnoreCase);
|
||||
=> Regex.IsMatch((codec ?? string.Empty).Replace("_", ""), "dvbsub|pgs|xsub|vobsub", RegexOptions.IgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// Determines the appropriate subtitle codec for conversion based on the container type and current subtitle codec.
|
||||
|
||||
@@ -521,7 +521,9 @@
|
||||
"SetWorkingFile": "Set as Working File",
|
||||
"SetWorkingFile-Help": "When this is checked, if a subtitle is extracted, the working file will be changed to this extracted subtitle. The original working file will NOT be deleted.",
|
||||
"ForcedOnly": "Forced Only",
|
||||
"ForcedOnly-Help": "If only forced subtitles should be extracted."
|
||||
"ForcedOnly-Help": "If only forced subtitles should be extracted.",
|
||||
"OnlyTextSubtitles": "Only Text Subtitles",
|
||||
"OnlyTextSubtitles-Help": "If only text subtitles should be extracted, all image based subtitles will be skipped."
|
||||
}
|
||||
},
|
||||
"VideoHasStream": {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Net;
|
||||
using FileFlows.VideoNodes.Helpers;
|
||||
|
||||
namespace FileFlows.VideoNodes;
|
||||
|
||||
@@ -40,7 +41,11 @@ public class SubtitleExtractor : EncodingNode
|
||||
/// </summary>
|
||||
[Boolean(4)]
|
||||
public bool ForcedOnly { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if only text subtitles should be extracted
|
||||
/// </summary>
|
||||
[Boolean(5)]
|
||||
public bool OnlyTextSubtitles { get; set; }
|
||||
|
||||
private Dictionary<string, object> _Variables;
|
||||
/// <summary>
|
||||
@@ -75,6 +80,9 @@ public class SubtitleExtractor : EncodingNode
|
||||
// ffmpeg -i input.mkv -map "0:m:language:eng" -map "-0:v" -map "-0:a" output.srt
|
||||
var subTrack = videoInfo.SubtitleStreams?.Where(x =>
|
||||
{
|
||||
if (OnlyTextSubtitles && SubtitleHelper.IsImageSubtitle(x.Codec))
|
||||
return false;
|
||||
|
||||
if (ForcedOnly && x.Forced == false)
|
||||
return false;
|
||||
if(string.IsNullOrEmpty(Language))
|
||||
@@ -103,7 +111,7 @@ public class SubtitleExtractor : EncodingNode
|
||||
OutputFile = args.MapPath(OutputFile);
|
||||
|
||||
string extension = "srt";
|
||||
if (subTrack.Codec?.ToLower()?.Contains("pgs") == true)
|
||||
if (SubtitleHelper.IsImageSubtitle(subTrack.Codec))
|
||||
extension = "sup";
|
||||
if (OutputFile.ToLower().EndsWith(".srt") || OutputFile.ToLower().EndsWith(".sup"))
|
||||
OutputFile = OutputFile[0..^4];
|
||||
|
||||
Reference in New Issue
Block a user