Add - Added ScaleAndBorder to settings

Chg - Adjusted some log messages
This commit is contained in:
Elwador 2024-06-19 12:37:06 +02:00
parent f78df5b07f
commit d220a7d0db
6 changed files with 172 additions and 75 deletions

View File

@ -151,6 +151,7 @@ public class Crunchyroll{
CrunOptions.SelectedCalendarLanguage = "de"; CrunOptions.SelectedCalendarLanguage = "de";
CrunOptions.DlVideoOnce = true; CrunOptions.DlVideoOnce = true;
CrunOptions.StreamEndpoint = "web/firefox"; CrunOptions.StreamEndpoint = "web/firefox";
CrunOptions.SubsAddScaledBorder = ScaledBorderAndShadowSelection.ScaledBorderAndShadowYes;
CrunOptions.History = true; CrunOptions.History = true;
@ -1023,12 +1024,14 @@ public class Crunchyroll{
DownloadSpeed = 0, DownloadSpeed = 0,
Doing = "Decrypting" Doing = "Decrypting"
}; };
Queue.Refresh();
var assetIdRegexMatch = Regex.Match(chosenVideoSegments.segments[0].uri, @"/assets/(?:p/)?([^_,]+)"); var assetIdRegexMatch = Regex.Match(chosenVideoSegments.segments[0].uri, @"/assets/(?:p/)?([^_,]+)");
var assetId = assetIdRegexMatch.Success ? assetIdRegexMatch.Groups[1].Value : null; var assetId = assetIdRegexMatch.Success ? assetIdRegexMatch.Groups[1].Value : null;
var sessionId = Helpers.GenerateSessionId(); var sessionId = Helpers.GenerateSessionId();
Console.WriteLine("Decryption Needed, attempting to decrypt"); //TODO change back from error
Console.Error.WriteLine("Decryption Needed, attempting to decrypt");
if (!_widevine.canDecrypt){ if (!_widevine.canDecrypt){
dlFailed = true; dlFailed = true;
@ -1057,8 +1060,9 @@ public class Crunchyroll{
var decRequestResponse = await HttpClientReq.Instance.SendHttpRequest(decRequest); var decRequestResponse = await HttpClientReq.Instance.SendHttpRequest(decRequest);
if (!decRequestResponse.IsOk){ if (!decRequestResponse.IsOk){
Console.WriteLine("Request to DRM Authentication failed: "); Console.Error.WriteLine("Request to DRM Authentication failed: ");
MainWindow.Instance.ShowError("Request to DRM Authentication failed"); MainWindow.Instance.ShowError("Request to DRM Authentication failed");
dlFailed = true;
return new DownloadResponse{ return new DownloadResponse{
Data = files, Data = files,
Error = dlFailed, Error = dlFailed,
@ -1066,7 +1070,8 @@ public class Crunchyroll{
ErrorText = "DRM Authentication failed" ErrorText = "DRM Authentication failed"
}; };
} }
//TODO change back from error
Console.Error.WriteLine("Request to DRM Authentication successful");
DrmAuthData authData = Helpers.Deserialize<DrmAuthData>(decRequestResponse.ResponseContent, SettingsJsonSerializerSettings) ?? new DrmAuthData(); DrmAuthData authData = Helpers.Deserialize<DrmAuthData>(decRequestResponse.ResponseContent, SettingsJsonSerializerSettings) ?? new DrmAuthData();
@ -1076,7 +1081,8 @@ public class Crunchyroll{
var encryptionKeys = await _widevine.getKeys(chosenVideoSegments.pssh, "https://lic.drmtoday.com/license-proxy-widevine/cenc/", authDataDict); var encryptionKeys = await _widevine.getKeys(chosenVideoSegments.pssh, "https://lic.drmtoday.com/license-proxy-widevine/cenc/", authDataDict);
if (encryptionKeys.Count == 0){ if (encryptionKeys.Count == 0){
Console.WriteLine("Failed to get encryption keys"); Console.Error.WriteLine("Failed to get encryption keys");
dlFailed = true;
return new DownloadResponse{ return new DownloadResponse{
Data = files, Data = files,
Error = dlFailed, Error = dlFailed,
@ -1093,7 +1099,8 @@ public class Crunchyroll{
var commandAudio = commandBase + $" \"{tempTsFile}.audio.enc.m4s\" \"{tempTsFile}.audio.m4s\""; var commandAudio = commandBase + $" \"{tempTsFile}.audio.enc.m4s\" \"{tempTsFile}.audio.m4s\"";
if (videoDownloaded){ if (videoDownloaded){
Console.WriteLine("Started decrypting video"); //TODO change back from error
Console.Error.WriteLine("Started decrypting video");
var decryptVideo = await Helpers.ExecuteCommandAsync("mp4decrypt", CfgManager.PathMP4Decrypt, commandVideo); var decryptVideo = await Helpers.ExecuteCommandAsync("mp4decrypt", CfgManager.PathMP4Decrypt, commandVideo);
if (!decryptVideo.IsOk){ if (!decryptVideo.IsOk){
@ -1370,8 +1377,14 @@ public class Crunchyroll{
subsAssReqResponse.ResponseContent = '\ufeff' + subsAssReqResponse.ResponseContent; subsAssReqResponse.ResponseContent = '\ufeff' + subsAssReqResponse.ResponseContent;
var sBodySplit = subsAssReqResponse.ResponseContent.Split(new[]{ "\r\n" }, StringSplitOptions.None).ToList(); var sBodySplit = subsAssReqResponse.ResponseContent.Split(new[]{ "\r\n" }, StringSplitOptions.None).ToList();
// Insert 'ScaledBorderAndShadow: yes' after the second line // Insert 'ScaledBorderAndShadow: yes' after the second line
if (sBodySplit.Count > 2) if (sBodySplit.Count > 2){
if (options.SubsAddScaledBorder == ScaledBorderAndShadowSelection.ScaledBorderAndShadowYes){
sBodySplit.Insert(2, "ScaledBorderAndShadow: yes"); sBodySplit.Insert(2, "ScaledBorderAndShadow: yes");
}else if (options.SubsAddScaledBorder == ScaledBorderAndShadowSelection.ScaledBorderAndShadowNo){
sBodySplit.Insert(2, "ScaledBorderAndShadow: no");
}
}
// Rejoin the lines back into a single string // Rejoin the lines back into a single string
subsAssReqResponse.ResponseContent = string.Join("\r\n", sBodySplit); subsAssReqResponse.ResponseContent = string.Join("\r\n", sBodySplit);

View File

@ -165,6 +165,12 @@ public enum DownloadMediaType{
Subtitle, Subtitle,
} }
public enum ScaledBorderAndShadowSelection{
DontAdd,
ScaledBorderAndShadowYes,
ScaledBorderAndShadowNo,
}
public enum SonarrCoverType{ public enum SonarrCoverType{
Banner, Banner,
FanArt, FanArt,

View File

@ -59,21 +59,18 @@ public class Helpers{
return milliseconds + highResTimestamp; return milliseconds + highResTimestamp;
} }
public static void ConvertChapterFileForFFMPEG(string chapterFilePath) public static void ConvertChapterFileForFFMPEG(string chapterFilePath){
{
var chapterLines = File.ReadAllLines(chapterFilePath); var chapterLines = File.ReadAllLines(chapterFilePath);
var ffmpegChapterLines = new List<string> { ";FFMETADATA1" }; var ffmpegChapterLines = new List<string>{ ";FFMETADATA1" };
for (int i = 0; i < chapterLines.Length; i += 2) for (int i = 0; i < chapterLines.Length; i += 2){
{
var timeLine = chapterLines[i]; var timeLine = chapterLines[i];
var nameLine = chapterLines[i + 1]; var nameLine = chapterLines[i + 1];
var timeParts = timeLine.Split('='); var timeParts = timeLine.Split('=');
var nameParts = nameLine.Split('='); var nameParts = nameLine.Split('=');
if (timeParts.Length == 2 && nameParts.Length == 2) if (timeParts.Length == 2 && nameParts.Length == 2){
{
var startTime = TimeSpan.Parse(timeParts[1]).TotalMilliseconds; var startTime = TimeSpan.Parse(timeParts[1]).TotalMilliseconds;
var endTime = i + 2 < chapterLines.Length ? TimeSpan.Parse(chapterLines[i + 2].Split('=')[1]).TotalMilliseconds : startTime + 10000; var endTime = i + 2 < chapterLines.Length ? TimeSpan.Parse(chapterLines[i + 2].Split('=')[1]).TotalMilliseconds : startTime + 10000;
@ -89,6 +86,7 @@ public class Helpers{
} }
public static async Task<(bool IsOk, int ErrorCode)> ExecuteCommandAsync(string type, string bin, string command){ public static async Task<(bool IsOk, int ErrorCode)> ExecuteCommandAsync(string type, string bin, string command){
try{
using (var process = new Process()){ using (var process = new Process()){
process.StartInfo.FileName = bin; process.StartInfo.FileName = bin;
process.StartInfo.Arguments = command; process.StartInfo.Arguments = command;
@ -121,6 +119,10 @@ public class Helpers{
return (IsOk: isSuccess, ErrorCode: process.ExitCode); return (IsOk: isSuccess, ErrorCode: process.ExitCode);
} }
} catch (Exception ex){
Console.Error.WriteLine($"An error occurred: {ex.Message}");
return (IsOk: false, ErrorCode: -1);
}
} }
public static double CalculateCosineSimilarity(string text1, string text2){ public static double CalculateCosineSimilarity(string text1, string text2){

View File

@ -53,6 +53,9 @@ public class CrDownloadOptions{
[YamlMember(Alias = "mux_skip_subs", ApplyNamingConventions = false)] [YamlMember(Alias = "mux_skip_subs", ApplyNamingConventions = false)]
public bool SkipSubsMux{ get; set; } public bool SkipSubsMux{ get; set; }
[YamlMember(Alias = "subs_add_scaled_border", ApplyNamingConventions = false)]
public ScaledBorderAndShadowSelection SubsAddScaledBorder{ get; set; }
[YamlMember(Alias = "mux_mp4", ApplyNamingConventions = false)] [YamlMember(Alias = "mux_mp4", ApplyNamingConventions = false)]
public bool Mp4{ get; set; } public bool Mp4{ get; set; }

View File

@ -33,6 +33,17 @@ public partial class SettingsPageViewModel : ViewModelBase{
[ObservableProperty] [ObservableProperty]
private bool _downloadChapters = true; private bool _downloadChapters = true;
[ObservableProperty]
private bool _addScaledBorderAndShadow = false;
[ObservableProperty]
private ComboBoxItem _selectedScaledBorderAndShadow;
public ObservableCollection<ComboBoxItem> ScaledBorderAndShadow{ get; } = new(){
new ComboBoxItem(){ Content = "ScaledBorderAndShadow: yes" },
new ComboBoxItem(){ Content = "ScaledBorderAndShadow: no" },
};
[ObservableProperty] [ObservableProperty]
private bool _muxToMp4; private bool _muxToMp4;
@ -297,6 +308,9 @@ public partial class SettingsPageViewModel : ViewModelBase{
SonarrApiKey = props.ApiKey + ""; SonarrApiKey = props.ApiKey + "";
} }
AddScaledBorderAndShadow = options.SubsAddScaledBorder is ScaledBorderAndShadowSelection.ScaledBorderAndShadowNo or ScaledBorderAndShadowSelection.ScaledBorderAndShadowYes;
SelectedScaledBorderAndShadow = GetScaledBorderAndShadowFromOptions(options);
DownloadVideo = !options.Novids; DownloadVideo = !options.Novids;
DownloadAudio = !options.Noaudio; DownloadAudio = !options.Noaudio;
DownloadVideoForEveryDub = !options.DlVideoOnce; DownloadVideoForEveryDub = !options.DlVideoOnce;
@ -362,6 +376,7 @@ public partial class SettingsPageViewModel : ViewModelBase{
Crunchyroll.Instance.CrunOptions.Numbers = LeadingNumbers; Crunchyroll.Instance.CrunOptions.Numbers = LeadingNumbers;
Crunchyroll.Instance.CrunOptions.FileName = FileName; Crunchyroll.Instance.CrunOptions.FileName = FileName;
Crunchyroll.Instance.CrunOptions.SubsAddScaledBorder = GetScaledBorderAndShadowSelection();
List<string> softSubs = new List<string>(); List<string> softSubs = new List<string>();
foreach (var listBoxItem in SelectedSubLang){ foreach (var listBoxItem in SelectedSubLang){
@ -434,6 +449,35 @@ public partial class SettingsPageViewModel : ViewModelBase{
CfgManager.WriteSettingsToFile(); CfgManager.WriteSettingsToFile();
} }
private ScaledBorderAndShadowSelection GetScaledBorderAndShadowSelection(){
if (!AddScaledBorderAndShadow){
return ScaledBorderAndShadowSelection.DontAdd;
}
if (SelectedScaledBorderAndShadow.Content + "" == "ScaledBorderAndShadow: yes"){
return ScaledBorderAndShadowSelection.ScaledBorderAndShadowYes;
}
if (SelectedScaledBorderAndShadow.Content + "" == "ScaledBorderAndShadow: no"){
return ScaledBorderAndShadowSelection.ScaledBorderAndShadowNo;
}
return ScaledBorderAndShadowSelection.ScaledBorderAndShadowYes;
}
private ComboBoxItem GetScaledBorderAndShadowFromOptions(CrDownloadOptions options){
switch (options.SubsAddScaledBorder){
case (ScaledBorderAndShadowSelection.ScaledBorderAndShadowYes):
return ScaledBorderAndShadow.FirstOrDefault(a => a.Content != null && (string)a.Content == "ScaledBorderAndShadow: yes") ?? ScaledBorderAndShadow[0];
case ScaledBorderAndShadowSelection.ScaledBorderAndShadowNo:
return ScaledBorderAndShadow.FirstOrDefault(a => a.Content != null && (string)a.Content == "ScaledBorderAndShadow: no") ?? ScaledBorderAndShadow[0];
default:
return ScaledBorderAndShadow[0];
}
}
private void UpdateSubAndDubString(){ private void UpdateSubAndDubString(){
if (SelectedSubLang.Count == 0){ if (SelectedSubLang.Count == 0){
SelectedSubs = "none"; SelectedSubs = "none";
@ -626,6 +670,14 @@ public partial class SettingsPageViewModel : ViewModelBase{
partial void OnSelectedStreamEndpointChanged(ComboBoxItem value){ partial void OnSelectedStreamEndpointChanged(ComboBoxItem value){
UpdateSettings(); UpdateSettings();
} }
partial void OnAddScaledBorderAndShadowChanged(bool value){
UpdateSettings();
}
partial void OnSelectedScaledBorderAndShadowChanged(ComboBoxItem value){
UpdateSettings();
}
} }
public class MuxingParam{ public class MuxingParam{

View File

@ -45,7 +45,8 @@
</ToggleButton.Content> </ToggleButton.Content>
</ToggleButton> </ToggleButton>
<Popup IsLightDismissEnabled="True" <Popup IsLightDismissEnabled="True"
IsOpen="{Binding IsChecked, ElementName=DropdownButtonDub, Mode=TwoWay}" Placement="Bottom" IsOpen="{Binding IsChecked, ElementName=DropdownButtonDub, Mode=TwoWay}"
Placement="Bottom"
PlacementTarget="{Binding ElementName=DropdownButtonDub}"> PlacementTarget="{Binding ElementName=DropdownButtonDub}">
<Border BorderThickness="1" Background="{DynamicResource ComboBoxDropDownBackground}"> <Border BorderThickness="1" Background="{DynamicResource ComboBoxDropDownBackground}">
<ListBox x:Name="ListBoxDubsSelection" SelectionMode="Multiple,Toggle" Width="210" <ListBox x:Name="ListBoxDubsSelection" SelectionMode="Multiple,Toggle" Width="210"
@ -107,6 +108,18 @@
</StackPanel> </StackPanel>
</controls:SettingsExpander.Footer> </controls:SettingsExpander.Footer>
<controls:SettingsExpanderItem Content="Add ScaledBorderAndShadow ">
<controls:SettingsExpanderItem.Footer>
<StackPanel Orientation="Horizontal">
<ComboBox HorizontalContentAlignment="Center" IsVisible="{Binding AddScaledBorderAndShadow}" Margin="5 0" MinWidth="210" MaxDropDownHeight="400"
ItemsSource="{Binding ScaledBorderAndShadow}"
SelectedItem="{Binding SelectedScaledBorderAndShadow}">
</ComboBox>
<CheckBox IsChecked="{Binding AddScaledBorderAndShadow}"> </CheckBox>
</StackPanel>
</controls:SettingsExpanderItem.Footer>
</controls:SettingsExpanderItem>
</controls:SettingsExpander> </controls:SettingsExpander>
<controls:SettingsExpander Header="History" <controls:SettingsExpander Header="History"
@ -259,7 +272,8 @@
<StackPanel> <StackPanel>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBox Name="TargetTextBox2" HorizontalAlignment="Left" MinWidth="250" <TextBox Name="TargetTextBox2" HorizontalAlignment="Left" MinWidth="250"
Text="{Binding MkvMergeOption }"></TextBox> Text="{Binding MkvMergeOption }">
</TextBox>
<Button HorizontalAlignment="Center" Margin="5 0" Command="{Binding AddMkvMergeParam}"> <Button HorizontalAlignment="Center" Margin="5 0" Command="{Binding AddMkvMergeParam}">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<controls:SymbolIcon Symbol="Add" FontSize="18" /> <controls:SymbolIcon Symbol="Add" FontSize="18" />
@ -274,11 +288,14 @@
</ItemsControl.ItemsPanel> </ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<Border BorderBrush="#4a4a4a" Background="#4a4a4a" BorderThickness="1" CornerRadius="10" Margin="2"> <Border BorderBrush="#4a4a4a" Background="#4a4a4a" BorderThickness="1"
CornerRadius="10" Margin="2">
<StackPanel Orientation="Horizontal" Margin="5"> <StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="{Binding ParamValue}" Margin="5,0"/> <TextBlock Text="{Binding ParamValue}" Margin="5,0" />
<Button Content="X" FontSize="10" VerticalAlignment="Center" HorizontalAlignment="Center" Width="15" Height="15" Padding="0" <Button Content="X" FontSize="10" VerticalAlignment="Center"
Command="{Binding $parent[ItemsControl].((vm:SettingsPageViewModel)DataContext).RemoveMkvMergeParam}" CommandParameter="{Binding .}"/> HorizontalAlignment="Center" Width="15" Height="15" Padding="0"
Command="{Binding $parent[ItemsControl].((vm:SettingsPageViewModel)DataContext).RemoveMkvMergeParam}"
CommandParameter="{Binding .}" />
</StackPanel> </StackPanel>
</Border> </Border>
</DataTemplate> </DataTemplate>
@ -287,7 +304,6 @@
</StackPanel> </StackPanel>
</controls:SettingsExpanderItem.Footer> </controls:SettingsExpanderItem.Footer>
</controls:SettingsExpanderItem> </controls:SettingsExpanderItem>
@ -296,7 +312,8 @@
<StackPanel> <StackPanel>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBox HorizontalAlignment="Left" MinWidth="250" <TextBox HorizontalAlignment="Left" MinWidth="250"
Text="{Binding FfmpegOption }"></TextBox> Text="{Binding FfmpegOption }">
</TextBox>
<Button HorizontalAlignment="Center" Margin="5 0" Command="{Binding AddFfmpegParam}"> <Button HorizontalAlignment="Center" Margin="5 0" Command="{Binding AddFfmpegParam}">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<controls:SymbolIcon Symbol="Add" FontSize="18" /> <controls:SymbolIcon Symbol="Add" FontSize="18" />
@ -311,11 +328,14 @@
</ItemsControl.ItemsPanel> </ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<Border BorderBrush="#4a4a4a" Background="#4a4a4a" BorderThickness="1" CornerRadius="10" Margin="2"> <Border BorderBrush="#4a4a4a" Background="#4a4a4a" BorderThickness="1"
CornerRadius="10" Margin="2">
<StackPanel Orientation="Horizontal" Margin="5"> <StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="{Binding ParamValue}" Margin="5,0"/> <TextBlock Text="{Binding ParamValue}" Margin="5,0" />
<Button Content="X" FontSize="10" VerticalAlignment="Center" HorizontalAlignment="Center" Width="15" Height="15" Padding="0" <Button Content="X" FontSize="10" VerticalAlignment="Center"
Command="{Binding $parent[ItemsControl].((vm:SettingsPageViewModel)DataContext).RemoveFfmpegParam}" CommandParameter="{Binding .}"/> HorizontalAlignment="Center" Width="15" Height="15" Padding="0"
Command="{Binding $parent[ItemsControl].((vm:SettingsPageViewModel)DataContext).RemoveFfmpegParam}"
CommandParameter="{Binding .}" />
</StackPanel> </StackPanel>
</Border> </Border>
</DataTemplate> </DataTemplate>
@ -363,7 +383,8 @@
</controls:SettingsExpanderItem.Footer> </controls:SettingsExpanderItem.Footer>
</controls:SettingsExpanderItem> </controls:SettingsExpanderItem>
<controls:SettingsExpanderItem Content="Use Sonarr Numbering" Description="Potentially wrong if it couldn't be matched"> <controls:SettingsExpanderItem Content="Use Sonarr Numbering"
Description="Potentially wrong if it couldn't be matched">
<controls:SettingsExpanderItem.Footer> <controls:SettingsExpanderItem.Footer>
<CheckBox IsChecked="{Binding SonarrUseSonarrNumbering}"> </CheckBox> <CheckBox IsChecked="{Binding SonarrUseSonarrNumbering}"> </CheckBox>
</controls:SettingsExpanderItem.Footer> </controls:SettingsExpanderItem.Footer>