Example #1
0
def loading(x='', y=False):
    global a
    if os.name == 'nt':
        print(x, end='', flush=True) if x != '' else None
    else:
        if y:
            a = pro(target=lod, args=(x, ))
            a.start()
        else:
            a.kill()
Example #2
0
def dl():
    con = False
    idih = input('url: ')
    if idih == '': return
    cls()
    a = pro(target=lod, args=('getting information',))
    a.start()
    try:
        info = req(f'https://www.youtube.com/oembed?url={idih}')
    except Exception as exc:
        a.kill()
        print()
        if 'code' in dir(exc):
            print(f'{exc.code} {exc.msg}')
        else:
            print(exc)
        return

    opt = {'quiet' : True}
    quest = ytdl(opt).extract_info(f'{idih}', download=False)
    title = quest['title']
    form = '251' if tipe == 'mp3' else lsform[bit]
    for x in quest['formats']:
        if x['format_id'] == form:
            url = x['url']
            break

    if os.path.exists(f'{dor}/{title}.{tipe}'):
        a.kill()
        ask = input(f'\n{title} exist\nLanjut?[y/n] ')
        if ask not in ('Y','y'):
            return
        else:
            os.remove(f'{dor}/{title}.{tipe}')

    elif os.path.exists(f'.{title}.download'):
        a.kill()
        ask = input('\nMau melanjutkan unduhan yang sudah ada?[y/n] ')
        if ask in ('y','Y'):
            con = True

    width = os.get_terminal_size().columns
    open('.0.jpg','wb').write(req(f'https://i.ytimg.com/vi/{quest["id"]}/0.jpg').read())
    if con:
        hed = Request(url)
        pan = len(open(f'.{title}.download', 'rb').read())
        hed.add_header('Range', f'bytes={pan}-')
        resp = req(hed)
        bytesdone = pan
        total = pan
    else:
        resp = req(url)
        bytesdone = 0
        total = 0
    total += int(resp.info()['Content-Length'].strip())
    chunksize, t0 = 16384, time.time()
    outfh = open(f'.{title}.download', 'ab')
    a.kill(); cls()
    open(f'logs/{quest["title"]}.txt','w').write(f'''{"Information".center(width,"=")}
Uploader: {quest["uploader"]}
Title: {quest["title"]}
Thumbnail: https://i.ytimg.com/vi/{quest["id"]}/0.jpg
Description:
{quest["description"]}
{"="*width}''')
    print('\r'+open(f'logs/{quest["title"]}.txt','r').read())
    print(f'{w[1]}Information saved to logs/{quest["title"]}.txt\n{w[5]}Downloading: {title} ({size(total)})')
    while True:
        chunk = resp.read(chunksize)
        outfh.write(chunk)
        elapsed = time.time() - t0
        bytesdone += len(chunk)
        rate = 0
        if elapsed != 0:
            rate = (bytesdone / 1024) / elapsed
        if rate:
            eta = (total - bytesdone) / (rate * 1024)
        else:
            eta = 0
        if not chunk:
            outfh.close()
            break
        print(f'\r{" "*(width)}', end='')
        print('\r{2}[{0}{1}{2}] [{0}{3:.2%}{2}] [{0}{4:4.0f} kbps{2}] [{0}{5:.0f} secs{2}]'.format(w[0], size(bytesdone), w[2], bytesdone * 1.0 / total, rate, eta),end='', flush=True)
    print()
    a = pro(target=lod, args=('menyelesaikan',)); a.start()
    if tipe == 'mp3':
        os.system(f'ffmpeg -nostats -loglevel 0 -i "{outfh.name}" -vn -ab {bit}k -ar 48000 ".out.mp3"; ffmpeg -nostats -loglevel 0 -i ".out.mp3" -i .0.jpg -map 1:0 -map 0:0 -c:a copy -c:v copy -id3v2_version 3 "{dor}/{title}.mp3"; rm .0.jpg "{outfh.name}" ".out.mp3"')
    else:
        open(f'.{title}.audio','wb').write(req(quest['requested_formats'][1]['url']).read())
        os.system(f'ffmpeg -nostats -loglevel 0 -i "{outfh.name}" -i ".{title}.audio" -c:v copy -map 0:v:0 -map 1:a:0 -b:a 320k "{dor}/{title}.mp4"; rm .0.jpg ".{title}.audio" "{outfh.name}"')
    a.kill(); cls()
    print(f'Downloaded: {dor}/{title}.{tipe}')
Example #3
0
    print('\n'*30)
    os.system('clear')
    print(f'''{w[1]} /$$     /$$ /$$     /$$$$$$$           
|  $$   /$$/| $$    | $$__  $$          
 \  $$ /$$//$$$$$$  | $$  \ $$ /$$   /$$
  \  $$$$/|_  $$_/  | $$$$$$$/| $$  | $$
   \  $$/   | $$    | $$____/ | $$  | $$
{w[0]}    | $$    | $$ /$$| $$      | $$  | $$
    | $$    |  $$$$/| $$      |  $$$$$$$
    |__/     \___/  |__/       \____  $$
                               /$$  | $$
                              |  $$$$$$/
                               \______/ ''')

cls()
a = pro(target=lod, args=('Loading',))
a.start()
try:
    import youtube_dl, readline, json, re, sys
    from urllib.request import urlopen as req, Request

except Exception as ex:
    a.kill()
    exit(f"Module '{ex.name}' belum terinstall\nsilahkan install dengan command:\n\t[sudo] python3 -m pip install {ex.name}")

ytdl = youtube_dl.YoutubeDL

readline.set_history_length(1024)

cmd = (
        'q', 'exit',
Example #4
0

def op():
    print('Load the web', end='')
    while True:
        for x in range(6):
            print('.', end='', flush=True)
            sleep(0.3)
        print('\b ', end='')
        for x in range(5):
            print('\b\b', end=' ', flush=True)
            sleep(0.1)
        print('\b', end='')


p = pro(target=op)
p.start()
import requests, os
from bs4 import BeautifulSoup as be
uwu = os.getcwd().split('/')
if 'figlet' not in uwu:
    os.chdir('/data/data/com.termux/files/usr/share/figlet')
r = be(requests.get('http://www.figlet.org/fontdb.cgi').text, 'html.parser')
r = [x.text + '.flf' for x in r.find_all('a') if 'flf' in x['href']]
ls = os.listdir()


def down(x):
    if x in ls:
        pass
    else:
Example #5
0
#!/usr/bin/env python
# -*-coding:utf-8 -*-

from multiprocessing import Process as pro
import os


#子进程的方法
def run_sub_process(name):
    print("我是子进程:%s 进程号 %s " % (name, os.getpid()))


if __name__ == "__main__":
    print('父进程是 %s.' % os.getpid())
    p = pro(target=run_sub_process, args=('子进程0', ))
    p2 = pro(target=run_sub_process, args=('子进程1', ))
    p2.start()
    p2.join()
    p.start()
    p.join()

    print('Child process end.')