From 433cfe886d0ef4280a142116e657a0006ddd2fc9 Mon Sep 17 00:00:00 2001 From: Obegg <13978119+Obegg@users.noreply.github.com> Date: Thu, 27 Jun 2024 21:33:52 +0300 Subject: [PATCH] updater.ps1: add update channels for yt-dlp Co-authored-by: zhongfly <11155705+zhongfly@users.noreply.github.com> --- mpv-root/installer/updater.ps1 | 96 ++++++++++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 10 deletions(-) diff --git a/mpv-root/installer/updater.ps1 b/mpv-root/installer/updater.ps1 index d8df970..e064315 100644 --- a/mpv-root/installer/updater.ps1 +++ b/mpv-root/installer/updater.ps1 @@ -83,7 +83,17 @@ function Download-Ytplugin ($plugin, $version) { if (-Not (Test-Path (Join-Path $env:windir "SysWow64"))) { $32bit = "_x86" } - $link = -join("https://github.com/yt-dlp/yt-dlp/releases/download/", $version, "/", $plugin, $32bit, ".exe") + $ytdlp_channel = Check-Ytdlp-Channel + if ($ytdlp_channel -eq 'stable') { + $repo = "https://github.com/yt-dlp/yt-dlp" + } + elseif ($ytdlp_channel -eq 'nightly') { + $repo = "https://github.com/yt-dlp/yt-dlp-nightly-builds" + } + elseif ($ytdlp_channel -eq 'master') { + $repo = "https://github.com/yt-dlp/yt-dlp-master-builds" + } + $link = -join($repo, "/releases/download/", $version, "/", $plugin, $32bit, ".exe") $plugin_exe = -join($plugin, $32bit, ".exe") } "youtube-dl" { @@ -141,13 +151,23 @@ function Get-Latest-Mpv($Arch, $channel) { function Get-Latest-Ytplugin ($plugin) { switch -wildcard ($plugin) { "yt-dlp*" { - $link = "https://github.com/yt-dlp/yt-dlp/releases.atom" - Write-Host "Fetching RSS feed for ytp-dlp" -ForegroundColor Green + $ytdlp_channel = Check-Ytdlp-Channel + if ($ytdlp_channel -eq 'stable') { + $repo = "https://github.com/yt-dlp/yt-dlp" + } + elseif ($ytdlp_channel -eq 'nightly') { + $repo = "https://github.com/yt-dlp/yt-dlp-nightly-builds" + } + elseif ($ytdlp_channel -eq 'master') { + $repo = "https://github.com/yt-dlp/yt-dlp-master-builds" + } + $link = -join($repo, "/releases.atom") + Write-Host "Fetching RSS feed for yt-dlp $ytdlp_channel" -ForegroundColor Green $resp = [xml](Invoke-WebRequest $link -MaximumRedirection 0 -ErrorAction Ignore -UseBasicParsing).Content $link = $resp.feed.entry[0].link.href $version = $link.split("/")[-1] return $version - } + } "youtube-dl" { $link = "https://yt-dl.org/downloads/latest/youtube-dl.exe" Write-Host "Fetching RSS feed for youtube-dl" -ForegroundColor Green @@ -242,6 +262,7 @@ function Create-XML { unset unset unset + unset "@ | Set-Content "settings.xml" -Encoding UTF8 } @@ -370,12 +391,26 @@ function Check-GetYTDL() { if (-not (Test-Path $file)) { exit } [xml]$doc = Get-Content $file if ($null -eq $doc.settings.getytdl) { + $yt = Check-Ytplugin + if ($yt -Match "yt-dlp*") { + $get_ytdl = "ytdlp" + } + elseif ($yt -Match "youtube-dl.exe"){ + $get_ytdl = "youtubedl" + } + else { + $get_ytdl = "unset" + } $newNode = $doc.CreateElement("getytdl") - $newNode.AppendChild($doc.CreateTextNode("unset")) | out-null + $newNode.AppendChild($doc.CreateTextNode($get_ytdl)) | out-null $doc.settings.appendchild($newNode) | out-null + $doc.Save($file) } - if ($doc.settings.getytdl -eq "unset") { - Write-Host "ytdlp or youtube-dl doesn't exist. " -ForegroundColor Green -NoNewline + else { + $get_ytdl = $doc.settings.getytdl + } + + if ($get_ytdl -eq "unset") { $result = Read-KeyOrTimeout "Download ytdlp or youtubedl? [1=ytdlp/2=youtubedl/N] (default=1)" "D1" Write-Host "" if ($result -eq 'D1') { @@ -393,11 +428,45 @@ function Check-GetYTDL() { $doc.settings.getytdl = $get_ytdl $doc.Save($file) } + + return $get_ytdl +} + +function Check-Ytdlp-Channel() { + $ytdlp_channel = "" + $file = "settings.xml" + + if (-not (Test-Path $file)) { exit } + [xml]$doc = Get-Content $file + if ($null -eq $doc.settings.ytdlpchannel) { + $newNode = $doc.CreateElement("ytdlpchannel") + $newNode.AppendChild($doc.CreateTextNode("unset")) | out-null + $doc.settings.appendchild($newNode) | out-null + } + if ($doc.settings.ytdlpchannel -eq "unset") { + $result = Read-KeyOrTimeout "Which update channel to update yt-dlp to? [1=stable/2=nightly/3=master] (default=1)" "D1" + Write-Host "" + if ($result -eq 'D1') { + $ytdlp_channel = "stable" + } + elseif ($result -eq 'D2') { + $ytdlp_channel = "nightly" + } + elseif ($result -eq 'D3') { + $ytdlp_channel = "master" + } + else { + throw "Please enter valid input key." + } + $doc.settings.ytdlpchannel = $ytdlp_channel + $doc.Save($file) + } else { - $get_ytdl = $doc.settings.getytdl + $ytdlp_channel = $doc.settings.ytdlpchannel } - return $get_ytdl + return $ytdlp_channel } + function Upgrade-Mpv { $need_download = $false $remoteName = "" @@ -479,10 +548,17 @@ function Upgrade-Ytplugin { } else { Write-Host "Newer" (Get-Item $yt).BaseName "build available" -ForegroundColor Green - & $yt --update + if ($yt -Match "yt-dlp*") { + $ytdlp_channel = Check-Ytdlp-Channel + & $yt --update-to $ytdlp_channel + } + else { + & $yt --update + } } } else { + Write-Host "ytdlp or youtube-dl doesn't exist. " -ForegroundColor Green -NoNewline $ytdl = Check-GetYTDL if ($ytdl -eq 'ytdlp') { $latest_release = Get-Latest-Ytplugin "yt-dlp"