# 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=2024.08.06
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'
}

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="
5db3ceeb217148755e31492d490bfeb69879400873274dec4320ce58b49dce9ce93d1e32714d6b7433364780e269087fc55acb94ef4fca0d998c504f2efac41f  yt-dlp-2024.08.06.tar.gz
"
