Skip to content

Commit

Permalink
update file drag for merging video
Browse files Browse the repository at this point in the history
  • Loading branch information
butaixianran committed Jan 3, 2024
1 parent 34f6432 commit 296b0df
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
8 changes: 7 additions & 1 deletion VideoRangeCopier/Model/MergeOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ public void GetVideoInfoByUri(string file_name, Uri file_path)

string name_no_ext = video_name.Replace(ext, "");

string new_name = name_no_ext + "_merged" + ext;
string new_ext = ext;
if (new_ext != ".mp4" && new_ext != ".mkv")
{
new_ext = ".mp4";
}

string new_name = name_no_ext + "_merged" + new_ext;

output_path = video_path.Replace(video_name, new_name);

Expand Down
2 changes: 1 addition & 1 deletion VideoRangeCopier/Util/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace VideoRangeCopier.Util
public static class Global
{
public static string AppName = "VideoRangeCopier";
public static string AppVersion = "";
public static string AppVersion = "0.3.0";

public static string Error = "";

Expand Down
11 changes: 7 additions & 4 deletions VideoRangeCopier/Views/MergeView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,24 @@
</Panel>

<StackPanel Margin="5">
<Border Margin="5" Padding="10" Background="Gray" HorizontalAlignment="Left" Width="80" DragDrop.AllowDrop="True">
<TextBlock>Drop File</TextBlock>
</Border>


<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Margin="5" VerticalAlignment="Center">Video File:</TextBlock>
<Button Margin="5" Click="SelectVideoFile_Clicked">Pick</Button>
<Border Name="DropVideoBorder" Margin="5" Padding="10" Background="Gray" HorizontalAlignment="Left" Width="130" DragDrop.AllowDrop="True" CornerRadius="4">
<TextBlock>Drop Video File</TextBlock>
</Border>
</StackPanel>
<TextBlock Name="VideoPathTextBlock" Margin="5"></TextBlock>


<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Margin="5" VerticalAlignment="Center">Audio File:</TextBlock>
<Button Margin="5" Click="SelectAudioFile_Clicked">Pick</Button>

<Border Name="DropAudioBorder" Margin="5" Padding="10" Background="Gray" HorizontalAlignment="Left" Width="130" DragDrop.AllowDrop="True" CornerRadius="4">
<TextBlock>Drop Audio File</TextBlock>
</Border>
</StackPanel>
<TextBlock Name="AudioPathTextBlock" Margin="5"></TextBlock>

Expand Down
37 changes: 27 additions & 10 deletions VideoRangeCopier/Views/MergeView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public partial class MergeView : UserControl
public MergeView()
{
InitializeComponent();
AddHandler(DragDrop.DropEvent, File_Drop);
DropVideoBorder.AddHandler(DragDrop.DropEvent, DropVideo);
DropAudioBorder.AddHandler(DragDrop.DropEvent, DropAudio);
}

private async void SelectVideoFile_Clicked(object sender, RoutedEventArgs args)
Expand Down Expand Up @@ -75,7 +76,7 @@ private async void SelectAudioFile_Clicked(object sender, RoutedEventArgs args)

}

private void File_Drop(object? sender, DragEventArgs e)
private void DropVideo(object? sender, DragEventArgs e)
{
if (!e.Data.Contains(DataFormats.Files)) { return; }

Expand All @@ -98,21 +99,37 @@ private void File_Drop(object? sender, DragEventArgs e)
Helper.Log($"Dragged Item name:{item.Name}");
Helper.Log($"Dragged Item path:{item.Path}");

string ext = Path.GetExtension(item.Name);
Global.MergeOpt.GetVideoInfoByUri(item.Name, item.Path);
VideoPathTextBlock.Text = Global.MergeOpt.video_path;

}

string[] audio_exts = [".m4a", ".wav", ".mp3"];
private void DropAudio(object? sender, DragEventArgs e)
{
if (!e.Data.Contains(DataFormats.Files)) { return; }

if (audio_exts.Contains(ext))
var files = e.Data.GetFiles() ?? Array.Empty<IStorageItem>();

if (files.Count() < 1)
{
Global.MergeOpt.GetAudioInfoByUri(item.Path);
AudioPathTextBlock.Text = Global.MergeOpt.audio_path;
return;
}
else

var item = files.First();

if (item is null) { return; }

if (!(item is IStorageFile))
{
Global.MergeOpt.GetVideoInfoByUri(item.Name, item.Path);
VideoPathTextBlock.Text = Global.MergeOpt.video_path;
return;
}

Helper.Log($"Dragged Item name:{item.Name}");
Helper.Log($"Dragged Item path:{item.Path}");

Global.MergeOpt.GetAudioInfoByUri(item.Path);
AudioPathTextBlock.Text = Global.MergeOpt.audio_path;

}

private async void Start_Click(object sender, RoutedEventArgs args)
Expand Down

0 comments on commit 296b0df

Please sign in to comment.