263 lines
5.9 KiB
C#
263 lines
5.9 KiB
C#
using System.ComponentModel;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace EmbyToolbox.Models;
|
|
|
|
public sealed class TrackExtractionQueueItem : INotifyPropertyChanged
|
|
{
|
|
private string _fullPath = string.Empty;
|
|
private string _fileName = string.Empty;
|
|
private int _rowNumber = 1;
|
|
private double _sizeMb;
|
|
private string _audioSummary = "\u2014";
|
|
private string _subtitleSummary = "\u2014";
|
|
private string _attachmentSummary = "\u2014";
|
|
private string _status = TrackExtractionStatuses.Queued;
|
|
private double _progressPercent;
|
|
private string _message = string.Empty;
|
|
private MediaAnalysisResult? _mediaAnalysis;
|
|
private int _totalTracksToExtract;
|
|
|
|
public TrackExtractionQueueItem(string fullPath)
|
|
{
|
|
RefreshPath(fullPath);
|
|
}
|
|
|
|
public string FullPath
|
|
{
|
|
get => _fullPath;
|
|
private set
|
|
{
|
|
if (_fullPath.Equals(value, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return;
|
|
}
|
|
|
|
_fullPath = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public string FileName
|
|
{
|
|
get => _fileName;
|
|
private set
|
|
{
|
|
if (_fileName == value)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_fileName = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public int RowNumber
|
|
{
|
|
get => _rowNumber;
|
|
internal set
|
|
{
|
|
if (_rowNumber == value)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_rowNumber = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public double SizeMb
|
|
{
|
|
get => _sizeMb;
|
|
private set
|
|
{
|
|
if (Math.Abs(_sizeMb - value) < 0.01)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_sizeMb = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public string AudioSummary
|
|
{
|
|
get => _audioSummary;
|
|
private set
|
|
{
|
|
if (_audioSummary == value)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_audioSummary = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public string SubtitleSummary
|
|
{
|
|
get => _subtitleSummary;
|
|
private set
|
|
{
|
|
if (_subtitleSummary == value)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_subtitleSummary = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public string AttachmentSummary
|
|
{
|
|
get => _attachmentSummary;
|
|
private set
|
|
{
|
|
if (_attachmentSummary == value)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_attachmentSummary = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public string Status
|
|
{
|
|
get => _status;
|
|
set
|
|
{
|
|
if (_status == value)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_status = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public double ProgressPercent
|
|
{
|
|
get => _progressPercent;
|
|
set
|
|
{
|
|
if (Math.Abs(_progressPercent - value) < 0.01)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_progressPercent = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public string Message
|
|
{
|
|
get => _message;
|
|
set
|
|
{
|
|
if (_message == value)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_message = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public MediaAnalysisResult? MediaAnalysis
|
|
{
|
|
get => _mediaAnalysis;
|
|
private set
|
|
{
|
|
if (ReferenceEquals(_mediaAnalysis, value))
|
|
{
|
|
return;
|
|
}
|
|
|
|
_mediaAnalysis = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public int TotalTracksToExtract
|
|
{
|
|
get => _totalTracksToExtract;
|
|
private set
|
|
{
|
|
if (_totalTracksToExtract == value)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_totalTracksToExtract = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
public void RefreshPath(string path)
|
|
{
|
|
FullPath = path;
|
|
FileName = Path.GetFileName(path);
|
|
try
|
|
{
|
|
var info = new FileInfo(path);
|
|
SizeMb = info.Exists ? Math.Round(info.Length / (1024.0 * 1024.0), 2) : 0;
|
|
}
|
|
catch
|
|
{
|
|
SizeMb = 0;
|
|
}
|
|
}
|
|
|
|
public void ResetForRequeue()
|
|
{
|
|
MediaAnalysis = null;
|
|
TotalTracksToExtract = 0;
|
|
const string dash = "\u2014";
|
|
AudioSummary = SubtitleSummary = AttachmentSummary = dash;
|
|
ProgressPercent = 0;
|
|
Message = string.Empty;
|
|
Status = TrackExtractionStatuses.Queued;
|
|
}
|
|
|
|
public void ApplyAnalysisOk(MediaAnalysisResult media)
|
|
{
|
|
MediaAnalysis = media;
|
|
var attachments = media.AllStreams.Count(x => x.Kind == MediaStreamKind.Attachment);
|
|
AudioSummary = media.AudioStreams.Count.ToString(CultureInfo.InvariantCulture);
|
|
SubtitleSummary = media.SubtitleStreams.Count.ToString(CultureInfo.InvariantCulture);
|
|
AttachmentSummary = attachments.ToString(CultureInfo.InvariantCulture);
|
|
TotalTracksToExtract = media.AudioStreams.Count + media.SubtitleStreams.Count + attachments;
|
|
Status = TrackExtractionStatuses.Ready;
|
|
ProgressPercent = 0;
|
|
Message = string.Empty;
|
|
}
|
|
|
|
public void ApplyAnalysisError(string reason)
|
|
{
|
|
MediaAnalysis = null;
|
|
TotalTracksToExtract = 0;
|
|
const string dash = "\u2014";
|
|
AudioSummary = SubtitleSummary = AttachmentSummary = dash;
|
|
Status = TrackExtractionStatuses.Error;
|
|
ProgressPercent = 0;
|
|
Message = reason.Trim();
|
|
}
|
|
|
|
private void OnPropertyChanged([CallerMemberName] string? propertyName = null) =>
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|