-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmp.playdir.ps1
123 lines (96 loc) · 3.45 KB
/
mp.playdir.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<#
.SYNOPSIS
Plays the media files in a given directory with mpv.
.DESCRIPTION
Simple script utilizing mpv to play media (video) files in a specified directory.
Dependencies:
- mpv (https://mpv.io/)
.PARAMETER Path
Specifies the path to the directory containing the media files you want to play.
Uses the current working location as default if no path is specified.
.PARAMETER Fullscreen
Switch to run mpv with the fullscreen flag set.
Be aware that this can be overridden, depending on the 'Options' parameter.
.PARAMETER Options
A collection of string values describing the command-line options that are passed on to mpv.
.PARAMETER Random
Switch to play the media files in randomized order.
Uses the standard alphanumeric sorting by default, as is.
.EXAMPLE
mp.playdir
.EXAMPLE
mp.playdir -Options saturation=28, volume=50
.EXAMPLE
mp.playdir -Path .\Films -Full -Random
.INPUTS
None. You cannot pipe objects to mp.playdir.ps1.
.OUTPUTS
None. mp.playdir.ps1 does not generate any output.
.LINK
https://github.com/Hrxn/pwsh
#>
#Requires -Version 7.1
param (
[Parameter()][string] $Path = $PWD.ToString(),
[Parameter()][switch] $Fullscreen = $false,
[Parameter()][switch] $Random = $false,
[Parameter(ValueFromRemainingArguments)][string[]] $Options
)
if ($PWD.Provider.Name -cne 'FileSystem') {
Write-Host '[mp.playdir] : Error -> The current working directory is not a valid path in a filesystem!' -ForegroundColor Red
exit 255
}
if ($null -eq (Get-Command -Name 'mpv' -ErrorAction Ignore)) {
Write-Host '[mp.playdir] : Error -> Dependency Error: Missing dependency: mpv' -ForegroundColor DarkRed
exit 254
}
if ($Path -eq '--help' -or $Path -eq '?') {
Write-Host '[mp.playdir] Usage: mp.playdir.ps1 [-Path] [<PATH>] [-Fullscreen] [-Options] [<MPV OPTIONS>] [-Random]'
exit 0
}
if (-not (Test-Path -LiteralPath $Path -PathType Container)) {
Write-Host "[mp.playdir] The given path parameter ""$Path"" does not exist as a valid directory!"
exit 1
}
$Realpath = Convert-Path -LiteralPath $Path -ErrorAction Stop
$Dirfiles = Get-ChildItem -Path $Realpath -File
$Playlist = [Collections.Generic.List[String]]::new()
$Execfile = (Get-Command -Name 'mpv').Path
if ($null -eq $Dirfiles) {
Write-Host "[mp.playdir] The specified directory ""$Realpath"" does not contain any files!"
exit
}
$FileExtsVid = @(
'.webm', '.mkv', '.mp4', '.mov', '.wmv', '.asf', '.ogv', '.avi', '.ts', '.flv', '.m4v', '.rm', '.rmvb', '.vob',
'.mpg', '.mp2', '.mpeg', '.mpe', '.mpv', '.m2v', '.mxf', '.m4p', '.drc', '.mts', '.m2ts', '.f4v', '.qt',
'.3gp', '.3g2', '.mk3d', '.m2p', '.ps', '.tsv', '.evo', '.ogx', '.divx', '.amv', '.yuv'
)
foreach ($File in $Dirfiles) {
if ($File.Extension -in $FileExtsVid) {
$Playlist.Add($File.FullName)
}
}
if ($Playlist.Count -eq 0) {
Write-Host "[mp.playdir] The specified directory ""$Realpath"" does not contain any supported media files!"
exit
}
if ($Random) {
$Playlist = $Playlist | Get-Random -Shuffle
}
for ($i = 0; $i -lt (($Options | Measure-Object).Count); $i++) {
$Options[$i] = $Options[$i].Insert(0, '--')
}
# Two (internal) different application call modes:
enum OutputType {Sstr; Pipe}
# Change OutputMode manually here:
$OutputMode = [OutputType]::Sstr
function _Output_Pipe {
$Playlist | & $Execfile $(if ($Fullscreen) {'--fs'}) $Options '--playlist=-'
}
function _Output_Sstr {
& $Execfile $(if ($Fullscreen) {'--fs'}) $Options $Playlist
}
switch ($OutputMode) {
([OutputType]::Sstr) {_Output_Sstr; break}
([OutputType]::Pipe) {_Output_Pipe; break}
}