# -*- 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: Portfile 120238 2014-05-20 04:46:04Z ryandesign@macports.org $

PortSystem          1.0

name                youtube-dl
version             2014.05.19
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  06a994a353028a4d634b1e1de45a1106f9d824bb \
                    sha256  da50c1f56e07e1c9c36a83f045a97d075fbd115023b813585ce29ad9b7f31e68

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 the original mtime of update.py (changed by the patch) so that `make` doesn't try to regenerate the documentation with `pandoc`.
    file mtime ${worksrcpath}/youtube_dl/update.py [file mtime ${worksrcpath}/youtube_dl/update.py.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 python27 conflicts python33 python34 description {Use Python 2.7} {
    depends_run-append  port:python27
    configure.python    ${prefix}/bin/python2.7
}

variant python33 conflicts python27 python34 description {Use Python 3.3} {
    depends_run-append  port:python33
    configure.python    ${prefix}/bin/python3.3
}

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

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

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