# Contributor: Dmitry Zakharchenko <dmitz@disroot.org>
# Maintainer: Dmitry Zakharchenko <dmitz@disroot.org>
pkgname=subliminal
pkgver=2.2.1
pkgrel=0
pkgdesc="Python library and CLI tool for searching and downloading subtitles"
url="https://github.com/Diaoul/subliminal"
arch="noarch"
license="MIT"
depends="
		py3-babelfish
		py3-beautifulsoup4
		py3-chardet
		py3-click
		py3-click-option-group
		py3-dogpile.cache
		py3-enzyme
		py3-guessit
		py3-platformdirs
		py3-pysubs2
		py3-srt
		py3-rarfile
		py3-requests
		py3-setuptools
		py3-tomli
		py3-stevedore
		"
makedepends="py3-setuptools py3-gpep517"
checkdepends="python3-dev py3-pytest py3-pytest-runner libarchive-tools py3-vcrpy py3-sympy"
subpackages="$pkgname-pyc"
source="$pkgname-$pkgver.tar.gz::https://github.com/Diaoul/subliminal/archive/$pkgver.tar.gz
	https://downloads.sourceforge.net/project/matroska/test_files/matroska_test_w1_1.zip

	no-rar.patch
	"

prepare() {
	default_prepare
	mkdir -p "$builddir"/tests/data/mkv
	mv "$srcdir"/test*.mkv "$builddir"/tests/data/mkv
}

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

check() {
	case "$CARCH" in
	s390x)
		export PYTEST_ADDOPTS="
			--deselect tests/test_subtitle.py::test_fix_line_ending_chinese_characters
		"
		;;
	esac

	python3 -m venv --clear --without-pip --system-site-packages .testenv
	gpep517 install-wheel --destdir .testenv --prefix '' .dist/*.whl
	.testenv/bin/python3 -m pytest \
		--deselect tests/test_core.py::test_refine_video_metadata
	# https://github.com/Diaoul/subliminal/issues/1135
}

package() {
	gpep517 install-wheel --destdir "$pkgdir" \
		.dist/*.whl
}

sha512sums="
4e59ccfe42419bb33df395aad6c2255ad03cfe7311fc754ea591be7c9e33ef5cc3e980a1da2839afe79e3b22024b3e7b458b03b4e6270ea8bcadc0337d7e37bf  subliminal-2.2.1.tar.gz
f170a8e83dab15228f992b3692330163da2402b8e436c7fa195ac1ecc06cf1eaf1a48d8c99a85c031122c158c2d4006023aae75d5b7805385ba25a6d601cb78f  matroska_test_w1_1.zip
53cb262f32becddf9ba423dfbceaa6e73eec0f81f8640c7ffef7df642495983a672f44acae28203ff876149b0c3273574081cb45525c0b03446804886ddd6535  no-rar.patch
"