Its built for the DirecTV M3U files. I need to make it more universal. You open command prompt in the folder the converter script and m3u txt file are in. Run this command
convert_m3u.bat input.txt output.json
example for the last run was
convert_m3u.bat directv_sat_la.txt directv_sat_la.json
<# : batch script wrapper
@echo off
setlocal
if "%~1"=="" (
echo Usage: convert_m3u.bat input.txt output.json
echo Example: convert_m3u.bat directv_sat_la.txt directv_sat_la.json
exit /b 1
)
:: Set environment variables for the PowerShell script to read
set "INPUT_FILE=%~1"
set "OUTPUT_FILE=%~2"
:: Execute the PowerShell logic written below
powershell -NoProfile -ExecutionPolicy Bypass -Command "Invoke-Expression ([System.IO.File]::ReadAllText('%~f0'))"
exit /b %ERRORLEVEL%
#>
# --- PowerShell Logic Begins Here ---
$InputFile = $env:INPUT_FILE
$OutputFile = $env:OUTPUT_FILE
if ([string]::IsNullOrWhiteSpace($OutputFile)) {
$OutputFile = "output.json"
}
# 1. Read the M3U content
$content = Get-Content $InputFile
$channels = @()
$currentChannel = @{}
# 2. Parse the lines
foreach ($line in $content) {
if ($line.StartsWith('#EXTINF')) {
# Extract Gracenote ID
if ($line -match 'tvc-guide-stationid="(.*?)"') {
$currentChannel.tvc_guide_stationid = $matches[1]
} else {
$currentChannel.tvc_guide_stationid = ""
}
# Extract Name
$name = $line.Substring($line.IndexOf(',') + 1).Trim()
$currentChannel.name = $name
# Format the ID string (lowercase, replace non-alphanumeric with hyphens)
$id = $name.ToLower() -replace '[^a-z0-9]', '-' -replace '-+', '-' -replace '^-|-$', ''
$currentChannel.id = "$id-dtv"
}
elseif ($line.StartsWith('http')) {
# Extract the deep link (everything after /tuner/ and convert ~ to /)
$dl = $line.Substring($line.IndexOf('/tuner/') + 7) -replace '~', '/'
$currentChannel.deep_link_content_id = $dl
$currentChannel.provider_id = 'directv'
# Ensure ordered properties for clean JSON output
$obj = [ordered]@{
name = $currentChannel.name
id = $currentChannel.id
provider_id = $currentChannel.provider_id
deep_link_content_id = $currentChannel.deep_link_content_id
tvc_guide_stationid = $currentChannel.tvc_guide_stationid
}
$channels += $obj
$currentChannel = @{}
}
}
# 3. Build Provider Header
$providerObj = [ordered]@{
id = "directv"
name = "DirecTV Ultimate"
package_name = "com.att.tv"
component = "com.clientapp.MainActivity"
fire_package_name = "com.att.tv"
fire_component = "com.clientapp.MainActivity"
url_template = "dtvnow://deeplink.directvnow.com/play/channel/{id}"
splash_delay_ms = 3000
}
# 4. Construct Final Object
$finalObj = [ordered]@{
providers = @($providerObj)
channels = $channels
}
# 5. Output formatted JSON
$finalObj | ConvertTo-Json -Depth 5 | Set-Content -Path $OutputFile -Encoding UTF8
Write-Host ""
Write-Host "======================================"
Write-Host "Success! Converted $($channels.Count) channels."
Write-Host "Saved output to: $OutputFile"
Write-Host "======================================"
I'll add the YouTube M3U support to it in the near future and post the updated file.