# -*- 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
# $Id$

PortSystem          1.0

name                youtube-dl
version             2016.10.26
categories          net
platforms           darwin
maintainers         ryandesign openmaintainer
supported_archs     noarch
license             public-domain

description         command-line program to download videos from YouTube.com and other sites

long_description    ${name} is a small ${description}.

homepage            http://rg3.github.com/youtube-dl/
master_sites        http://youtube-dl.org/downloads/${version}

checksums           rmd160  d4b7a74c8bdd46d0fbbbecab0a1b2543f7f5999f \
                    sha256  df9f9848198ef225bc351db016d54843fb93252704a786e7e34418f60617b1a5

depends_build       bin:zip:zip

worksrcdir          ${name}

post-extract {
    # Force the script to be regenerated by `make`.
    delete ${worksrcpath}/${name}
}

patchfiles          patch-Makefile.diff \
                    patch-youtube_dl-update.py.diff
patch.args          --backup

post-patch {
    # Restore original mtimes of files changed by the patch so that `make` doesn't try to regenerate the documentation with `pandoc`.
    foreach f {youtube_dl/update.py} {
        file mtime ${worksrcpath}/${f} [file mtime ${worksrcpath}/${f}.orig]
    }
}

use_configure       no

pre-build {
    build.args-append   PYTHON=${configure.python}
}

destroot.args       PREFIX=${prefix} \
                    MANDIR=${prefix}/share/man \
                    SYSCONFDIR=${prefix}/etc

post-destroot {
    set docdir ${prefix}/share/doc/${name}
    xinstall -d ${destroot}${docdir}
    xinstall -m 644 -W ${worksrcpath} LICENSE README.md ${destroot}${docdir}
}

variant ffmpeg description {Add ffmpeg dependency, used to extract audio} {
    depends_run-append  path:bin/ffmpeg:ffmpeg
}

default_variants    +ffmpeg

variant python27 conflicts python34 python35 description {Use Python 2.7} {
    depends_run-append      port:python27
    depends_build-append    port:python27
    configure.python        ${prefix}/bin/python2.7
}

variant python33 requires python34 description {Legacy compatibility variant} {}

variant python34 conflicts python27 python35 description {Use Python 3.4} {
    depends_run-append      port:python34
    depends_build-append    port:python34
    configure.python        ${prefix}/bin/python3.4
}

variant python35 conflicts python27 python34 description {Use Python 3.5} {
    depends_run-append      port:python35
    depends_build-append    port:python35
    configure.python        ${prefix}/bin/python3.5
}

if {![variant_isset python27] && ![variant_isset python34] && ![variant_isset python35]} {
    default_variants +python27
}

livecheck.type      regex
livecheck.url       http://rg3.github.com/youtube-dl/update/versions.json
livecheck.regex     {"latest":\s*"([0-9.]+)"}