22.12.18 - ffmpeg merge 옵션 삭제
22.11.21 - --no-keep-fragments 옵션 추가, 3개의 쓰레드 사용 옵션 제거
22.10.08 - yt-dlp 설치링크 추가( 박스 용량문제로 yt-dlp 삭제)
22.10.01 - 출력파일명 수정 (채널명-연월일-방송시작시간-방제.확장자)
yt [유튜브링크][저장할_최상위_폴더]
arst
yt-dlp 설치 (환경변수 설정된 폴더에 저장해야합니다.)
압축 해제한 폴더를 본인지 절대 지우지 않을 폴더에 저장한다.
윈도우 탐색기에서 yt-dlp.exe가 보이는 데까지 이동한 후 아래 링크를 따라서 한다
등록한 후, 파워쉘을 끄고 켠다.
파워쉘에서 아래 명령어를 입력하면, 2022.11.11"와 같이 업데이트 된 날짜가 나와야 한다.
yt-dlp.exe --version
파일을 열어 수정할 부분을 수정한다.
주석을 보고 설명에 따라서 아래 변수를 설정한다
[string]$root_path="$HOME\Videos\youtube\streaming"
[string]$configs = "--cookies `"C:\youtube.com_cookies.txt`" --ffmpeg-location `"C:\ffmpeg\bin`""
yt-dlp -U
param( [string]$Uri, [string]$root_path = "${HOME}\Videos\youtube\live", [int]$time=60 )
[string]$externals = "--cookies `"C:\youtube.com_cookies.txt`" --ffmpeg-location `"C:\ffmpeg\bin`""
[string]$generalOpt = '-f bestvideo+bestaudio/best --merge-output-format mkv --no-part --ignore-errors --skip-unavailable-fragments --hls-use-mpegts --buffer-size 1M --force-overwrites'
[string]$postprocessor = '--postprocessor-args "Merger+ffmpeg_o:-sn -dn -map_metadata -1 -map_chapters -1 -metadata creation_time=now -movflags faststart -vcodec copy -acodec copy"'
[string]$outputOpt = "%(channel)s\%(channel)s-%(release_date>%y%m%d,upload_date>%y%m%d|Unknown)s-%(epoch-3600>%Hh%Mm%Ss)s-%(title)s.%(ext)s"
[string]$property = "${externals} ${generalOpt} --live-from-start ${postprocessor} -o `"${outputOpt}`""
function Invoke-Loop {
try {
Clear-Host;
while (($null -eq $Uri) -or ("" -eq $Uri)) { $Uri = Read-Host "링크 입력 " };
if ( -not (Test-Path $root_path) ) {New-Item $root_path -Type Directory | Out-Null}; Set-Location $root_path;
$i=0; $loop = $true;
[string]$Live_Uri = $Uri | Get-Info | New-LiveUri
if ($Live_Uri) {
Write-Host "유튜브 라이브 전역 링크: ${Live_Uri}"
Write-Host "`r`nyt-dlp ${property} ${Live_Uri}";
while($loop) {
$i++; Write-Host "`r`n`r`n${i}회차 루프";
Start-Process -NoNewWindow -Wait yt-dlp "${property} ${Live_Uri}"
timeout.exe /NoBreak $time
}
}
} catch {
Write-Host "`r`nAn error occurred:`r`n $($_.Exception.Message)";
$loop = $false
} finally { Write-Host "Exit!" }
}
function Get-Info {
param (
[CmdletBinding()][Parameter(ValueFromPipeline=$true)]
[string] $sourceUri = $null
)
if ( -not ($sourceUri -match 'youtu') ) {
$sourceUri = "https://www.youtube.com/@${sourceUri}"
}
try {
$response = Invoke-WebRequest $sourceUri
if ($response.StatusCode -ge 400) {
throw "HTTP error occurred. Status code:`r`n $($response.StatusCode)"
}
return $response.Content
} catch [System.Net.WebException] {
Write-Host "An error occurred. Error:`r`n $($_.Exception.Message)"
return $null
}
}
function New-LiveUri {
param (
[CmdletBinding()][Parameter(ValueFromPipeline=$true)]
[string]$text
)
if ($text -match "/@(\w+)") {
return "https://www.youtube.com/@$($Matches[1])/live"
} else { return $null }
}
Invoke-Loop