Beispiel #1
0
    def update(self, amountRead):
        currentTime = time.time()
        elapsedTime = currentTime - self.startTime

        self.readSoFar = self.readSoFar + amountRead

        if elapsedTime > 0:
            speed = self.readSoFar / elapsedTime
        else:
            speed = float("inf")

        terminalWidth = Console.terminal_width()

        nameWidth = terminalWidth - 33

        status = "{0:{nameWidth}}: {1:>6}B {2:>6}B/s".format(self.name[:nameWidth], format_number(self.readSoFar), format_number(speed), nameWidth = nameWidth)

        if self.estimatedSize > 0:
            self.readSoFar = min(self.estimatedSize, self.readSoFar)
            pct = self.readSoFar / self.estimatedSize
            timeToGo = elapsedTime * (1 - pct) / pct
            output = " {0:4.0%} {1:>6}".format(pct, format_time(timeToGo))
            status = status + output

        print("\r", status, end = "")
Beispiel #2
0
def displayOrGet(item, nolist, info, get, options, grabber, fmt):
    if info:
        width = Console.terminal_width()
        item.display(width)
    elif not nolist:
        # this is list
        print(item.short(fmt))

    if get:
        try:
            item.download(Config.programFolder, options, grabber)
        except Exception as e:
            print("Exception: {0}".format(e))
            print()
Beispiel #3
0
def displayOrGet(item, nolist, info, get, options, grabber, fmt):
    if info:
        width = Console.terminal_width()
        item.display(width)
    elif not nolist:
        # this is list
        print(item.short(fmt))

    if get:
        try:
            item.download(Config.programFolder, options, grabber)
        except Exception as e:
            print("Exception: {0}".format(e))
            print()
Beispiel #4
0
def process(args):
    db = {}

    proxy = None

    if args.location:
        Config.programFolder = Config.createFolder(args.location)

    if args.tor:
        # we use privoxy to access tor
        Utils.setTorExitNodes(args.tor, args.tor_pass)
        proxy = { "http"  : "http://127.0.0.1:8118",
                  "https" : "http://127.0.0.1:8118" }
    else:
        if args.proxy:
            proxy = { "http"  : args.proxy,
                      "https" : args.proxy }

    proxyHandler = urllib.request.ProxyHandler(proxy)

    grabber = urllib.request.build_opener(proxyHandler)
    # we still need to install the global one, as sometimes we cannot pass in a new one
    # (m3u8 and urlretrieve)
    urllib.request.install_opener(grabber)

    grabberForDownload = None
    if args.tor and args.tor_only_metadata:
        # we do not want to use to for the actual download
        # only for the metadata
        grabberForDownload = urllib.request.build_opener()
    else:
        # use the same opener everywhere
        grabberForDownload = grabber

    if args.ip:
        width = Console.terminal_width()
        Info.display(grabber, width, args.tor)
        return

    if args.page:
        Page.download(db, grabber, args.page, args.download)

    if args.ondemand:
        Demand.download(db, grabber, args.download)

    if args.tg:
        TG.download(db, grabber, args.download)

    if args.junior:
        Junior.download(db, grabber, args.download)

    if args.search:
        Search.download(db, grabber, args.search, args.download)

    if args.follow:
        follows = args.follow
        while follows:
            subset = {}
            find(db, follows[0], args.re, subset)
            # continue follow calculation
            db = {}
            for p in subset.values():
                p.follow(db, args.download)
            follows = follows[1:] # continue with one element less

    if args.replay:
        Replay.download(db, grabber, args.download)

    if args.pluzz:
        Pluzz.download(db, grabber, args.download)

    if args.tf1:
        TF1.download(db, grabber, args.download)

    if args.m6:
        M6.download(db, grabber, args.download)

    if args.mediaset:
        Mediaset.download(db, grabber, args.download, "mediaset")

    if args.tg5:
        Mediaset.download(db, grabber, args.download, "tg5")

    if args.item:
        p = Item.Demand(grabber, args.item, args.download, len(db))
        db[p.pid] = p

    if args.m3u8:
        p = Playlist.process(grabber, args.m3u8, len(db))
        db[p.pid] = p

    if args.pid:
        subset = {}
        for pid in args.pid:
            find(db, pid, args.re, subset)
    else:
        subset = db

    if args.date:
        subset = filterByDate(subset, args.date)

    if args.channel:
        subset = filterByChannel(subset, args.channel)

    # we should only copy over
    # format, bwidth, overwrite, quiet
    options = args

    listDisplayOrGet(subset, args.nolist, args.info, args.get, options, grabberForDownload)
Beispiel #5
0
def process(args):
    db = {}

    proxy = None

    if args.location:
        Config.programFolder = Config.createFolder(args.location)

    if args.tor:
        # we use privoxy to access tor
        Utils.setTorExitNodes(args.tor, args.tor_pass)
        proxy = {
            "http": "http://127.0.0.1:8118",
            "https": "http://127.0.0.1:8118"
        }
    else:
        if args.proxy:
            proxy = {"http": args.proxy, "https": args.proxy}

    proxyHandler = urllib.request.ProxyHandler(proxy)

    grabber = urllib.request.build_opener(proxyHandler)
    # we still need to install the global one, as sometimes we cannot pass in a new one
    # (m3u8 and urlretrieve)
    urllib.request.install_opener(grabber)

    grabberForDownload = None
    if args.tor and args.tor_only_metadata:
        # we do not want to use to for the actual download
        # only for the metadata
        grabberForDownload = urllib.request.build_opener()
    else:
        # use the same opener everywhere
        grabberForDownload = grabber

    if args.ip:
        width = Console.terminal_width()
        Info.display(grabber, width, args.tor)
        return

    if args.page:
        Page.download(db, grabber, args.page, args.download)

    if args.ondemand:
        Demand.download(db, grabber, args.download)

    if args.tg:
        TG.download(db, grabber, args.download)

    if args.junior:
        Junior.download(db, grabber, args.download)

    if args.search:
        Search.download(db, grabber, args.search, args.download)

    if args.follow:
        follows = args.follow
        while follows:
            subset = {}
            find(db, follows[0], args.re, subset)
            # continue follow calculation
            db = {}
            for p in subset.values():
                p.follow(db, args.download)
            follows = follows[1:]  # continue with one element less

    if args.replay:
        Replay.download(db, grabber, args.download)

    if args.pluzz:
        Pluzz.download(db, grabber, args.download)

    if args.tf1:
        TF1.download(db, grabber, args.download)

    if args.m6:
        M6.download(db, grabber, args.download)

    if args.mediaset:
        Mediaset.download(db, grabber, args.download, "mediaset")

    if args.tg5:
        Mediaset.download(db, grabber, args.download, "tg5")

    if args.item:
        p = Item.Demand(grabber, args.item, args.download, len(db))
        db[p.pid] = p

    if args.m3u8:
        p = Playlist.process(grabber, args.m3u8, len(db))
        db[p.pid] = p

    if args.pid:
        subset = {}
        for pid in args.pid:
            find(db, pid, args.re, subset)
    else:
        subset = db

    if args.date:
        subset = filterByDate(subset, args.date)

    if args.channel:
        subset = filterByChannel(subset, args.channel)

    # we should only copy over
    # format, bwidth, overwrite, quiet
    options = args

    listDisplayOrGet(subset, args.nolist, args.info, args.get, options,
                     grabberForDownload)