-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.ps1
More file actions
100 lines (86 loc) · 3.88 KB
/
Copy pathstart.ps1
File metadata and controls
100 lines (86 loc) · 3.88 KB
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
# start.ps1 - Local Offline Stream Server for VLC
# Run this script to automatically fix wrong extensions, generate the playlist, and serve the music files locally.
# 1. Detect and fix incorrect file extensions in the mp3files folder
$MusicDir = Join-Path $PSScriptRoot "mp3files"
if (Test-Path $MusicDir) {
Write-Host "Checking for incorrect file extensions..." -ForegroundColor Cyan
$Files = Get-ChildItem -Path $MusicDir -File
$RenamedCount = 0
foreach ($File in $Files) {
$FilePath = $File.FullName
# Open file stream and read the first 12 bytes
try {
$Stream = [System.IO.File]::OpenRead($FilePath)
$Buffer = New-Object byte[] 12
$BytesRead = $Stream.Read($Buffer, 0, 12)
$Stream.Close()
}
catch {
continue
}
if ($BytesRead -lt 8) {
continue
}
# Check for 'ftyp' at offset 4 (MPEG-4 container: M4A, MP4)
$IsM4A = $Buffer[4] -eq 0x66 -and $Buffer[5] -eq 0x74 -and $Buffer[6] -eq 0x79 -and $Buffer[7] -eq 0x70
# Check for 'ID3' at offset 0 (MP3)
$IsID3 = $Buffer[0] -eq 0x49 -and $Buffer[1] -eq 0x44 -and $Buffer[2] -eq 0x33
$CurrentExt = $File.Extension.ToLower()
$NewExt = $null
if ($IsM4A -and $CurrentExt -ne ".m4a") {
$NewExt = ".m4a"
} elseif ($IsID3 -and $CurrentExt -ne ".mp3") {
$NewExt = ".mp3"
}
if ($NewExt) {
$NewName = [System.IO.Path]::ChangeExtension($File.Name, $NewExt)
Write-Host "Fixing extension: '$($File.Name)' -> '$NewName'" -ForegroundColor Yellow
try {
Rename-Item -LiteralPath $FilePath -NewName $NewName -Force
$RenamedCount++
}
catch {
Write-Error "Failed to rename $($File.Name): $_"
}
}
}
if ($RenamedCount -gt 0) {
Write-Host "Renamed $RenamedCount file(s) to their true extension." -ForegroundColor Green
} else {
Write-Host "All extensions are correct." -ForegroundColor Green
}
}
# 2. Regenerate the playlist
Write-Host "`nRegenerating playlist..." -ForegroundColor Cyan
python generate_playlist.py
# 3. Detect Local Network IPv4 Address
$LocalIP = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object { $_.IPAddress -notlike "127.*" -and $_.IPAddress -notlike "169.254.*" } | Select-Object -First 1).IPAddress
if (-not $LocalIP) {
$LocalIP = "127.0.0.1"
}
$Port = 8000
$LocalUrl = "http://localhost:$Port/playlist.m3u"
$NetworkUrl = "http://$($LocalIP):$Port/playlist.m3u"
Write-Host "`n==================================================" -ForegroundColor Green
Write-Host "🎵 LOCAL OFFLINE STREAM SERVER STARTED 🎵" -ForegroundColor Green
Write-Host "==================================================" -ForegroundColor Green
Write-Host "Your music server is running offline."
Write-Host ""
Write-Host "👉 To play locally on this PC (completely offline, no server needed):" -ForegroundColor Yellow
Write-Host " Double-click 'playlist.m3u' or open it directly in VLC."
Write-Host ""
Write-Host "👉 To stream to other devices (Phone, Tablet, PC) on your local Wi-Fi:" -ForegroundColor Yellow
Write-Host " 1. Connect your device to the same Wi-Fi network."
Write-Host " 2. Open VLC on your device."
Write-Host " 3. Go to 'Stream' or 'Open Network Stream' and enter:"
Write-Host " $NetworkUrl" -ForegroundColor Cyan
Write-Host ""
if ($RenamedCount -gt 0) {
Write-Host "⚠️ IMPORTANT: You have renamed files. Don't forget to commit and push them" -ForegroundColor Yellow
Write-Host " to GitHub so your online cloud stream is updated!" -ForegroundColor Yellow
Write-Host ""
}
Write-Host "Press Ctrl+C to stop the local web server."
Write-Host "==================================================`n"
# Start python's built-in web server
python -m http.server $Port