# Path: post.py
# def post_file(filename, dest_uri):
#     h, p, dst = make_host_port(dest_uri)
#     dst = quote(unquote(dst))
#     conn = HTTPConnection(h, p)
#     if not py3:
#         if isinstance(filename, unicode):
#             filename = filename.encode("utf8")
#     #post_one(filename, conn, quote(unquote(dst)))
#     post_one(filename, conn, dst, "uploaded ")
# 
# Path: merge.py
# def run1(name, cnt):
# def merge1(name, ext, cnt):
# def find_tool():
# def merge(name, ext, cnt, clean=False, ists=False):
# def waitp(p, timeout=0):
# def m3u8_merge(url, outfn, slow=False):
# def usage():
# def main():


import os
import re
import ssl
import sys
import zlib
import argparse
import subprocess
    import http.client as httplib
    import urllib.parse as urlparse
    import httplib
    import urlparse
import ssl
from time import sleep
    from queue import Queue
    from urllib.parse import quote, unquote
    from urllib.request import HTTPCookieProcessor, ProxyHandler
    from urllib.request import HTTPRedirectHandler, HTTPSHandler
    from urllib.request import Request
    from urllib.request import build_opener
    from urllib import quote, unquote
    from Queue import Queue
    from urllib2 import HTTPCookieProcessor, ProxyHandler
    from urllib2 import HTTPRedirectHandler, HTTPSHandler
    from urllib2 import Request
    from urllib2 import build_opener
from post import post_file
from merge import merge, tss, m3u8_merge
        from you_get.common import download_urls
    from threading import Thread
        echo("unum =", unum)
        for t, u in dats:
            ret = self.wget_one_url(t, u, unum)
            if ret == 0:
                cnt += 1
                echo("progress = %.1f%%" % (100.0 * cnt / unum))
        if cnt == unum:
            echo("progress = 100%")
            echo("merge")
            self.avconv_m3u8(title, "mp4", fm3u8)
        else:
            echo("some download failed %d != %d, skip merge" % (cnt, unum))

    def download_m3u8(self, title, url):
        outfn = self.get_outfn(title, "mp4")
        if not outfn:
            return    # file exists
        echo("download", outfn)
        #if self.skim_output:
        #    self.wget_m3u8(title, url)
        #else:
        #    self.avconv_m3u8(title, "mp4", url)
        if self.parsed_args.avconv_m3u8:
            self.avconv_m3u8(title, "mp4", url)
        else:
            self.wget_m3u8(title, url)
        return outfn

    def avconv_m3u8(self, title, ext, url):
        outfn = self.get_outfn(title, ext)

# Path: post.py
# def post_file(filename, dest_uri):
#     h, p, dst = make_host_port(dest_uri)
#     dst = quote(unquote(dst))
#     conn = HTTPConnection(h, p)
#     if not py3:
#         if isinstance(filename, unicode):
#             filename = filename.encode("utf8")
#     #post_one(filename, conn, quote(unquote(dst)))
#     post_one(filename, conn, dst, "uploaded ")
# 
# Path: merge.py
# def run1(name, cnt):
# def merge1(name, ext, cnt):
# def find_tool():
# def merge(name, ext, cnt, clean=False, ists=False):
# def waitp(p, timeout=0):
# def m3u8_merge(url, outfn, slow=False):
# def usage():
# def main():


# Path: comm.py
import os
import re
import ssl
import sys
import zlib
import argparse
import subprocess
    import http.client as httplib
    import urllib.parse as urlparse
    import httplib
    import urlparse
import ssl
from time import sleep
    from queue import Queue
    from urllib.parse import quote, unquote
    from urllib.request import HTTPCookieProcessor, ProxyHandler
    from urllib.request import HTTPRedirectHandler, HTTPSHandler
    from urllib.request import Request
    from urllib.request import build_opener
    from urllib import quote, unquote
    from Queue import Queue
    from urllib2 import HTTPCookieProcessor, ProxyHandler
    from urllib2 import HTTPRedirectHandler, HTTPSHandler
    from urllib2 import Request
    from urllib2 import build_opener
from post import post_file
from merge import merge, tss, m3u8_merge
        from you_get.common import download_urls
    from threading import Thread

        echo("unum =", unum)
        for t, u in dats:
            ret = self.wget_one_url(t, u, unum)
            if ret == 0:
                cnt += 1
                echo("progress = %.1f%%" % (100.0 * cnt / unum))
        if cnt == unum:
            echo("progress = 100%")
            echo("merge")
            self.avconv_m3u8(title, "mp4", fm3u8)
        else:
            echo("some download failed %d != %d, skip merge" % (cnt, unum))

    def download_m3u8(self, title, url):
        outfn = self.get_outfn(title, "mp4")
        if not outfn:
            return    # file exists
        echo("download", outfn)
        #if self.skim_output:
        #    self.wget_m3u8(title, url)
        #else:
        #    self.avconv_m3u8(title, "mp4", url)
        if self.parsed_args.avconv_m3u8:
            self.avconv_m3u8(title, "mp4", url)
        else:
            self.wget_m3u8(title, url)
        return outfn

    def avconv_m3u8(self, title, ext, url):
        outfn = self.get_outfn(title, ext)

        m3u8_merge(url, outfn, self.m3u8_slow_merge)