コード例 #1
0
def prompt(*args: str):  ## {{{
    global length

    for arg in args:
        if   arg == '-l':
            try:    length
            except:
                try:    length = int(get_input('Length'))
                except: invalid('Length should be a number')
コード例 #2
0
def getopts():  ## {{{
    global length

    try:
        duos, duos_long = getopt(script_args, 'hl:', ['help', 'length='])
    except Exception as exc:
        invalid(f'{exc!r}')

    for opt, arg in duos:
        if   opt in ('-h', '--help'):   help()
        elif opt in ('-l', '--length'): length = int(arg)
コード例 #3
0
def getopts():  ## {{{
    global inpt, password

    try:
        duos, duos_long = getopt(script_args, 'hi:p:',
                                 ['help', 'input=', 'password='******'{exc!r}')

    for opt, arg in duos:
        if opt in ('-h', '--help'): help()
        elif opt in ('-i', '--input'): inpt = arg
        elif opt in ('-p', '--password'): password = arg
コード例 #4
0
def getopts():  ## {{{
    global file, string

    try:
        duos, duos_long = getopt(script_args, 'hf:s:',
                                 ['help', 'string=', 'file='])
    except Exception as exc:
        invalid(f'{exc!r}')

    for opt, arg in duos:
        if opt in ('-h', '--help'): help()
        elif opt in ('-s', '--string'): string = arg
        elif opt in ('-f', '--file'): file = arg
コード例 #5
0
def getopts():  ## {{{
    global string, file, command

    try:
        duos, duos_long = getopt(script_args, 'hs:f:c:',
                                 ['help', 'string=', 'file=', 'command='])
    except Exception as exc:
        invalid(f'{exc!r}')

    for opt, arg in duos:
        if opt in ('-h', '--help'): help()
        elif opt in ('-s', '--string'): string = arg
        elif opt in ('-f', '--file'): file = arg
        elif opt in ('-c', '--command'): command = arg
コード例 #6
0
def prompt(*args: str):  ## {{{
    global inpt, password

    for arg in args:
        if arg == '-i':
            try:
                inpt
            except:
                inpt = get_input('Input')
            if not path.exists(f'{inpt}'): invalid('No such file/dir')
        elif arg == '-p':
            try:
                password
            except:
                password = get_password('Password ')
コード例 #7
0
def prompt(*args: str):  ## {{{
    global file, string

    for arg in args:
        if arg == '-f':
            try:
                file
            except:
                file = get_input('File')
            if not path.exists(f'{file}'): invalid('No such file')
            if path.isdir(f'{file}'): invalid('Files only')
        elif arg == '-s':
            try:
                string
            except:
                string = get_input('String')
コード例 #8
0
def prompt(*args: str):  ## {{{
    global string, file, command

    for arg in args:
        if arg == '-s':
            try:
                string
            except:
                string = get_input('String')
        elif arg == '-f':
            try:
                file
            except:
                file = get_input('File')
            if not path.exists(f'{file}'): invalid('No such file')
        elif arg == '-c':
            try:
                command
            except:
                command = get_input('Command')
コード例 #9
0
def getopts():  ## {{{
    global main_args, x_value, downloader, torsocks, ignore_information, complete_error
    main_args, x_value, downloader, torsocks, ignore_information, complete_error = (
        {}, ) + (None, ) + (False, ) * 4

    try:
        duos, duos_long = getopt(script_args, 'hw:f:v:u:s:x:p:o:dtic', [
            'help', 'when=', 'file-type=', 'video-quality=', 'url=',
            'source-file=', 'x-value=', 'playlist-id=', 'output-file=',
            'downloader', 'torsocks', 'ignore-information', 'complete-error'
        ])
        for opt, arg in duos:
            if opt in ('-h', '--help'): help()
            elif opt in ('-w', '--when'): main_args['when'] = arg
            elif opt in ('-f', '--file-type'): main_args['file-type'] = arg
            elif opt in ('-v', '--video-quality'):
                main_args['video-quality'] = arg
            elif opt in ('-u', '--url'):
                main_args['url'] = arg
            elif opt in ('-s', '--source-file'):
                main_args['source-file'] = arg
            elif opt in ('-p', '--playlist-id'):
                main_args['playlist-id'] = arg
            elif opt in ('-o', '--output-file'):
                main_args['output-file'] = arg
            elif opt in ('-x', '--x-value'):
                main_args['x-value'] = arg
            elif opt in ('-d', '--downloader'):
                main_args['downloader'] = True
            elif opt in ('-t', '--torsocks'):
                main_args['torsocks'] = True
            elif opt in ('-i', '--ignore-information'):
                main_args['ignore-information'] = True
            elif opt in ('-c', '--complete-error'):
                main_args['complete-error'] = True
    except Exception as exc:
        reason = f'{exc!r}'
        invalid({'GETOPTS ERROR': reason})
コード例 #10
0
ファイル: lf-ranger.py プロジェクト: davoudarsalani/scripts
                'ERROR',
                f'xtracting <span color=\"{getenv("orange")}\">{base}</span>\n{exc!r}',
                f'{getenv("HOME")}/linux/themes/alert-w.png')
        dorm(0.1)
elif main_arg == 'zip':
    for f in files:
        try:
            _, base = path.split(f)
            use_password = get_single_input('Use password (y/n)?')
            if use_password == 'y':
                password = get_password('Password ')
                compress_zip(f, password)
            elif use_password == 'n':
                compress_zip(f)
            else:
                invalid('Wrong choice')
            msgn('compressed',
                 f'<span color=\"{getenv("orange")}\">{base}</span> to zip')
        except Exception as exc:
            msgc(
                'ERROR',
                f'compressing <span color=\"{getenv("orange")}\">{base}</span> to zip\n{exc!r}',
                f'{getenv("HOME")}/linux/themes/alert-w.png')
        dorm(0.1)
elif main_arg == 'unzip':
    for f in files:
        try:
            _, base = path.split(f)
            has_password = get_single_input('Has password (y/n)?')
            if has_password == 'y':
                password = get_password('Password ')
コード例 #11
0
def prompt(*args: str):  ## {{{
    global when, file_type, video_quality, url, source_file, playlist_id, output_file, x_value, downloader, torsocks, ignore_information, complete_error
    global main_args, display_args, urls, dest_dir

    for arg in args:
        if arg == '-w':
            when = main_args.get('when')
            if not when: when = get_single_input('When (n/h)')
            if when not in ['n', 'h']: invalid('Invalid time')
            display_args['when'] = when

        elif arg == '-f':
            file_type = main_args.get('file-type')
            if not file_type: file_type = get_input('File type (v/s/vs/a/t/o)')
            if file_type not in ['v', 's', 'vs', 'a', 't', 'o']:
                invalid('Invalid file type')

            if file_type in ['v', 'vs']: prompt('-v')
            elif file_type == 'o': prompt('-t')

            # ## we may need downloader only for youtube_dl
            # if file_type in ['v', 's', 'vs', 'a', 't']:
            #     prompt('-d')

            display_args['file-type'] = file_type

        elif arg == '-v':
            video_quality = main_args.get('video-quality')
            if not video_quality:
                video_quality = get_input('Video quality (e.g. 22, best, etc)')
            display_args['video-quality'] = video_quality

        elif arg == '-u':
            url = main_args.get('url')
            if not url: url = get_input('URL')
            display_args['url'] = url

        elif arg == '-s':
            source_file = main_args.get('source-file')
            if not source_file: source_file = get_input('Source file')
            ## check if source_file exists
            if not path.exists(source_file): invalid('No such file')
            ## check if source_file is a directory
            if path.isdir(source_file):
                invalid('Source file cannot be a directory')

            ## create urls list from source_file
            with open(source_file, 'r') as SOURCE_FILE:
                lines = SOURCE_FILE.read().splitlines()
            urls = list(
                filter(lambda line: not line.startswith('#'), lines)
            )  ## OR: [line for line in lines if not line.startswith('#')]
            if not urls:
                invalid('Source file contains no downloadable urls')

            root_base, ext = path.splitext(source_file)
            dest_dir = root_base
            dest_dir = if_exists(dest_dir)

            display_args['source-file'] = sub(getenv('HOME'), '~', source_file)
            display_args['destination-directory'] = sub(
                getenv('HOME'), '~', dest_dir)

        elif arg == '-p':
            playlist_id = main_args.get('playlist-id')
            if not playlist_id:
                playlist_id = get_input(
                    'Playlist id (e.g. PL-osiE80TeTt2d9bfVyTiXJA-UTHn6WwU)')
            display_args['playlist-id'] = playlist_id

        elif arg == '-o':
            output_file = main_args.get('output-file')
            if not output_file: output_file = get_input('Output file')
            output_file = if_exists(output_file)
            display_args['output-file'] = sub(getenv('HOME'), '~', output_file)

        elif arg == '-x':
            x_value = main_args.get('x-value', None)
            if x_value:
                try:
                    x_value = int(x_value)
                except Exception:
                    invalid('x-value should be a number')
                display_args['x-value'] = x_value

        elif arg == '-d':
            downloader = main_args.get('downloader', False)
            if downloader: display_args['downloader'] = downloader

        elif arg == '-t':
            torsocks = main_args.get('torsocks', False)
            if torsocks: display_args['torsocks'] = torsocks

        elif arg == '-i':
            ignore_information = main_args.get('ignore-information', False)
            if ignore_information:
                display_args['ignore-information'] = ignore_information

        elif arg == '-c':
            complete_error = main_args.get('complete-error', False)
            if complete_error: display_args['complete-error'] = complete_error
コード例 #12
0
print(Color().heading(title))

main_items = ['audio', 'screen 1', 'screen 2', 'screen all', 'video']
main_item = fzf(main_items)

mic = get_single_input('Need mic?')
if mic == 'y':
    Audio().mic('unmute')
    Audio().mic('25')
    Audio().mon('unmute')
    Audio().mon('100')
elif mic == 'n':
    Audio().mon('unmute')
    Audio().mon('100')
else:
    invalid('Invalid answer')

update_audio()

set_widget('record', 'fg', getenv('red'))

if main_item == 'audio':
    suffix = 'AUD-UL'
    output = f'{getenv("HOME")}/downloads/{get_datetime("jymdhms")}-{suffix}.mp3'
    set_widget('record', 'markup', f'<b>{record_icon()}:{suffix}</b>')
    Record().audio_ul(output)
elif main_item == 'screen 1':
    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()
    resolution = scr_1_res
    x_offset = 0