-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgta_playlist.ps1
86 lines (79 loc) · 3.13 KB
/
gta_playlist.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
# In order to run, you may have to allow custom scripts... Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
# Taken from https://superuser.com/questions/108207/how-to-run-a-powershell-script-as-administrator
param([switch]$Elevated)
function Test-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if ((Test-Admin) -eq $false) {
if ($elevated)
{
# tried to elevate, did not work, aborting
}
else {
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
}
exit
}
'running with full privileges'
# Taken from https://stackoverflow.com/a/25690250/1253609
Function FileBrowser([string] $initialDirectory = 'Desktop', [bool] $foldersOnly = $false, [string] $description) {
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
if ($foldersOnly -eq $true) {
$Browser = New-Object System.Windows.Forms.FolderBrowserDialog
if ($initialDirectory) {
$Browser.SelectedPath = $initialDirectory
}
if ($description) {
$Browser.Description = $description
}
}
else {
$Browser = New-Object System.Windows.Forms.OpenFileDialog
$Browser.filter = 'All files (*.*)|*.*'
if ($initialDirectory) {
$Browser.initialDirectory = $initialDirectory
}
}
[void] $Browser.ShowDialog()
if ($foldersOnly) {
return $Browser.SelectedPath
}
return $Browser.FileName
}
function playlistGta($playlist) {
[System.Collections.ArrayList] $list = @()
foreach($line in Get-Content $playlist) {
# Winamp adds some weird metadata to m3u8 files
if (!($line -match "^#")) {
if ($line -match "^\\Shared") {
$line = 'Z:' + $line
}
$a = Get-Item -LiteralPath $line
# Replace any slashes, so we don't attempt to create new dirs
$path = $a.FullName.Replace('\', "_")
# Unfortunately, we have to replace [ and ] with three tildas before it... -Target doesn't use literal pathing like -Path
# See also https://github.com/PowerShell/PowerShell/issues/6232
$a = $a.FullName.Replace('[', "```[")
$a = $a.Replace(']', "```]")
$a = $a -replace '\\\\MyCloudEx2Ultra\\Public', 'Z:'
$list.Add([System.Collections.ArrayList] @($path, $a))
}
}
for ($i = 0; $i -lt 200; $i++) {
$max = $list.Count - 1
$index = Get-Random -Minimum 0 -Maximum $max
$item = $list[$index]
$list.RemoveAt($index)
#echo $item[0]
#echo $item[1]
New-Item -ItemType SymbolicLink -Path $item[0] -Target $item[1]
}
#New-Item -ItemType SymbolicLink -Path "$path" -Target "$a"
}
# Make sure admin user can access network drive... https://stackoverflow.com/a/4777229
net use Z: '\\MyCloudEx2Ultra\Public'
$gtaLocation = FileBrowser "$env:userprofile\Documents\Rockstar Games\GTA V\User Music" $true 'Select GTA V User Music Directory'
$playlist = FileBrowser 'Z:\Shared Music\Playlists\Playlists'
cd $gtaLocation
playlistGta "$playlist"