%define pypi_name	youtube_dl

%if 0%{?mageia}
%define dist mgr8
%endif

%if 0%{!?mkrel:1}
%define mkrel(c)  %{1}%{?dist}
%endif

%if 0%{?fedora}
%define has_pandoc 1
%endif

Name:		youtube-dl
Version:	2025.02.07
Release:	%mkrel 1.1
Summary:	Small command-line program to download videos from YouTube
License:	Public Domain
Group:		Video/Players
URL:		https://ytdl-org.github.io/youtube-dl/
# Done on the 2023.06.17 after bug https://github.com/ytdl-org/youtube-dl/issues/32314 is fixed
# Memo: git archive --output=./master.tar.gz --format=tar.gz --prefix=ytdl-org-youtube-dl-a96a45b/ HEAD
Source0:	https://github.com/ytdl-org/ytdl-nightly/releases/download/%{version}/%{name}-%{version}.tar.gz
#Source1:	https://yt-dl.org/downloads/%%{version}/%%{name}-%%{version}.tar.gz.sig
BuildArch:	noarch
BuildRequires:  make
BuildRequires:	zip
BuildRequires:	pkgconfig(python3)
BuildRequires:  python3dist(pip)
BuildRequires:	python3dist(setuptools)
BuildRequires:  python3dist(wheel)
BuildRequires:  rpm_macro(pyproject_wheel)
%if 0%{?has_pandoc}
BuildRequires:  pandoc
%endif
Requires:	python3
# MGA#18464 - cclive crashes
Obsoletes:	cclive < 0.9.4

%description
Small command-line program to download videos from YouTube.

%package -n	python3-%{name}
Summary:	Python 3 bindings for %{name}
Group:		Development/Python
BuildArch:	noarch
%{?python_provide:%python_provide python3-%{name}}

%description -n	python3-%{name}
This is the Python 3 bindings for %{name}.

%prep
%autosetup -n %{name}

# remove pre-built file
rm -f bin/*

%if 0%{!?has_pandoc}
sed -i -e 's|pandoc |#pandoc |g'
%endif

%build
%pyproject_wheel

%install
%pyproject_install
%pyproject_save_files %{pypi_name}

%make_install PREFIX="%{_prefix}" MANDIR="%{_mandir}"

# force the youtube-dl binary to use python 3 environment by default
sed -i -e 's,#!/usr/bin/env python,#!/usr/bin/python3,' %{buildroot}%{_bindir}/%{name}

#rm -rf %{buildroot}%{_prefix}/etc
install -D -m 0644 LICENSE  %{buildroot}%{_datadir}/doc/youtube_dl/LICENSE

%files
%license %{_datadir}/doc/youtube_dl/LICENSE
%attr(0755,root,root) %{_bindir}/%{name}
%{_sysconfdir}/bash_completion.d/
%{_sysconfdir}/fish/completions/youtube-dl.fish
%{_prefix}%{_sysconfdir}/bash_completion.d/
%{_prefix}%{_sysconfdir}/fish/completions/youtube-dl.fish
%{_datadir}/zsh/site-functions/_youtube-dl
%{_docdir}/%{pypi_name}/README.txt
%{_mandir}/man1/%{name}.1.*

%files -n python3-%{name} -f %{pyproject_files}