# Contributor: Peter Bui <pnutzh4x0r@gmail.com>
# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Timo Teräs <timo.teras@iki.fi>
# Contributor: Leo <thinkabit.ukim@gmail.com>
# Contributor: Sodface <sod@sodface.com>
# Maintainer: lauren n. liberda <lauren@selfisekai.rocks>
pkgname=yt-dlp
pkgver=2025.06.25
pkgrel=0
pkgdesc="Command-line program to download videos from YouTube"
url="https://github.com/yt-dlp/yt-dlp"
arch="noarch"
license="Unlicense"
depends="python3"
_extradeps="
	attr
	ca-certificates
	ffmpeg
	py3-brotli
	py3-mutagen
	py3-pycryptodomex
	py3-secretstorage
	py3-websockets
	"
makedepends="$_extradeps py3-gpep517 py3-hatchling"
checkdepends="
	py3-flake8
	py3-nose
	py3-pytest-xdist
	py3-requests
	"
subpackages="
	$pkgname-core-pyc
	$pkgname-core
	$pkgname-doc
	$pkgname-zsh-completion
	$pkgname-bash-completion
	$pkgname-fish-completion
	"
[ "$CARCH" != 'riscv64' ] || options="!check"
source="$pkgname-$pkgver.tar.gz::https://github.com/yt-dlp/yt-dlp/releases/download/$pkgver/yt-dlp.tar.gz
	"
builddir="$srcdir/$pkgname"

# secfixes:
#   2024.07.01-r0:
#     - CVE-2024-38519
#   2023.11.14-r0:
#     - CVE-2023-46121
#   2023.07.06-r0:
#     - CVE-2023-35934
#   0-r0:
#     - CVE-2023-40581
#     - CVE-2024-22423

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	python3 -m venv --clear --without-pip --system-site-packages .testenv
	.testenv/bin/python3 -m installer .dist/*.whl
	# last 2 are flaky in upstream, failing more often than not here
	.testenv/bin/python3 -m pytest -k 'not download and not verify_cert and not mtls' -n logical
}

package() {
	depends="
		$_extradeps
		yt-dlp-core=$pkgver-r$pkgrel
		"

	python3 -m installer -d "$pkgdir" \
		.dist/*.whl

	ln -sfv yt-dlp "$pkgdir"/usr/bin/youtube-dl
}

core() {
	# provide compat for removed old youtube-dl
	provides="youtube-dl=$pkgver-r$pkgrel"
	replaces="youtube-dl"

	amove usr/lib/python3*/site-packages/
	amove usr/bin
}

sha512sums="
545bac883124ec6c059a99cfbdc8f8707c22589d6fba6ef41fae7a81e894bdaab871e238b9b339bde2ceb1666558767013a7549046f99706857c27560b19ac2e  yt-dlp-2025.06.25.tar.gz
"
