Skip to content

Commit

Permalink
Report GetIdetInfo() error on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
ptr727 committed Apr 10, 2024
1 parent 0d0dfc3 commit ed324f3
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 150 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ FodyWeavers.xsd
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Local History for Visual Studio Code
.history/
Expand Down
94 changes: 0 additions & 94 deletions .vscode/settings.json

This file was deleted.

129 changes: 129 additions & 0 deletions PlexCleaner.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
"folders": [
{
"path": "."
}
],
"settings": {
"cSpell.words": [
"adpcm",
"aencode",
"aencoder",
"analyzeduration",
"archlinux",
"AVFMT",
"avformat",
"checkfornewtools",
"checkfortools",
"codexffmpeg",
"commandline",
"createschema",
"createsidecar",
"cuda",
"decomb",
"defaultsettings",
"deint",
"deinterlace",
"deinterlaced",
"deinterlacing",
"dvhe",
"EBML",
"Emby",
"extlang",
"facs",
"ffprobe",
"filesystems",
"flac",
"getbitrateinfo",
"getmediainfo",
"getsidecar",
"getsidecarinfo",
"gettagmap",
"gettoolinfo",
"getversioninfo",
"getxxxinfo",
"Gyan",
"hdmv",
"hwaccel",
"Idet",
"indeo",
"Jellyfin",
"kbits",
"Kodi",
"libebml",
"libhb",
"libmatroska",
"libsvtav",
"libx",
"logappend",
"logfile",
"loglevel",
"logwarning",
"Lsize",
"Matroska",
"MBAFF",
"Mbps",
"mediafiles",
"mediainfo",
"Memberwise",
"mkvmerge",
"mkvtoolnix",
"mmco",
"msmpeg",
"msrle",
"muxer",
"Muxing",
"Nerdbank",
"Newtonsoft",
"NONSTRICT",
"nostats",
"NVENC",
"partitioner",
"Plex",
"plexcleaner",
"preprocess",
"printmediainfo",
"printsidecar",
"privateuse",
"probesize",
"quicktype",
"rawvideo",
"reencode",
"reencoded",
"reencoding",
"removesubtitles",
"remux",
"remuxed",
"remuxing",
"schemafile",
"Serilog",
"settingsfile",
"SMPTE",
"subdir",
"subsampling",
"subtag",
"testnomodify",
"testsnippets",
"threadcount",
"tmpint",
"tmprmx",
"truehd",
"unref",
"updatesidecar",
"upgradesidecar",
"VOBSUB",
"Vorbis",
"watchlist",
"WEBVTT",
"wmapro",
"wmav",
"xerror",
"Xunit",
"YIFY"
],
"yaml.schemas": {
"https://json.schemastore.org/github-issue-config.json": "file:/.github/ISSUE_TEMPLATE/config.yml"
},
"dotnet.defaultSolution": "PlexCleaner.sln"
}
}
4 changes: 2 additions & 2 deletions PlexCleaner/FfMpegIdetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public bool IsInterlaced()
return InterlacedPercentage > Program.InterlacedThreshold;
}

public static bool GetIdetInfo(FileInfo mediaFile, out FfMpegIdetInfo idetInfo)
public static bool GetIdetInfo(FileInfo mediaFile, out FfMpegIdetInfo idetInfo, out string error)
{
return Tools.FfMpeg.GetIdetInfo(mediaFile.FullName, out idetInfo);
return Tools.FfMpeg.GetIdetInfo(mediaFile.FullName, out idetInfo, out error);
}
}
15 changes: 10 additions & 5 deletions PlexCleaner/FfMpegTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected override string GetSubFolder()
return "bin";
}

public bool VerifyMedia(string filename, out string error)
public bool VerifyMedia(string fileName, out string error)
{
// https://trac.ffmpeg.org/ticket/6375
// Too many packets buffered for output stream 0:1
Expand All @@ -171,7 +171,7 @@ public bool VerifyMedia(string filename, out string error)

// Build commandline
StringBuilder commandline = new();
CreateDefaultArgs(filename, commandline);
CreateDefaultArgs(fileName, commandline);

// Null muxer and exit immediately on error (-xerror)
commandline.Append("-hide_banner -nostats -loglevel error -xerror -f null -");
Expand Down Expand Up @@ -349,12 +349,17 @@ public bool RemoveMetadata(string inputName, string outputName)
return exitCode == 0;
}

public bool GetIdetInfo(string filename, out FfMpegIdetInfo idetInfo)
public bool GetIdetInfo(string fileName, out FfMpegIdetInfo idetInfo, out string error)
{
// Get idet output and parse
idetInfo = null;
return GetIdetInfoText(filename, out var text) &&
GetIdetInfoFromText(text, out idetInfo);
error = null;
if (!GetIdetInfoText(fileName, out var text) || !GetIdetInfoFromText(text, out idetInfo))
{
error = text;
return false;
}
return true;
}

private bool GetIdetInfoText(string inputName, out string text)
Expand Down
24 changes: 12 additions & 12 deletions PlexCleaner/FfProbeTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ protected override string GetToolNameLinux()
return "ffprobe";
}

public bool GetPacketInfo(string filename, out List<Packet> packets)
public bool GetPacketInfo(string fileName, out List<Packet> packetList)
{
// Init
packets = null;
packetList = null;

// Write JSON text output to compressed memory stream to save memory
// TODO: Do the packet calculation in ProcessEx.OutputHandler() instead of writing all output to stream then processing the stream
Expand All @@ -54,7 +54,7 @@ public bool GetPacketInfo(string filename, out List<Packet> packets)
{
commandline.Append($"-read_intervals %{Program.SnippetTimeSpan:mm\\:ss} ");
}
commandline.Append($"-show_packets -show_entries packet=codec_type,stream_index,pts_time,dts_time,duration_time,size -print_format json \"{filename}\"");
commandline.Append($"-show_packets -show_entries packet=codec_type,stream_index,pts_time,dts_time,duration_time,size -print_format json \"{fileName}\"");

// Get packet info
string path = GetToolPath();
Expand All @@ -77,29 +77,29 @@ public bool GetPacketInfo(string filename, out List<Packet> packets)
return false;
}

packets = packetInfo.Packets;
packetList = packetInfo.Packets;
return true;
}

public bool GetFfProbeInfo(string filename, out MediaInfo mediainfo)
public bool GetFfProbeInfo(string fileName, out MediaInfo mediaInfo)
{
mediainfo = null;
return GetFfProbeInfoJson(filename, out string json) &&
GetFfProbeInfoFromJson(json, out mediainfo);
mediaInfo = null;
return GetFfProbeInfoJson(fileName, out string json) &&
GetFfProbeInfoFromJson(json, out mediaInfo);
}

public bool GetFfProbeInfoJson(string filename, out string json)
public bool GetFfProbeInfoJson(string fileName, out string json)
{
// Get media info as JSON
string commandline = $"-loglevel quiet -show_streams -show_format -print_format json \"{filename}\"";
string commandline = $"-loglevel quiet -show_streams -show_format -print_format json \"{fileName}\"";
int exitCode = Command(commandline, out json, out string error);
return exitCode == 0 && error.Length == 0;
}

public bool GetFfProbeInfoText(string filename, out string text)
public bool GetFfProbeInfoText(string fileName, out string text)
{
// Get media info using default output
string commandline = $"-hide_banner \"{filename}\"";
string commandline = $"-hide_banner \"{fileName}\"";
int exitCode = Command(commandline, out _, out text);
return exitCode == 0;
}
Expand Down
8 changes: 4 additions & 4 deletions PlexCleaner/MediaInfoTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ protected override bool GetLatestVersionLinux(out MediaToolInfo mediaToolInfo)
return false;
}

public bool GetMediaInfo(string filename, out MediaInfo mediaInfo)
public bool GetMediaInfo(string fileName, out MediaInfo mediaInfo)
{
mediaInfo = null;
return GetMediaInfoXml(filename, out var xml) &&
return GetMediaInfoXml(fileName, out var xml) &&
GetMediaInfoFromXml(xml, out mediaInfo);
}

public bool GetMediaInfoXml(string filename, out string xml)
public bool GetMediaInfoXml(string fileName, out string xml)
{
// Get media info as XML
var commandline = $"--Output=XML \"{filename}\"";
var commandline = $"--Output=XML \"{fileName}\"";
var exitCode = Command(commandline, out xml);

// TODO: No error is returned when the file does not exist
Expand Down
Loading

0 comments on commit ed324f3

Please sign in to comment.