#!/usr/bin/make -f
+
+#export DH_VERBOSE = 1
+export PYBUILD_NAME = youtube_dl
+export PATH := $(CURDIR)/debian/utils:$(PATH)
+
 %:
-       dh $@ --with python2 --buildsystem=python_distutils \
-               --with bash-completion
+       dh $@ --with python3 --buildsystem=pybuild --with bash-completion
 
 override_dh_auto_configure:
        PREFIX=/usr SYSCONFDIR=/etc make
-       mv Makefile Makefile.inactive
        rm youtube-dl
 
 override_dh_clean:
-       test -f Makefile || mv Makefile.inactive Makefile
        make clean
        dh_clean
 
 override_dh_auto_test:
+ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
+       make offlinetest PYTHON=python3
+endif