# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           github 1.0
PortGroup           python 1.0

# PyPi tarball lacks requirements and fails to build.
github.setup        mps-youtube yewtube 2.12.0 v
revision            0
categories          net multimedia
platforms           {darwin any}
license             GPL-3
maintainers         nomaintainer
description         Terminal-based YouTube player and downloader
long_description    {*}${description}. No Youtube API key required.
checksums           rmd160  2de71190074877ffaa82bd19a3fca8d556121107 \
                    sha256  0a45b09fed598d29275f62847cbb556c948cd46d2b7bb0f6b0996b2ce05b77fe \
                    size    222486
supported_archs     noarch
github.tarball_from archive

set python.version  312

depends_lib-append  port:desktop-file-utils \
                    port:py${python.version}-pylast \
                    port:py${python.version}-pyperclip \
                    port:py${python.version}-requests \
                    port:youtube-search-python \
                    port:yt-dlp

# FIXME: currently only low-res vids will stream.
# Once upstream fixes the problem, add a patch.
# See: https://github.com/mps-youtube/yewtube/issues/942
# Downloading works for full-res normally.
# See also: https://github.com/mps-youtube/yewtube/issues/1275
# And: https://github.com/mps-youtube/yewtube/issues/1298

notes "
Config files are saved in ~/.config/mps-youtube/.\
You may edit `config.json` to set a player of choice,\
and `transcode` to point to ffmpeg executable.
"

set appdir ${prefix}/share/applications

post-destroot {
    xinstall -d ${destroot}${prefix}/bin
    ln -s ${python.prefix}/bin/yt ${destroot}${prefix}/bin/yt
    xinstall -d ${destroot}${appdir}
    xinstall -m 0644 -W ${worksrcpath} yewtube.desktop ${destroot}${appdir}
}

post-activate {
    system "${prefix}/bin/update-desktop-database ${appdir}"
}
