# Path: comm.py
# def start(kls):
#     global DEBUG
#     p = argparse.ArgumentParser(description='Download Web Movie')
#     #, add_help=False)
#     p.add_argument('url', metavar='URL', type=str, action='store',
#                    help='url of movie')
#     p.add_argument('-i', '--info_only', action='store_true',
#                    help='show information only')
#     p.add_argument('-o', '--output', metavar='dir', action='store',
#                    #help='where download file go, dir or url to post',
#                    help='where download file go, dir',
#                    default='.')
#     p.add_argument('-n', '--norm_title', action='store_true',
#                    help='normalize title')
#     p.add_argument('-p', '--playlist_only', action='store_true',
#                    help='try playlist only')
#     p.add_argument('-P', '--not_playlist', action='store_true',
#                    help='not try playlist')
#     p.add_argument('--playlist_top', type=int, metavar='#', action='store',
#                    help='only get top # of playlist', default=0)
#     p.add_argument('--playlist_skip', type=int, metavar='#', action='store',
#                    help='skip # in playlist', default=0)
#     p.add_argument('--title', metavar='TITLE', action='store',
#                    help='movie name if you want to define it',
#                    default=UTITLE)
#     p.add_argument('--post_uri', metavar='URI', action='store',
#                    help='uri to post downloaded file')
#     #p.add_argument('--wget_skip', type=int, metavar='#', action='store',
#     #               help='wget skip # urls in list', default=0)
#     p.add_argument('--align_num', type=int, metavar='#', action='store',
#                    help='align number', default=0)
#     p.add_argument('--cookie', metavar='COOKIE_STR', action='store',
#                    help='input cookie for login', default='')
#     p.add_argument('--user_agent', metavar='USER_AGENT', action='store',
#                    help='pair with cookie for login', default='')
#     p.add_argument('--no_merge', action='store_true',
#                    help='skip merge video pieces')
#     p.add_argument('--no_check_certificate', action='store_true',
#                    help='not check https certificate')
#     p.add_argument('--no_proxy', action='store_true',
#                    help='disable auto proxy')
#     p.add_argument('--skim_output', action='store_true',
#                    help='only output data for WUI')
#     p.add_argument('--avconv_m3u8', action='store_true',
#                    help='download m3u8 by avconv')
#     p.add_argument('--debug', action='store_true',
#                    help='display debug message')
#     p.add_argument('--testing', action='store_true',
#                    help='do testing')
#     args = p.parse_args()
#     DEBUG = args.debug
#     debug(args)
# 
#     if not getattr(kls, 'query_info', None):
#         kls = kls(args.url)
#         if kls is None:
#             echo("Not support ", args.url)
#             sys.exit(1)
#     if args.title == "":
#         args.title = UTITLE
#     if py3:
#         kls.title = args.title
#     else:
#         kls.title = args.title.decode('utf8')
#     kls.out_dir = args.output
#     kls.no_merge = args.no_merge
#     kls.no_proxy = args.no_proxy
#     kls.info_only = args.info_only
#     kls.align_num = args.align_num
#     kls.login_cookie = args.cookie
#     kls.login_agent = args.user_agent
#     DWM.no_check_certificate = args.no_check_certificate
#     #if args.no_check_certificate:
#     if kls.no_check_certificate:
#         ssl._create_default_https_context = ssl._create_unverified_context
#     kls.download_urls = DWM.wget_urls
#     kls.skim_output = args.skim_output
#     k = kls()
#     k.parsed_args = args
#     if args.testing:
#         DEBUG = True
#         k.test(args)
#     else:
#         run(k, args)
# 
# def echo(*args):
#     sys.stdout.write(" ".join(map(str, args)) + "\n")
#     sys.stdout.flush()


import os
import re
import sys
import imp
from comm import start, echo
#! /usr/bin/python -B


# python -B
sys.dont_write_bytecode = True


def find_kls(url):
    p = os.path.dirname(sys.argv[0])
    n = os.path.basename(sys.argv[0])
    if not p:
        p = "."
    dwmkls = re.compile("^class\s+(\S+)\s*\(DWM\)\:", re.M)
    for fn in os.listdir(p):
        if not fn.endswith(".py") or fn == n:
            continue
        ret = dwmkls.findall(open(fn).read())
        if not ret:
            continue
        name = fn[:-3]
        try:
            m = imp.load_source(name, fn)
        except Exception as e:

# Path: comm.py
# def start(kls):
#     global DEBUG
#     p = argparse.ArgumentParser(description='Download Web Movie')
#     #, add_help=False)
#     p.add_argument('url', metavar='URL', type=str, action='store',
#                    help='url of movie')
#     p.add_argument('-i', '--info_only', action='store_true',
#                    help='show information only')
#     p.add_argument('-o', '--output', metavar='dir', action='store',
#                    #help='where download file go, dir or url to post',
#                    help='where download file go, dir',
#                    default='.')
#     p.add_argument('-n', '--norm_title', action='store_true',
#                    help='normalize title')
#     p.add_argument('-p', '--playlist_only', action='store_true',
#                    help='try playlist only')
#     p.add_argument('-P', '--not_playlist', action='store_true',
#                    help='not try playlist')
#     p.add_argument('--playlist_top', type=int, metavar='#', action='store',
#                    help='only get top # of playlist', default=0)
#     p.add_argument('--playlist_skip', type=int, metavar='#', action='store',
#                    help='skip # in playlist', default=0)
#     p.add_argument('--title', metavar='TITLE', action='store',
#                    help='movie name if you want to define it',
#                    default=UTITLE)
#     p.add_argument('--post_uri', metavar='URI', action='store',
#                    help='uri to post downloaded file')
#     #p.add_argument('--wget_skip', type=int, metavar='#', action='store',
#     #               help='wget skip # urls in list', default=0)
#     p.add_argument('--align_num', type=int, metavar='#', action='store',
#                    help='align number', default=0)
#     p.add_argument('--cookie', metavar='COOKIE_STR', action='store',
#                    help='input cookie for login', default='')
#     p.add_argument('--user_agent', metavar='USER_AGENT', action='store',
#                    help='pair with cookie for login', default='')
#     p.add_argument('--no_merge', action='store_true',
#                    help='skip merge video pieces')
#     p.add_argument('--no_check_certificate', action='store_true',
#                    help='not check https certificate')
#     p.add_argument('--no_proxy', action='store_true',
#                    help='disable auto proxy')
#     p.add_argument('--skim_output', action='store_true',
#                    help='only output data for WUI')
#     p.add_argument('--avconv_m3u8', action='store_true',
#                    help='download m3u8 by avconv')
#     p.add_argument('--debug', action='store_true',
#                    help='display debug message')
#     p.add_argument('--testing', action='store_true',
#                    help='do testing')
#     args = p.parse_args()
#     DEBUG = args.debug
#     debug(args)
# 
#     if not getattr(kls, 'query_info', None):
#         kls = kls(args.url)
#         if kls is None:
#             echo("Not support ", args.url)
#             sys.exit(1)
#     if args.title == "":
#         args.title = UTITLE
#     if py3:
#         kls.title = args.title
#     else:
#         kls.title = args.title.decode('utf8')
#     kls.out_dir = args.output
#     kls.no_merge = args.no_merge
#     kls.no_proxy = args.no_proxy
#     kls.info_only = args.info_only
#     kls.align_num = args.align_num
#     kls.login_cookie = args.cookie
#     kls.login_agent = args.user_agent
#     DWM.no_check_certificate = args.no_check_certificate
#     #if args.no_check_certificate:
#     if kls.no_check_certificate:
#         ssl._create_default_https_context = ssl._create_unverified_context
#     kls.download_urls = DWM.wget_urls
#     kls.skim_output = args.skim_output
#     k = kls()
#     k.parsed_args = args
#     if args.testing:
#         DEBUG = True
#         k.test(args)
#     else:
#         run(k, args)
# 
# def echo(*args):
#     sys.stdout.write(" ".join(map(str, args)) + "\n")
#     sys.stdout.flush()


# Path: dwm.py
import os
import re
import sys
import imp
from comm import start, echo

#! /usr/bin/python -B


# python -B
sys.dont_write_bytecode = True


def find_kls(url):
    p = os.path.dirname(sys.argv[0])
    n = os.path.basename(sys.argv[0])
    if not p:
        p = "."
    dwmkls = re.compile("^class\s+(\S+)\s*\(DWM\)\:", re.M)
    for fn in os.listdir(p):
        if not fn.endswith(".py") or fn == n:
            continue
        ret = dwmkls.findall(open(fn).read())
        if not ret:
            continue
        name = fn[:-3]
        try:
            m = imp.load_source(name, fn)
        except Exception as e:

            echo(name, e)