Skip to content

Commit 8675bb1

Browse files
author
Ili Metuky
committed
Base
0 parents  commit 8675bb1

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

Split-MotionPhoto.ps1

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
function Split-MotionPhoto
2+
{
3+
<#
4+
.SYNOPSIS
5+
Short Description
6+
.DESCRIPTION
7+
Detailed Description
8+
.EXAMPLE
9+
Split-MotionPhoto
10+
explains how to use the command
11+
can be multiple lines
12+
.EXAMPLE
13+
Split-MotionPhoto
14+
another example
15+
can have as many examples as you like
16+
#>
17+
[CmdletBinding()]
18+
param
19+
(
20+
[Parameter(Mandatory, Position=0)]
21+
[System.String]
22+
$FilePath
23+
)
24+
25+
$PatternString = 'MotionPhoto_Data'
26+
27+
$Raw = Get-Content -Path $FilePath -Raw
28+
$RawSplit = $Raw -split $PatternString
29+
if ($RawSplit.Length -ne 2)
30+
{
31+
throw "Split failed $PatternString not found."
32+
}
33+
34+
$Encoding = [system.Text.Encoding]::Default
35+
[System.IO.File]::WriteAllBytes(($FilePath -replace '.jpg','_New.jpg'),$Encoding.GetBytes($RawSplit[0]))
36+
[System.IO.File]::WriteAllBytes(($FilePath -replace '.jpg','_New.mp4'),$Encoding.GetBytes($RawSplit[1]))
37+
}
38+
39+
Add-Type -AssemblyName System.Windows.Forms
40+
$OpenFileDialog = [System.Windows.Forms.OpenFileDialog]::new()
41+
#$OpenFileDialog.InitialDirectory = [System.IO.Directory]::GetCurrentDirectory()
42+
$OpenFileDialog.Title = 'Select files to split'
43+
$OpenFileDialog.Filter = 'Samsung Motion Photo Files (*.JPG)|*.JPG|All Files (*.*)|*.*'
44+
$OpenFileDialog.Multiselect = $true
45+
46+
$Result = $OpenFileDialog.ShowDialog()
47+
if ($Result -eq 'OK')
48+
{
49+
foreach ($File in $OpenFileDialog.FileNames)
50+
{
51+
"Splitting $File"
52+
try
53+
{
54+
Split-MotionPhoto -FilePath $File -ErrorAction Stop
55+
56+
}
57+
catch
58+
{
59+
Write-Error -Message "Split failed for file: $File. Error: $_"
60+
}
61+
}
62+
}
63+
else
64+
{
65+
'Import Settings File Cancelled!'
66+
}

0 commit comments

Comments
 (0)