Something about ts seg dec
Tools
- powershell execution enviroment
- ffmpeg, ffplay
- nodejs
- m3u8dl(or internet_download_manager as idman)
Steps
- Paste the news url address to console window
- Analyze content to obtain res ID
- Get res info from api interface
- Get the h5e enc adress
- Replace to high quality address
- Download m3u8 address
- Download ts segments as enc res
- Decode the resources and save to dec folder
- Preview the high quality video from cache folder
- Merge dec resources as mp4 file
Code
execution_as_ps.bat
Param ( $MainEntry )
$oScript = @"
@echo off
cls
pushd %~dp0
>%tmp%\%~n0.ps1 more +0 %~s0
powershell -Command "Set-ExecutionPolicy -Scope Process Bypass; . %tmp%\%~n0.ps1 -MainEntry '%cd%'"
goto :EOF
"@
function pause() {
Write-Host "Press any key to contiune..."
[Console]::ReadKey() | Out-Null
}
function GetVID() {
Param( $oPage )
$strRegInnerContent = ".* guid(_0)* *=.*"
$strRet = ""
$bRet = $oPage.Content -Match $strRegInnerContent
if ($bRet) {
$strInnerCon = $Matches[0]
$strReg = ".* guid(_0)* *= *\`"([^`"]*)\`".*"
$bRet = $strInnerCon -match $strReg
if ($bRet) {
$strRet = $Matches[2]
}
}
return $strRet
}
function Download() {
Param ( $strUrl, $strFile, $bUseTool = $false )
if (!$bUseTool) {
Invoke-WebRequest -Uri "$strUrl" -Method GET -OutFile "$strFile"
} else {
$strCMD = "/d `"$strUrl`" /p `"${Script:WORK_ROOT}/cache/enc`" /f `"$(Split-Path -Leaf "$strFile")`" /n /q"
#$strCMD
Start idman -Args $strCMD -Wait
}
}
function DownloadAndDec() {
Param ($strUrl, $strTitle)
Write-Host "Current action:"
Write-Host "`tDownloading: ${strTitle}"
if (!(Test-Path "${Script:WORK_ROOT}")) { mkdir "${Script:WORK_ROOT}" }
if ((Test-Path "${Script:WORK_ROOT}/cache/enc")) { rm -Recurse -Force "${Script:WORK_ROOT}/cache/enc" }
if ((Test-Path "${Script:WORK_ROOT}/cache/dec")) { rm -Recurse -Force "${Script:WORK_ROOT}/cache/dec" }
mkdir "${Script:WORK_ROOT}/cache/enc"
mkdir "${Script:WORK_ROOT}/cache/dec"
Download -strUrl "$strUrl" -strFile "${Script:WORK_ROOT}/cache/dec/list.m3u8"
m3u8dl "$strUrl" --workDir "${Script:WORK_ROOT}" --noMerge --saveName cache
# Step 1: Download encrypt segments
$arrListUrl = @()
cat "${Script:WORK_ROOT}/cache/dec/list.m3u8" | findstr /v "^#" | %{
$strFile = $_.Trim()
Write-Host "Current file: $strFile"
$strFileUrl = $strUrl -Replace "2000.m3u8.*", "$strFile"
Write-Host "Current file url: $strFileUrl"
$oItem = @{
strFile = $strFile
strFileUrl = $strFileUrl
}
$arrListUrl += $oItem
}
#pause
$nCodecLength = ([string]$arrListUrl.Length).Length
for ($nIndex = 0; $nIndex -lt $arrListUrl.Length; $nIndex++) {
Write-Host "=====================Segment Process Mission========================="
Write-Host "Step 1: Download encrypt segments"
# Download each segment to cache folder
# Replaced by m3u8dl with --noMerge param [2024/11/05]
#Download -strUrl $($oItem.strFileUrl) -strFile "${Script:WORK_ROOT}/cache/enc/$($oItem.strFile)" -bUseTool $true
# Step 2: Decrypt segments
Write-Host "Step 2: Decrypt segments"
$strFileNameEnc = "00000$($arrListUrl[$nIndex].strFile)"
$strFileNameEnc = $strFileNameEnc.Substring($strFileNameEnc.Length - (3 + $nCodecLength))
Write-Host "Search file: $strFileNameEnc"
$strFileEnc = $(ls ${Script:WORK_ROOT}/cache/Part_0/*.ts | ?{ $_.FullName -like "*0*$strFileNameEnc" } | %{ $_.FullName})
Write-Host "Process file: $strFileEnc"
node cctv_dec/ts_decrypt.js "$strFileEnc" "${Script:WORK_ROOT}/cache/dec/$($arrListUrl[$nIndex].strFile)"
if ($nIndex -ge 6 -and ${Script:PREVIEWING} -eq $false) {
${Script:PREVIEWING} = $true
Preview -strUrl "${Script:WORK_ROOT}/cache/dec/list.m3u8" -strTitle "$strTitle"
}
#pause
}
#Write-Host "Press any key till downloading segments mission complete successfully."
#pause
# Step 3: Merge segments
Write-Host "Step 3: Merge segments"
$strCMD = "ffmpeg -hide_banner -i `"${Script:WORK_ROOT}/cache/dec/list.m3u8`" -c copy -y `"${strTitle}.mp4`""
Start cmd -NoNewWindow -Args "/c $strCMD" -Wait
#rm ${Script:WORK_ROOT}/* -Recurse -Force
}
function Preview() {
Param ( $strUrl, $strTitle )
Write-Host "Current action:"
Write-Host "`tPlaying: ${strTitle}"
$strCMD = "ffplay -hide_banner -i `"$strUrl`" -window_title `"XXTV_Preview::${strTitle}`" -autoexit"
Start cmd -NoNewWindow -args "/c $strCMD" -RedirectStandardError .\Nul
}
function main() {
Param ( $Entry )
pushd $Entry
$strNewsUrl = Read-Host "请输入视频观看网址"
$oPage = Invoke-WebRequest "$strNewsUrl"
$strVID = GetVID $oPage
Write-Host "当前视频信息:"
Write-Host "`t$strVID"
if ("" -ne "$strVID") {
$strAPIUrl = "https://FQDN/api/getHttpVideoInfo.do?pid=${strVID}"
#Write-Host "API Url: $strAPIUrl"
$oRet = Invoke-RestMethod "$strAPIUrl"
Write-Host $($oRet | ConvertTo-Json)
$strPreviewUrl = "$($oRet.hls_url)"
$strTitle = "$($oRet.title)"
Write-Host "Preview URL: $strTrueUrl"
#Preview "$strPreviewUrl" "$strTitle"
$strH5eUrl = $oRet.manifest.hls_h5e_url
$strH5eUrl = $strH5eUrl -replace "main", "2000"
Write-Host "h5e_url : $strH5eUrl"
DownloadAndDec -strUrl "$strH5eUrl" -strTitle "$strTitle"
} else {
Write-Host "No valiable info found in page. Contact the author of script."
}
}
$PREVIEWING = $false
$WORK_ROOT = "${env:localappdata}/xxtv_downloader"
main -Entry $MainEntry
pause

References
- https://www.52pojie.cn/thread-1875225-1-1.html
- https://www.52pojie.cn/thread-1957747-1-1.html
- https://github.com/nilaoda/N_m3u8DL-CLI

245

被折叠的 条评论
为什么被折叠?



