Example #1
0
def main():  ## {{{
    getopts()

    print(Color().heading(title))

    main_items = [
        'single', 'bulk', 'get youtube playlist urls',
        'video available formats', 'help'
    ]
    main_item = fzf(main_items)

    if main_item == 'single':
        total_duration = single()
        print(Color().brown({
            'time': get_datetime('jhms'),
            'total duration': total_duration
        }))
    elif main_item == 'bulk':
        total_duration = bulk()
        append_to_log(
            str({
                'time': get_datetime('jhms'),
                'total duration': total_duration
            }) + '\n')
        print(Color().brown({
            'time': get_datetime('jhms'),
            'total duration': total_duration
        }))
    elif main_item == 'get youtube playlist urls':
        get_youtube_playlist_urls()
    elif main_item == 'video available formats':
        video_available_formats()
    elif main_item == 'help':
        help()
Example #2
0
def single():  ## {{{
    global outputname, attempt, should_break

    prompt('-f', '-u', '-d', '-i', '-c')

    order = {}
    if file_type in ['v', 's', 'vs', 'a', 't']:
        title, uploader, channel, dur, view_count, like_count, dislike_count, ext, outputname, error = Video(
        ).get_info()
        current = Video(order, get_datetime('jhms'), url, title, uploader,
                        channel, dur, view_count, like_count, dislike_count,
                        ext, outputname, error)
    elif file_type == 'o':
        size, raw_size, content_type, last_modified, outputname, error = File(
        ).get_info()
        current = File(order, get_datetime('jhms'), url, size, raw_size,
                       content_type, last_modified, outputname, error)

    outputname = f'{hnd}/{outputname}'
    outputname = if_exists(outputname)
    current.outputname = sub(getenv('HOME'), '~', outputname)

    print(Color().white_dim(display_args))
    print()

    for attempt in attempts:
        should_break = False

        if attempt == 1:
            attempt_message = current.info_dict
        else:
            attempt_message = {'attempt': attempt}
        print(Color().blue(attempt_message))

        download(caller='single')

        if should_break:
            break
Example #3
0
def video_available_formats():  ## {{{
    global attempt, should_break

    prompt('-u', '-i', '-c')

    print(Color().white_dim(display_args))
    print()

    order = {}
    title, uploader, channel, dur, view_count, like_count, dislike_count, ext, outputname, error = Video(
    ).get_info()
    current = Video(order, get_datetime('jhms'), url, title, uploader, channel,
                    dur, view_count, like_count, dislike_count, ext,
                    outputname, error)

    for attempt in attempts:
        should_break = False

        if attempt == 1:
            attempt_message = current.info_dict
        else:
            attempt_message = {'attempt': attempt}
        print(Color().blue(attempt_message))

        options = {
            'no_color':
            True,  ## better be uncommented, otherwise analyze can't read error messages properly
            'proxy': proxy,
            'skip_download': True,
            'listformats': True,
            'logger': Ydl_DW_Logger(),
        }

        try:
            with YoutubeDL(options) as Y_DL:
                Y_DL.download([url])
            should_break = True
        except Exception as exc:
            analyze(f'{exc!r}', caller='video_available_formats')

        if should_break:
            break
Example #4
0
if 'relative' in mode:
    try:
        relative = int(dmenu(title='relative time'))
    except Exception as exc:
        msgc('ERROR', f'{exc!r}')
        exit()

    message = dmenu(title='message')
    msgn(f'Reminder in {relative} seconds', message)
    dorm(relative)
    msgc('Reminder', message)
elif 'specific' in mode:
    try:
        specific = dmenu(title='specific time')
        specific2 = specific.replace(':', '')
        specific2 = remove_leading_zeros(specific2)
        specific2 = int(specific2)
    except Exception as exc:
        msgc('ERROR', f'{exc!r}')
        exit()

    message = dmenu(title='message')
    msgn(f'Reminder at {specific}', message)
    while True:
        current_time = int(get_datetime('jhms')[:4])
        current_time = int(remove_leading_zeros(current_time))
        if current_time == specific2:
            msgc('Reminder', message)
            break
        dorm(30)
Example #5
0
def check_to_exit():  ## {{{
    current_time = int(get_datetime('jhms'))
    exit_permission = current_time > 63000

    return exit_permission
Example #6
0
def check_to_start():  ## {{{
    current_time = int(get_datetime('jhms'))
    start_permission = current_time > 21000 and current_time < 63000

    return start_permission
Example #7
0
def bulk():  ## {{{
    global dest_dir, log_file, outputname, failed_sites, order, should_break, attempt, urls, url, x_value

    failed_sites = []

    prompt('-w', '-f', '-s', '-x', '-d', '-i', '-c')

    mkdir(dest_dir)
    chdir(dest_dir)

    log_file = f'{dest_dir}/log'

    append_to_log(str(display_args) + '\n\n')
    print(Color().white_dim(display_args))

    print()

    while True:
        permission = check_to_start()
        if when == 'h' and not permission:
            ## not yet
            append_to_log(str({'time': get_datetime('jhms')}) + '\n')
            print(Color().brown({'time': get_datetime('jhms')}))
            dorm(60)
        else:
            for url in urls:

                urls_length = len(urls)
                nth = urls.index(url) + 1
                perc = int(nth * 100 / urls_length)
                order = {f'{nth}/{urls_length}': f'%{perc}'}

                if file_type in ['v', 's', 'vs', 'a', 't']:
                    title, uploader, channel, dur, view_count, like_count, dislike_count, ext, outputname, error = Video(
                    ).get_info()
                    current = Video(order, get_datetime('jhms'), url, title,
                                    uploader, channel, dur, view_count,
                                    like_count, dislike_count, ext, outputname,
                                    error)
                elif file_type == 'o':
                    size, raw_size, content_type, last_modified, outputname, error = File(
                    ).get_info()
                    current = File(order, get_datetime('jhms'), url, size,
                                   raw_size, content_type, last_modified,
                                   outputname, error)

                outputname = f'{dest_dir}/{outputname}'
                current.outputname = sub(getenv('HOME'), '~', outputname)

                for attempt in attempts:
                    should_break = False

                    should_exit = check_to_exit()
                    if when == 'h' and should_exit:
                        append_to_log('\nHappy hours over. Exit.\n')
                        print('\nHappy hours over. Exit.')
                        exit()

                    if attempt == 1:
                        attempt_message = current.info_dict
                    else:
                        attempt_message = {'attempt': attempt}
                    append_to_log(f'{attempt_message}\n')
                    print(Color().blue(attempt_message))

                    url_duration = download(caller='bulk')

                    if should_break:
                        break
                ## END attempt

                raw_dest_dir_size = dest_dir_size()
                converted_dest_dir_size = convert_byte(raw_dest_dir_size)
                append_to_log(
                    str({
                        'url duration': url_duration,
                        'dest dir size': converted_dest_dir_size
                    }) + '\n')
                print(Color().brown({
                    'url duration': url_duration,
                    'dest dir size': converted_dest_dir_size
                }))

                append_to_log('-' * 60 + '\n')
                print(separator())

                if x_value:
                    x_value += 1
            ## END urls

            ## fails report
            if failed_sites:
                table_header = [f'{len(failed_sites)} fails']
                table_rows = [[failed_site] for failed_site in failed_sites]
                failed_table = draw_table(table_rows, table_header)

                append_to_log(f'{failed_table}\n')
                print(Color().red(failed_table))

            break
Example #8
0
            str({
                'time': get_datetime('jhms'),
                'total duration': total_duration
            }) + '\n')
        print(Color().brown({
            'time': get_datetime('jhms'),
            'total duration': total_duration
        }))
    elif main_item == 'get youtube playlist urls':
        get_youtube_playlist_urls()
    elif main_item == 'video available formats':
        video_available_formats()
    elif main_item == 'help':
        help()


## }}}
## variables {{{
title = path.basename(__file__).replace('.py', '')
hnd = f'{getenv("HOME")}/downloads'
s = Session()
hdrs = get_headers()
proxy = 'socks5://127.0.0.1:9050'
display_args = {'datetime': get_datetime('jymdhms')}
script_args = argv[1:]
attempts = [att for att in range(1, 6)]
## }}}

if __name__ == '__main__':
    main()
    msgn(f'copied\n<span color=\"{getenv("orange")}\">{string}</span>')
elif main_item == 'file':
    prompt('-f')
    with open(file, 'r') as F:
        content = F.read().strip()
    clipboard_copy(content)
    msgn(f'copied\n<span color=\"{getenv("orange")}\">{content}</span>')
elif main_item == 'command':
    prompt('-c')
    cmd = run(command,
              shell=True,
              universal_newlines=True,
              capture_output=True)
    cmd_output = cmd.stdout.strip()
    clipboard_copy(cmd_output)
    msgn(f'copied\n<span color=\"{getenv("orange")}\">{cmd_output}</span>')
elif main_item == 'datetime':
    current_datetime = get_datetime('ymdhms')
    clipboard_copy(current_datetime)
    msgn(
        f'copied\n<span color=\"{getenv("orange")}\">{current_datetime}</span>'
    )
elif main_item == 'jalali datetime':
    current_datetime = get_datetime('jymdhms')
    clipboard_copy(current_datetime)
    msgn(
        f'copied\n<span color=\"{getenv("orange")}\">{current_datetime}</span>'
    )
elif main_item == 'help':
    help()
Example #10
0
    output = f'{p_name}.jpg'
    im.save(output, quality=100)
    try:
        remove(png_image)
    except Exception:
        pass


## }}}

main_items = [
    'screen 1', 'screen 2', 'screen all', 'current window', 'selected area'
]
main_item = dmenu(main_items, 'screenshot')

now = get_datetime('jymdhms')
global output
output = f'{getenv("HOME")}/downloads/{now}-SS.png'

scr_1_name, scr_1_res, scr_1_x, scr_1_y = Screen().screen_1()
scr_2_name, scr_2_res, scr_2_x, scr_2_y = Screen().screen_2()
scr_all_res = Screen().screen_all()

## https://askubuntu.com/questions/1011507/screenshot-of-an-active-application-using-python
if main_item == 'screen 1':
    countdown()
    window = Gdk.get_default_root_window()
    pb = Gdk.pixbuf_get_from_window(window, 0, 0, int(scr_1_x), int(scr_1_y))
    pb.savev(output, 'png', (), ())
    # convert_to_jpg(output)
    msgn('screen 1', f'<span color=\"{getenv("orange")}\">{output}</span>')