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

_realname=youtube-dl
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2021.06.06
pkgrel=1
pkgdesc="A command-line program to download videos from YouTube.com and a few more sites (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://youtube-dl.org"
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-setuptools")
optdepends=("${MINGW_PACKAGE_PREFIX}-ffmpeg: for video post-processing")
            #'rtmpdump: for rtmp streams support'
            #'atomicparsley: for embedding thumbnails into m4a files'
            #'python-pycryptodome: for hlsnative downloader'
source=("https://github.com/ytdl-org/${_realname}/releases/download/${pkgver}/${_realname}-${pkgver}.tar.gz"{,.sig})
sha256sums=('3ccb0e4db9fd172338ed1c32bae0be2f716458dca4143e55732ff55260b20ac3'
            'SKIP')
validpgpkeys=('ED7F5BF46B3BBED81C87368E2C393E0F18A9236D') # Sergey M. <dstftw@gmail.com>

build() {
  cd "${srcdir}/${_realname}"
  ${MINGW_PREFIX}/bin/python setup.py --quiet build
}

package() {
  cd "${srcdir}/${_realname}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=;--install-purelib=;--install-data=" \
    ${MINGW_PREFIX}/bin/python setup.py --quiet install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1

  PREFIX_WIN=$(cygpath -m ${MINGW_PREFIX})
  sed -s "s|${PREFIX_WIN}/bin/||g" \
    -i "${pkgdir}${MINGW_PREFIX}/bin/youtube-dl-script.py"

  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
