# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=yt-dlp
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2025.12.08
pkgrel=1
pkgdesc="A youtube-dl fork with additional features and fixes (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: yt-dlp'
  'gentoo: net-misc/yt-dlp'
  'purl: pkg:pypi/yt-dlp'
)
url='https://github.com/yt-dlp/yt-dlp/'
license=('spdx:Unlicense')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python-certifi"
  "${MINGW_PACKAGE_PREFIX}-python-websockets"
  "${MINGW_PACKAGE_PREFIX}-python-brotli"
  "${MINGW_PACKAGE_PREFIX}-python-mutagen"
  "${MINGW_PACKAGE_PREFIX}-python-urllib3"
  "${MINGW_PACKAGE_PREFIX}-python-pycryptodomex"
  "${MINGW_PACKAGE_PREFIX}-python-requests"
)
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-hatchling"
             "${MINGW_PACKAGE_PREFIX}-python-installer")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest")
optdepends=("${MINGW_PACKAGE_PREFIX}-aria2: for using aria2 as external downloader"
            "${MINGW_PACKAGE_PREFIX}-ffmpeg: for video post-processing"
            "${MINGW_PACKAGE_PREFIX}-yt-dlp-ejs: JavaScript runtime support")
options=('!strip')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/yt-dlp/yt-dlp/releases/download/${pkgver}/yt-dlp.tar.gz")
sha256sums=('9814ae7dd4118a80a6104399d4984e355d2a71f78e6bbc48137a5b299eddcbaf')

build() {
  cp -r "${_realname}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  python -m pytest || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
